- java.lang.Object
-
- org.omnifaces.utils.Lang
-
public final class Lang extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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
isEmpty(Object value)
Returnstrue
if the given value is null or is empty.static boolean
isEmpty(Object[] array)
Returnstrue
if the given array is null or is empty.static boolean
isEmpty(String string)
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
isEmpty(Map<?,?> map)
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
toUrlSafe(String string)
Converts given string to URL safe format, also called a "slug".
-
-
-
Method Detail
-
isEmpty
public static boolean isEmpty(String string)
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
public static boolean isEmpty(Object[] array)
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
public static boolean isEmpty(Collection<?> collection)
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
public static boolean isEmpty(Map<?,?> map)
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
public static boolean isEmpty(Object value)
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
public static boolean isAllEmpty(Object... values)
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
public static boolean isAnyEmpty(Object... values)
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
public static boolean isNotBlank(String string)
-
requireNotEmpty
public static <T,E extends Exception> T requireNotEmpty(T value, Supplier<E> exceptionSupplier) throws E extends Exception
- Throws:
E extends Exception
-
ifEmptyGet
public static <T> T ifEmptyGet(T value, Supplier<T> defaultSupplier)
-
setIfNotEmpty
public 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.- 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
@SafeVarargs public static <T> T coalesce(T... objects)
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
@SafeVarargs public static <T> boolean isOneOf(T object, T... objects)
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
public static boolean startsWithOneOf(String string, String... prefixes)
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
public static boolean endsWithOneOf(String string, String... suffixes)
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
public 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. 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
public static boolean containsIsoControlCharacters(String string)
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
public static String capitalize(String string)
Converts the first character of given string to upper case.- Parameters:
string
- String to be capitalized.- Returns:
- The given string capitalized.
-
toTitleCase
public static String toTitleCase(String string)
Converts given string to title case.- Parameters:
string
- String to be converted to title case.- Returns:
- The given string converted to title case.
-
toUrlSafe
public static String toUrlSafe(String string)
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
public static String escapeAsProperty(String string) throws IOException
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.
-
-