public class Utils extends Object
Modifier and Type | Method and Description |
---|---|
static boolean |
areNotNullOrBlank(String... strings)
Are all the given strings not
null and not blank? |
static <T> List<T> |
copyIfNotNull(List<T> list)
Returns an (unmodifiable) copy of the provided list.
|
static String |
firstChars(String string,
int numberOfChars)
Returns the first
numberOfChars characters of the given string. |
static String |
generateUUIDFrom(String input)
Generates a UUID from a hash of the given input string.
|
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. |
static <T> T |
getOrDefault(T value,
T defaultValue)
Returns the given value if it is not
null , otherwise returns the given default value. |
static boolean |
isCollectionEmpty(Collection<?> collection)
Deprecated.
Use
isNullOrEmpty(Collection) instead. |
static boolean |
isNotNullOrBlank(String string)
Is the given string not
null and not blank? |
static boolean |
isNullOrBlank(String string)
Is the given string
null or blank? |
static boolean |
isNullOrEmpty(Collection<?> collection)
Is the collection
null or empty? |
static String |
quoted(Object object)
Returns the given object's
toString() surrounded by quotes. |
static String |
randomUUID()
Returns a random UUID.
|
static byte[] |
readBytes(String url)
Reads the content as bytes from the given URL as a GET request.
|
static String |
repeat(String string,
int times)
Returns a string consisting of the given string repeated
times times. |
public static <T> T getOrDefault(T value, T defaultValue)
null
, otherwise returns the given default value.T
- The type of the value.value
- The value to return if it is not null
.defaultValue
- The value to return if the value is null
.null
, otherwise returns the given default value.public static <T> T getOrDefault(T value, Supplier<T> defaultValueSupplier)
null
, otherwise returns the value returned by the given supplier.T
- The type of the value.value
- The value to return if it is not null
.defaultValueSupplier
- The supplier to call if the value is null
.null
, otherwise returns the value returned by the given supplier.public static boolean isNullOrBlank(String string)
null
or blank?string
- The string to check.null
or blank.public static boolean isNotNullOrBlank(String string)
null
and not blank?string
- The string to check.public static boolean areNotNullOrBlank(String... strings)
null
and not blank?strings
- The strings to check.true
if every string is non-null
and non-empty.public static boolean isNullOrEmpty(Collection<?> collection)
null
or empty?collection
- The collection to check.true
if the collection is null
or Collection.isEmpty()
, otherwise false
.@Deprecated public static boolean isCollectionEmpty(Collection<?> collection)
isNullOrEmpty(Collection)
instead.collection
- The collection to check.true
if the collection is null
or empty, false
otherwise.public static String repeat(String string, int times)
times
times.string
- The string to repeat.times
- The number of times to repeat the string.times
times.public static String randomUUID()
public static String generateUUIDFrom(String input)
input
- The input string.public static String quoted(Object object)
toString()
surrounded by quotes.
If the given object is null
, the string "null"
is returned.
object
- The object to quote.public static String firstChars(String string, int numberOfChars)
numberOfChars
characters of the given string.
If the string is shorter than numberOfChars
, the whole string is returned.string
- The string to get the first characters from.numberOfChars
- The number of characters to return.numberOfChars
characters of the given string.public static byte[] readBytes(String url)
url
- The URL to read from.RuntimeException
- if the request fails.Copyright © 2024. All rights reserved.