Package ai.docling.serve.api.util
Class Utils
java.lang.Object
ai.docling.serve.api.util.Utils
Utility methods.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> @NonNull TfirstNotNull(@NonNull String name, @Nullable T... values) Returns the first non-null value from the provided array of values.static <T> TgetOrDefault(@Nullable T value, Supplier<T> defaultValueSupplier) Returns the given value if it is notnull, otherwise returns the value returned by the given supplier.static <T> List<T>getOrDefault(List<T> list, List<T> defaultList) Returns the given list if it is notnulland 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 notnulland not empty, otherwise returns the given default map.static <T> TgetOrDefault(T value, T defaultValue) Returns the given value if it is notnull, otherwise returns the given default value.static booleanisNotNullOrBlank(String string) Is the given string notnulland not blank?static booleanisNotNullOrEmpty(String string) Is the given string notnulland not empty ("")?static booleanisNullOrBlank(String string) Is the given stringnullor blank?static <K,V> boolean isNullOrEmpty(@Nullable Map<K, V> map) Is the map objectnullor empty?static <T> booleanisNullOrEmpty(Iterable<T> iterable) Is the iterable objectnullor empty?static booleanisNullOrEmpty(String string) Is the given stringnullor empty ("")?static <T> booleanisNullOrEmpty(Collection<T> collection) Is the collectionnullor empty?static <T> booleanisNullOrEmpty(T[] array) Utility method to check if an array is null or has no elements.
-
Method Details
-
firstNotNull
Returns the first non-null value from the provided array of values. If all values are null, an new IllegalArgumentException is thrown.- Parameters:
name- A non-null string representing the name associated with the values.values- An array of potentially nullable values to search through.- Returns:
- The first non-null value in the array.
- Throws:
IllegalArgumentException- If all values are null or if the array is empty.
-
getOrDefault
public static <T> T getOrDefault(T value, T defaultValue) Returns the given value if it is notnull, otherwise returns the given default value.- Type Parameters:
T- The type of the 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
Returns the given list if it is notnulland not empty, otherwise returns the given default list.- Type Parameters:
T- The type of the value.- 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
Returns the given map if it is notnulland 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
Returns the given value if it is notnull, otherwise returns the value returned by the given supplier.- Type Parameters:
T- The type of the value.- 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
Is the given stringnullor blank?- Parameters:
string- The string to check.- Returns:
- true if the string is
nullor blank.
-
isNullOrEmpty
Is the given stringnullor empty ("")?- Parameters:
string- The string to check.- Returns:
- true if the string is
nullor empty.
-
isNotNullOrBlank
Is the given string notnulland not blank?- Parameters:
string- The string to check.- Returns:
- true if there's something in the string.
-
isNotNullOrEmpty
Is the given string notnulland not empty ("")?- Parameters:
string- The string to check.- Returns:
- true if the given string is not
nulland not empty ("")?
-
isNullOrEmpty
Is the collectionnullor empty?- Parameters:
collection- The collection to check.- Returns:
trueif the collection isnullorCollection.isEmpty(), otherwisefalse.
-
isNullOrEmpty
Is the iterable objectnullor empty?- Parameters:
iterable- The iterable object to check.- Returns:
trueif the iterable object isnullor there are no objects to iterate over, otherwisefalse.
-
isNullOrEmpty
public static <T> boolean isNullOrEmpty(T[] array) Utility method to check if an array is null or has no elements.- Parameters:
array- the array to check- Returns:
trueif the array is null or has no elements, otherwisefalse
-
isNullOrEmpty
Is the map objectnullor empty?- Parameters:
map- The iterable object to check.- Returns:
trueif the map object isnullor empty map, otherwisefalse.
-