Class Utils

java.lang.Object
ai.docling.serve.api.util.Utils

public final class Utils extends Object
Utility methods.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> @NonNull T
    firstNotNull(@NonNull String name, @Nullable T... values)
    Returns the first non-null value from the provided array of values.
    static <T> T
    getOrDefault(@Nullable 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> List<T>
    getOrDefault(List<T> list, List<T> defaultList)
    Returns the given list if it is not null and 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 null and not empty, otherwise returns the given default map.
    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
    Is the given string not null and not blank?
    static boolean
    Is the given string not null and not empty ("")?
    static boolean
    Is the given string null or blank?
    static <K, V> boolean
    isNullOrEmpty(@Nullable Map<K,V> map)
    Is the map object null or empty?
    static <T> boolean
    isNullOrEmpty(Iterable<T> iterable)
    Is the iterable object null or empty?
    static boolean
    Is the given string null or empty ("")?
    static <T> boolean
    isNullOrEmpty(Collection<T> collection)
    Is the collection null or empty?
    static <T> boolean
    isNullOrEmpty(T[] array)
    Utility method to check if an array is null or has no elements.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • firstNotNull

      @SafeVarargs public static <T> @NonNull T firstNotNull(@NonNull String name, @Nullable T... values)
      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 not null, otherwise returns the given default value.
      Type Parameters:
      T - The type of the value.
      Parameters:
      value - The value to return if it is not null.
      defaultValue - The value to return if the value is null.
      Returns:
      the given value if it is not null, otherwise returns the given default value.
    • getOrDefault

      public static <T> List<T> getOrDefault(List<T> list, List<T> defaultList)
      Returns the given list if it is not null and 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 not null and not empty.
      defaultList - The list to return if the list is null or empty.
      Returns:
      the given list if it is not null and not empty, otherwise returns the given default list.
    • getOrDefault

      public static <K, V> Map<K,V> getOrDefault(Map<K,V> map, Map<K,V> defaultMap)
      Returns the given map if it is not null and not empty, otherwise returns the given default map.
      Parameters:
      map - The map to return if it is not null and not empty.
      defaultMap - The map to return if the map is null or empty.
      Returns:
      the given map if it is not null and not empty, otherwise returns the given default map.
    • getOrDefault

      public static <T> T getOrDefault(@Nullable T value, Supplier<T> defaultValueSupplier)
      Returns the given value if it is not null, 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 not null.
      defaultValueSupplier - The supplier to call if the value is null.
      Returns:
      the given value if it is not null, otherwise returns the value returned by the given supplier.
    • isNullOrBlank

      public static boolean isNullOrBlank(String string)
      Is the given string null or blank?
      Parameters:
      string - The string to check.
      Returns:
      true if the string is null or blank.
    • isNullOrEmpty

      public static boolean isNullOrEmpty(String string)
      Is the given string null or empty ("")?
      Parameters:
      string - The string to check.
      Returns:
      true if the string is null or empty.
    • isNotNullOrBlank

      public static boolean isNotNullOrBlank(String string)
      Is the given string not null and not blank?
      Parameters:
      string - The string to check.
      Returns:
      true if there's something in the string.
    • isNotNullOrEmpty

      public static boolean isNotNullOrEmpty(String string)
      Is the given string not null and not empty ("")?
      Parameters:
      string - The string to check.
      Returns:
      true if the given string is not null and not empty ("")?
    • isNullOrEmpty

      public static <T> boolean isNullOrEmpty(Collection<T> collection)
      Is the collection null or empty?
      Parameters:
      collection - The collection to check.
      Returns:
      true if the collection is null or Collection.isEmpty(), otherwise false.
    • isNullOrEmpty

      public static <T> boolean isNullOrEmpty(Iterable<T> iterable)
      Is the iterable object null or empty?
      Parameters:
      iterable - The iterable object to check.
      Returns:
      true if the iterable object is null or there are no objects to iterate over, otherwise false.
    • 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:
      true if the array is null or has no elements, otherwise false
    • isNullOrEmpty

      public static <K, V> boolean isNullOrEmpty(@Nullable Map<K,V> map)
      Is the map object null or empty?
      Parameters:
      map - The iterable object to check.
      Returns:
      true if the map object is null or empty map, otherwise false.