Class Utils
-
- All Implemented Interfaces:
public class UtilsUtility methods.
-
-
Method Summary
Modifier and Type Method Description static <T> TgetOrDefault(T value, T defaultValue)Returns the given value if it is not null, otherwise returns the given default value.static <T> List<T>getOrDefault(List<T> list, List<T> defaultList)Returns the given list if it is not nulland not empty, otherwise returns the given default list.static <K, V> Map<K, V>getOrDefault(Map<K, V> map, Map<K, V> defaultMap)Returns the given map if it is not nulland not empty, otherwise returns the given default map.static <T> TgetOrDefault(T value, Supplier<T> defaultValueSupplier)Returns the given value if it is not null, otherwise returns the value returned by the given supplier.static booleanisNullOrBlank(String string)Is the given string nullor blank?static booleanisNullOrEmpty(String string)Is the given string nullor empty ("")?static booleanisNotNullOrBlank(String string)Is the given string not nulland not blank?static booleanisNotNullOrEmpty(String string)Is the given string not nulland not empty ("")?static booleanareNotNullOrBlank(Array<String> strings)Are all the given strings not nulland not blank?static booleanisNullOrEmpty(Collection<out Object> collection)Is the collection nullor empty?static booleanisNullOrEmpty(Iterable<out Object> iterable)Is the iterable object nullor empty?static booleanisNullOrEmpty(Map<out Object, out Object> map)Is the map object nullor empty?static booleanisCollectionEmpty(Collection<out Object> collection)static Stringrepeat(String string, int times)Returns a string consisting of the given string repeated timestimes.static StringrandomUUID()Returns a random UUID. static StringgenerateUUIDFrom(String input)Generates a UUID from a hash of the given input string. static StringensureTrailingForwardSlash(String url)Appends a trailing '/' if the provided URL does not end with '/' static Stringquoted(Object object)Returns the given object's toString()surrounded by quotes.static StringfirstChars(String string, int numberOfChars)Returns the first numberOfCharscharacters of the given string.static Array<byte>readBytes(String url)Reads the content as bytes from the given URL as a GET request for HTTP/HTTPS resources, and from files stored on the local filesystem. static <T> Set<T>copyIfNotNull(Set<T> set)Returns an (unmodifiable) copy of the provided set. static <T> List<T>copyIfNotNull(List<T> list)Returns an (unmodifiable) copy of the provided list. static <K, V> Map<K, V>copyIfNotNull(Map<K, V> map)Returns an (unmodifiable) copy of the provided map. -
-
Method Detail
-
getOrDefault
static <T> T getOrDefault(T value, T defaultValue)
Returns the given value if it is not
null, otherwise returns the given default value.- Parameters:
value- The value to return if it is notnull.defaultValue- The value to return if the value isnull.- Returns:
the given value if it is not
null, otherwise returns the given default value.
-
getOrDefault
static <T> List<T> getOrDefault(List<T> list, List<T> defaultList)
Returns the given list if it is not
nulland not empty, otherwise returns the given default list.- Parameters:
list- The list to return if it is notnulland not empty.defaultList- The list to return if the list isnullor empty.- Returns:
the given list if it is not
nulland not empty, otherwise returns the given default list.
-
getOrDefault
static <K, V> Map<K, V> getOrDefault(Map<K, V> map, Map<K, V> defaultMap)
Returns the given map if it is not
nulland not empty, otherwise returns the given default map.- Parameters:
map- The map to return if it is notnulland not empty.defaultMap- The map to return if the map isnullor empty.- Returns:
the given map if it is not
nulland not empty, otherwise returns the given default map.
-
getOrDefault
static <T> T getOrDefault(T value, Supplier<T> defaultValueSupplier)
Returns the given value if it is not
null, otherwise returns the value returned by the given supplier.- Parameters:
value- The value to return if it is notnull.defaultValueSupplier- The supplier to call if the value isnull.- Returns:
the given value if it is not
null, otherwise returns the value returned by the given supplier.
-
isNullOrBlank
static boolean isNullOrBlank(String string)
Is the given string
nullor blank?- Parameters:
string- The string to check.- Returns:
true if the string is
nullor blank.
-
isNullOrEmpty
static boolean isNullOrEmpty(String string)
Is the given string
nullor empty ("")?- Parameters:
string- The string to check.- Returns:
true if the string is
nullor empty.
-
isNotNullOrBlank
static boolean isNotNullOrBlank(String string)
Is the given string not
nulland not blank?- Parameters:
string- The string to check.- Returns:
true if there's something in the string.
-
isNotNullOrEmpty
static boolean isNotNullOrEmpty(String string)
Is the given string not
nulland not empty ("")?- Parameters:
string- The string to check.- Returns:
true if the given string is not
nulland not empty ("")?
-
areNotNullOrBlank
static boolean areNotNullOrBlank(Array<String> strings)
Are all the given strings not
nulland not blank?- Parameters:
strings- The strings to check.- Returns:
trueif every string is non-nulland non-empty.
-
isNullOrEmpty
static boolean isNullOrEmpty(Collection<out Object> collection)
Is the collection
nullor empty?- Parameters:
collection- The collection to check.- Returns:
trueif the collection isnullor isEmpty, otherwisefalse.
-
isNullOrEmpty
static boolean isNullOrEmpty(Iterable<out Object> iterable)
Is the iterable object
nullor empty?- Parameters:
iterable- The iterable object to check.- Returns:
trueif the iterable object isnullor there are no objects to iterate over, otherwisefalse.
-
isNullOrEmpty
static boolean isNullOrEmpty(Map<out Object, out Object> map)
Is the map object
nullor empty?- Parameters:
map- The iterable object to check.- Returns:
trueif the map object isnullor empty map, otherwisefalse.
-
isCollectionEmpty
@Deprecated(forRemoval = true) static boolean isCollectionEmpty(Collection<out Object> collection)
- Parameters:
collection- The collection to check.- Returns:
trueif the collection isnullor empty,falseotherwise.
-
repeat
static String repeat(String string, int times)
Returns a string consisting of the given string repeated
timestimes.- Parameters:
string- The string to repeat.times- The number of times to repeat the string.- Returns:
A string consisting of the given string repeated
timestimes.
-
randomUUID
static String randomUUID()
Returns a random UUID.
- Returns:
a UUID.
-
generateUUIDFrom
static String generateUUIDFrom(String input)
Generates a UUID from a hash of the given input string.
- Parameters:
input- The input string.- Returns:
A UUID.
-
ensureTrailingForwardSlash
static String ensureTrailingForwardSlash(String url)
Appends a trailing '/' if the provided URL does not end with '/'
- Parameters:
url- URL to check for trailing '/'- Returns:
Same URL if it already ends with '/' or a new URL with '/' appended
-
quoted
static String quoted(Object object)
Returns the given object's
toString()surrounded by quotes.If the given object is
null, the string"null"is returned.- Parameters:
object- The object to quote.- Returns:
The given object surrounded by quotes.
-
firstChars
static String firstChars(String string, int numberOfChars)
Returns the first
numberOfCharscharacters of the given string. If the string is shorter thannumberOfChars, the whole string is returned.- Parameters:
string- The string to get the first characters from.numberOfChars- The number of characters to return.- Returns:
The first
numberOfCharscharacters of the given string.
-
readBytes
static Array<byte> readBytes(String url)
Reads the content as bytes from the given URL as a GET request for HTTP/HTTPS resources, and from files stored on the local filesystem.
- Parameters:
url- The URL to read from.- Returns:
The content as bytes.
-
copyIfNotNull
static <T> Set<T> copyIfNotNull(Set<T> set)
Returns an (unmodifiable) copy of the provided set. Returns
nullif the provided set isnull.- Parameters:
set- The set to copy.- Returns:
The copy of the provided set.
-
copyIfNotNull
static <T> List<T> copyIfNotNull(List<T> list)
Returns an (unmodifiable) copy of the provided list. Returns
nullif the provided list isnull.- Parameters:
list- The list to copy.- Returns:
The copy of the provided list.
-
-
-
-