java.lang.Object
org.omnifaces.utils.Lang
-
Method Summary
Modifier and TypeMethodDescriptionstatic Stringcapitalize(String string) Converts the first character of given string to upper case.static <T> Tcoalesce(T... objects) Returns the first non-nullobject of the argument list, ornullif there is no such element.static booleancontainsIsoControlCharacters(String string) Returnstrueif the given string contains any ISO control characters.static booleanendsWithOneOf(String string, String... suffixes) Returnstrueif the given string ends with one of the given suffixes.static StringescapeAsProperty(String string) Escape given string as validPropertiesentry value.static <T> TifEmptyGet(T value, Supplier<T> defaultSupplier) static booleanisAllEmpty(Object... values) Returns true if all values are empty, false if at least one value is not empty.static booleanisAnyEmpty(Object... values) Returnstrueif at least one value is empty.static booleanReturnstrueif the given value is null or is empty.static booleanReturnstrueif the given array is null or is empty.static booleanReturnstrueif the given string is null or is empty.static booleanisEmpty(Collection<?> collection) Returnstrueif the given collection is null or is empty.static booleanReturnstrueif the given map is null or is empty.static booleanisNotBlank(String string) static <T> booleanisOneOf(T object, T... objects) Returnstrueif the given object equals one of the given objects.static StringreplaceLast(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> voidsetIfNotEmpty(T value, Consumer<? super T> setter) Call the given setter with the given value ifisEmpty(Object)returnsfalsefor the given value.static booleanstartsWithOneOf(String string, String... prefixes) Returnstrueif the given string starts with one of the given prefixes.static StringtoTitleCase(String string) Converts given string to title case.static StringConverts given string to URL safe format, also called a "slug".
-
Method Details
-
isEmpty
Returnstrueif the given string is null or is empty.- Parameters:
string- The string to be checked on emptiness.- Returns:
trueif the given string is null or is empty.
-
isEmpty
Returnstrueif the given array is null or is empty.- Parameters:
array- The array to be checked on emptiness.- Returns:
trueif the given array is null or is empty.
-
isEmpty
Returnstrueif the given collection is null or is empty.- Parameters:
collection- The collection to be checked on emptiness.- Returns:
trueif the given collection is null or is empty.
-
isEmpty
Returnstrueif the given map is null or is empty.- Parameters:
map- The map to be checked on emptiness.- Returns:
trueif the given map is null or is empty.
-
isEmpty
Returnstrueif 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:
trueif 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
Returnstrueif at least one value is empty.- Parameters:
values- the values to be checked on emptiness- Returns:
trueif any value is empty andfalseif 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)returnsfalsefor 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-nullobject of the argument list, ornullif 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-
nullobject of the argument list, ornullif there is no such element.
-
isOneOf
Returnstrueif 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:
trueif the given object equals one of the given objects.
-
startsWithOneOf
Returnstrueif 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:
trueif the given string starts with one of the given prefixes.
-
endsWithOneOf
Returnstrueif 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:
trueif 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
Returnstrueif the given string contains any ISO control characters.- Parameters:
string- the string to check for control characters- Returns:
trueif the string contains any ISO control characters andfalseotherwise
-
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 validPropertiesentry value.- Parameters:
string- String to be escaped as validPropertiesentry value.- Returns:
- The given string escaped as valid
Propertiesentry value. - Throws:
IOException- When appending a character fails.
-