Class ObjectTools

java.lang.Object
rife.bld.extension.tools.ObjectTools

public final class ObjectTools extends Object
Object Tools.

Utility methods for null-checking and emptiness-checking objects, arrays, collections, and maps.

Varargs semantics note: single-argument isEmpty overloads return true if that one argument is null or empty. Multi-argument (varargs) isEmpty overloads return true only if all arguments are null or empty. Conversely, multi-argument isNotEmpty overloads return true if any argument is not null and not empty.

The same applies to isNull, isAnyNull and isNotNull.

Callers should take care to use the correct overload for their intent.

Since:
1.0
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    isAnyNull(Collection<?> collection)
    Checks if any element in the collection is null.
    static <T> boolean
    isAnyNull(T... objects)
    Checks if any of the provided objects are null.
    static boolean
    isEmpty(Collection<?> collection)
    Checks if the provided collection is empty or null.
    static boolean
    isEmpty(Map<?,?> map)
    Checks if the provided Map is empty or null.
    static <T> boolean
    isEmpty(T[] array)
    Checks if the provided array is empty or null.
    static <T> boolean
    isEmpty(T[]... arrays)
    Checks if all provided arrays are empty or null.
    static boolean
    isNotEmpty(Collection<?> collection)
    Checks if the provided collection is not null and not empty.
    static boolean
    isNotEmpty(Map<?,?> map)
    Checks if the provided Map is not null and not empty.
    static <T> boolean
    isNotEmpty(T[] array)
    Checks if the provided array is not null and not empty.
    static <T> boolean
    isNotEmpty(T[]... arrays)
    Checks if any of the provided arrays are not null and not empty.
    static boolean
    isNotNull(Collection<?> collection)
    Checks if all elements in the collection are non-null.
    static <T> boolean
    isNotNull(T... objects)
    Checks if all provided objects are non-null.
    static boolean
    isNull(Collection<?> collection)
    Checks if all elements in the collection are null.
    static <T> boolean
    isNull(T... objects)
    Checks if all provided objects are null.

    Methods inherited from class java.lang.Object

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

    • isAnyNull

      @SafeVarargs public static <T> boolean isAnyNull(T... objects)
      Checks if any of the provided objects are null.

      Returns true if the varargs array itself is null.

      Parameters:
      objects - the objects to check
      Returns:
      true if any object is null; false otherwise
      Since:
      1.0
    • isAnyNull

      public static boolean isAnyNull(Collection<?> collection)
      Checks if any element in the collection is null.

      Returns true if the collection itself is null.

      Parameters:
      collection - the collection to check
      Returns:
      true if any element is null; false otherwise
      Since:
      1.0
    • isEmpty

      public static <T> boolean isEmpty(T[] array)
      Checks if the provided array is empty or null.

      Note: this overload takes a plain array parameter. PMD's UseVarargs warning is suppressed intentionally as converting to varargs would create an ambiguous overload conflict with isEmpty(Object[]...).

      Parameters:
      array - the array to check; can be null
      Returns:
      true if the array is null or empty; false otherwise
      Since:
      1.0
    • isEmpty

      public static boolean isEmpty(Map<?,?> map)
      Checks if the provided Map is empty or null.
      Parameters:
      map - the map to check; can be null
      Returns:
      true if the map is null or empty; false otherwise
      Since:
      1.0
    • isEmpty

      @SafeVarargs public static <T> boolean isEmpty(T[]... arrays)
      Checks if all provided arrays are empty or null.

      Returns true if the varargs array itself is null or if every individual array is null or empty. Returns false as soon as any array contains at least one element. See the class-level note on varargs semantics.

      Parameters:
      arrays - the arrays to check; can be null or contain null elements
      Returns:
      true if all arrays are null or empty; false if any array is not empty
      Since:
      1.0
    • isEmpty

      public static boolean isEmpty(Collection<?> collection)
      Checks if the provided collection is empty or null.
      Parameters:
      collection - the collection to check; can be null
      Returns:
      true if the collection is null or empty; false otherwise
      Since:
      1.0
    • isEmpty

      @SafeVarargs public static <T extends Collection<?>> boolean isEmpty(T... collections)
      Checks if all provided collections are empty or null.

      Returns true if the varargs array itself is null or if every individual collection is null or empty. Returns false as soon as any collection contains at least one element. See the class-level note on varargs semantics.

      Parameters:
      collections - the collections to check; can be null or contain null elements
      Returns:
      true if all collections are null or empty; false if any collection is not empty
      Since:
      1.0
    • isNotEmpty

      public static <T> boolean isNotEmpty(T[] array)
      Checks if the provided array is not null and not empty.

      Note: this overload takes a plain array parameter. PMD's UseVarargs warning is suppressed intentionally as converting to varargs would create an ambiguous overload conflict with isNotEmpty(Object[]...).

      Parameters:
      array - the array to check; can be null
      Returns:
      true if the array is not null and not empty; false otherwise
      Since:
      1.0
    • isNotEmpty

      public static boolean isNotEmpty(Map<?,?> map)
      Checks if the provided Map is not null and not empty.
      Parameters:
      map - the map to check; can be null
      Returns:
      true if the map is not null and not empty; false otherwise
      Since:
      1.0
    • isNotEmpty

      @SafeVarargs public static <T> boolean isNotEmpty(T[]... arrays)
      Checks if any of the provided arrays are not null and not empty.

      Logical negation of isEmpty(Object[]...). Returns true as soon as any array contains at least one element. See the class-level note on varargs semantics.

      Parameters:
      arrays - the arrays to check; can be null or contain null elements
      Returns:
      true if any array is not null and not empty; false if all are null or empty
      Since:
      1.0
    • isNotEmpty

      public static boolean isNotEmpty(Collection<?> collection)
      Checks if the provided collection is not null and not empty.
      Parameters:
      collection - the collection to check; can be null
      Returns:
      true if the collection is not null and not empty; false otherwise
      Since:
      1.0
    • isNotEmpty

      @SafeVarargs public static <T extends Collection<?>> boolean isNotEmpty(T... collections)
      Checks if any of the provided collections are not null and not empty.

      Logical negation of isEmpty(Collection[]). Returns true as soon as any collection contains at least one element. See the class-level note on varargs semantics.

      Parameters:
      collections - the collections to check; can be null or contain null elements
      Returns:
      true if any collection is not null and not empty; false if all are null or empty
      Since:
      1.0
    • isNotNull

      @SafeVarargs public static <T> boolean isNotNull(T... objects)
      Checks if all provided objects are non-null.

      Returns false if the varargs array itself is null.

      Returns true for an empty argument list (vacuously true).

      Parameters:
      objects - the objects to check
      Returns:
      true if all objects are non-null; false otherwise
      Since:
      1.0
    • isNotNull

      public static boolean isNotNull(Collection<?> collection)
      Checks if all elements in the collection are non-null.

      Returns false if the collection itself is null.

      Parameters:
      collection - the collection to check
      Returns:
      true if all elements are non-null; false otherwise
      Since:
      1.0
    • isNull

      @SafeVarargs public static <T> boolean isNull(T... objects)
      Checks if all provided objects are null.

      Returns true if the varargs array itself is null.

      Returns true for an empty argument list (vacuously true).

      Parameters:
      objects - the objects to check
      Returns:
      true if all objects are null; false otherwise
      Since:
      1.0
    • isNull

      public static boolean isNull(Collection<?> collection)
      Checks if all elements in the collection are null.

      Returns true if the collection itself is null.

      Parameters:
      collection - the collection to check
      Returns:
      true if all elements are null; false otherwise
      Since:
      1.0