java.lang.Object
org.omnifaces.utils.Lang
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
capitalize
(String string) Converts the first character of given string to upper case.static <T> T
coalesce
(T... objects) Returns the first non-null
object of the argument list, ornull
if there is no such element.static boolean
containsIsoControlCharacters
(String string) Returnstrue
if the given string contains any ISO control characters.static boolean
endsWithOneOf
(String string, String... suffixes) Returnstrue
if the given string ends with one of the given suffixes.static String
escapeAsProperty
(String string) Escape given string as validProperties
entry value.static <T> T
ifEmptyGet
(T value, Supplier<T> defaultSupplier) static boolean
isAllEmpty
(Object... values) Returns true if all values are empty, false if at least one value is not empty.static boolean
isAnyEmpty
(Object... values) Returnstrue
if at least one value is empty.static boolean
Returnstrue
if the given value is null or is empty.static boolean
Returnstrue
if the given array is null or is empty.static boolean
Returnstrue
if the given string is null or is empty.static boolean
isEmpty
(Collection<?> collection) Returnstrue
if the given collection is null or is empty.static boolean
Returnstrue
if the given map is null or is empty.static boolean
isNotBlank
(String string) static <T> boolean
isOneOf
(T object, T... objects) Returnstrue
if the given object equals one of the given objects.static String
replaceLast
(String string, String regex, String replacement) Replaces the last substring of given string that matches the given regular expression with the given replacement.static <T,
E extends Exception>
TrequireNotEmpty
(T value, Supplier<E> exceptionSupplier) static <T> void
setIfNotEmpty
(T value, Consumer<? super T> setter) Call the given setter with the given value ifisEmpty(Object)
returnsfalse
for the given value.static boolean
startsWithOneOf
(String string, String... prefixes) Returnstrue
if the given string starts with one of the given prefixes.static String
toTitleCase
(String string) Converts given string to title case.static String
Converts given string to URL safe format, also called a "slug".
-
Method Details
-
isEmpty
Returnstrue
if the given string is null or is empty.- Parameters:
string
- The string to be checked on emptiness.- Returns:
true
if the given string is null or is empty.
-
isEmpty
Returnstrue
if the given array is null or is empty.- Parameters:
array
- The array to be checked on emptiness.- Returns:
true
if the given array is null or is empty.
-
isEmpty
Returnstrue
if the given collection is null or is empty.- Parameters:
collection
- The collection to be checked on emptiness.- Returns:
true
if the given collection is null or is empty.
-
isEmpty
Returnstrue
if the given map is null or is empty.- Parameters:
map
- The map to be checked on emptiness.- Returns:
true
if the given map is null or is empty.
-
isEmpty
Returnstrue
if the given value is null or is empty. Types of String, Collection, Map, Optional and Array are recognized. If none is recognized, then examine the emptiness of the toString() representation instead.- Parameters:
value
- The value to be checked on emptiness.- Returns:
true
if the given value is null or is empty.
-
isAllEmpty
Returns true if all values are empty, false if at least one value is not empty.- Parameters:
values
- the values to be checked on emptiness- Returns:
- True if all values are empty, false otherwise
-
isAnyEmpty
Returnstrue
if at least one value is empty.- Parameters:
values
- the values to be checked on emptiness- Returns:
true
if any value is empty andfalse
if no values are empty
-
isNotBlank
-
requireNotEmpty
public static <T,E extends Exception> T requireNotEmpty(T value, Supplier<E> exceptionSupplier) throws E - Throws:
E extends Exception
-
ifEmptyGet
-
setIfNotEmpty
Call the given setter with the given value ifisEmpty(Object)
returnsfalse
for the given value.- Type Parameters:
T
- the generic type of the value- Parameters:
value
- the value to setsetter
- a consumer that calls the setter with the value
-
coalesce
Returns the first non-null
object of the argument list, ornull
if there is no such element.- Type Parameters:
T
- The generic object type.- Parameters:
objects
- The argument list of objects to be tested for non-null
.- Returns:
- The first non-
null
object of the argument list, ornull
if there is no such element.
-
isOneOf
Returnstrue
if the given object equals one of the given objects.- Type Parameters:
T
- The generic object type.- Parameters:
object
- The object to be checked if it equals one of the given objects.objects
- The argument list of objects to be tested for equality.- Returns:
true
if the given object equals one of the given objects.
-
startsWithOneOf
Returnstrue
if the given string starts with one of the given prefixes.- Parameters:
string
- The string to be checked if it starts with one of the given prefixes.prefixes
- The argument list of prefixes to be checked.- Returns:
true
if the given string starts with one of the given prefixes.
-
endsWithOneOf
Returnstrue
if the given string ends with one of the given suffixes.- Parameters:
string
- The string to be checked if it ends with one of the given suffixes.suffixes
- The argument list of suffixes to be checked.- Returns:
true
if the given string ends with one of the given suffixes.
-
replaceLast
Replaces the last substring of given string that matches the given regular expression with the given replacement. Author: https://stackoverflow.com/a/2282998- Parameters:
string
- The string to be replaced.regex
- The regular expression to which given string is to be matched.replacement
- The string to be substituted for the last match.- Returns:
- The resulting string.
-
containsIsoControlCharacters
Returnstrue
if the given string contains any ISO control characters.- Parameters:
string
- the string to check for control characters- Returns:
true
if the string contains any ISO control characters andfalse
otherwise
-
capitalize
Converts the first character of given string to upper case.- Parameters:
string
- String to be capitalized.- Returns:
- The given string capitalized.
-
toTitleCase
Converts given string to title case.- Parameters:
string
- String to be converted to title case.- Returns:
- The given string converted to title case.
-
toUrlSafe
Converts given string to URL safe format, also called a "slug".- Parameters:
string
- String to be converted to URL safe format.- Returns:
- The given string converted to URL safe format.
-
escapeAsProperty
Escape given string as validProperties
entry value.- Parameters:
string
- String to be escaped as validProperties
entry value.- Returns:
- The given string escaped as valid
Properties
entry value. - Throws:
IOException
- When appending a character fails.
-