Class ObjectTools

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

public final class ObjectTools extends Object
Object Tools.

Unified utility methods for emptiness-checking objects, arrays, collections, maps, and character sequences.

Emptiness is defined only for types where the concept is meaningful: CharSequence, Collection, Map, and arrays. All other non-null objects are considered not empty.

Multi-value helpers are provided as both predicates and validators.

Since:
1.0
Author:
Erik C. Thauvin
  • Method Details

    • allEmpty

      public static boolean allEmpty(@Nullable Object... values)
      Returns true if all provided values are empty.
      Parameters:
      values - the values to inspect; may be null
      Returns:
      true if all values are empty
      Since:
      1.3
    • allNotEmpty

      public static boolean allNotEmpty(@Nullable Object... values)
      Returns true if all provided values are not empty.
      Parameters:
      values - the values to inspect; may be null
      Returns:
      true if all values are not empty
      Since:
      1.3
    • anyNotEmpty

      public static boolean anyNotEmpty(@Nullable Object... values)
      Returns true if at least one of the provided values is not empty.
      Parameters:
      values - the values to inspect; may be null
      Returns:
      true if any value is not empty
      Since:
      1.3
    • isEmpty

      public static boolean isEmpty(@Nullable Object value)
      Determines whether the given value is null or empty.

      Emptiness is defined for CharSequence, Collection, Map, and arrays. All other non-null objects are considered not empty.

      Parameters:
      value - the value to inspect; may be null
      Returns:
      true if the value is null or empty
    • isNotEmpty

      public static boolean isNotEmpty(@Nullable Object value)
      Determines whether the given value is not null and not empty.
      Parameters:
      value - the value to inspect; may be null
      Returns:
      true if the value is not null and not empty
    • requireAllEmpty

      public static void requireAllEmpty(@Nullable Object[] values, String message)
      Requires all provided values to be empty.

      The array itself must not be null, but may be empty (all elements are empty). All elements must be null or empty.

      Parameters:
      values - the values to inspect; must not be null
      message - the exception message; must not be null or empty
      Throws:
      IllegalArgumentException - if any value is not empty
      IllegalArgumentException - if values array is null
      IllegalArgumentException - if message is null or empty
      Since:
      1.3
    • requireAllEmpty

      public static void requireAllEmpty(@Nullable Object[] values, String message, @Nullable Object... args)
      Requires all provided values to be empty.

      The array itself must not be null, but may be empty (all elements are empty). All elements must be null or empty. The message may contain String.format(String, Object...) placeholders, which are resolved using the supplied args. If formatting fails, the raw message is used.

      Parameters:
      values - the values to inspect; must not be null
      message - the exception message or format string; must not be null or empty
      args - optional arguments used to format the message
      Throws:
      IllegalArgumentException - if any value is not empty
      IllegalArgumentException - if values array is null
      IllegalArgumentException - if message is null or empty
      Since:
      1.3
    • requireAllEmpty

      public static void requireAllEmpty(@Nullable Map<?,?> map, String message)
      Requires all values in the provided map to be empty.

      The map itself may be null or empty. If it is non-empty, all values must be null or empty as defined by isEmpty(Object). If any value is not empty, an IllegalArgumentException is thrown.

      Since:
      1.3
    • requireAllEmpty

      public static void requireAllEmpty(@Nullable Map<?,?> map, String message, @Nullable Object... args)
      Requires all values in the provided map to be empty.

      The map itself may be null or empty. If it is non-empty, all values must be null or empty as defined by isEmpty(Object). The message may contain String.format(String, Object...) placeholders, which are resolved using the supplied args. If formatting fails, the raw message is used.

      Since:
      1.3
    • requireAllEmpty

      public static void requireAllEmpty(@Nullable Collection<?> values, String message)
      Requires all provided collection elements to be empty.

      The collection itself must not be null, but may be empty. All elements must be null or empty as defined by isEmpty(Object). If any element is not empty, an IllegalArgumentException is thrown.

      Since:
      1.2
    • requireAllEmpty

      public static void requireAllEmpty(@Nullable Collection<?> values, String message, @Nullable Object... args)
      Requires all provided collection elements to be empty.

      The collection itself must not be null, but may be empty. All elements must be null or empty as defined by isEmpty(Object). The message may contain String.format(String, Object...) placeholders, which are resolved using the supplied args. If formatting fails, the raw message is used.

      Since:
      1.2
    • requireAllNotEmpty

      public static void requireAllNotEmpty(@Nullable Object[] values, String message)
      Requires all provided values to be not empty.

      The array itself must not be null or empty, and none of its elements may be null or empty.

      Parameters:
      values - the values to inspect; must not be null or empty
      message - the exception message; must not be null or empty
      Throws:
      IllegalArgumentException - if values array is null or empty
      IllegalArgumentException - if any value is null or empty
      IllegalArgumentException - if message is null or empty
      Since:
      1.3
    • requireAllNotEmpty

      public static void requireAllNotEmpty(@Nullable Object[] values, String message, @Nullable Object... args)
      Requires all provided values to be not empty.

      The array itself must not be null or empty, and none of its elements may be null or empty. The message may contain String.format(String, Object...) placeholders, which are resolved using the supplied args. If formatting fails, the raw message is used.

      Parameters:
      values - the values to inspect; must not be null or empty
      message - the exception message or format string; must not be null or empty
      args - optional arguments used to format the message
      Throws:
      IllegalArgumentException - if values array is null or empty
      IllegalArgumentException - if any value is null or empty
      IllegalArgumentException - if message is null or empty
      Since:
      1.3
    • requireAllNotEmpty

      public static void requireAllNotEmpty(@Nullable Map<?,?> map, String message)
      Requires the provided map to be not empty, and all of its values to be not empty.

      The map itself must not be null or empty, and none of its values may be null or empty as defined by isEmpty(Object). If the map is null, empty, or contains any empty value, an IllegalArgumentException is thrown.

      Since:
      1.3
    • requireAllNotEmpty

      public static void requireAllNotEmpty(@Nullable Map<?,?> map, String message, @Nullable Object... args)
      Requires the provided map to be not empty, and all of its values to be not empty.

      The map itself must not be null or empty, and none of its values may be null or empty as defined by isEmpty(Object). The message may contain String.format(String, Object...) placeholders, which are resolved using the supplied args. If formatting fails, the raw message is used.

      Since:
      1.3
    • requireAllNotEmpty

      public static void requireAllNotEmpty(@Nullable Collection<?> values, String message)
      Requires all provided collection elements to be not empty.

      The collection itself must not be null or empty, and none of its elements may be null or empty as defined by isEmpty(Object). If the collection is null, empty, or contains any empty element, an IllegalArgumentException is thrown.

      Since:
      1.2
    • requireAllNotEmpty

      public static void requireAllNotEmpty(@Nullable Collection<?> values, String message, @Nullable Object... args)
      Requires all provided collection elements to be not empty.

      The collection itself must not be null or empty, and none of its elements may be null or empty as defined by isEmpty(Object). The message may contain String.format(String, Object...) placeholders, which are resolved using the supplied args. If formatting fails, the raw message is used.

      Since:
      1.2
    • requireEmpty

      public static <T> T requireEmpty(@Nullable T value, String message)
      Requires the given value to be empty.

      Emptiness is defined for CharSequence, Collection, Map, and arrays. All other non-null objects are considered not empty. If the value is not empty, an IllegalArgumentException is thrown. Otherwise, the original value is returned unchanged.

      Type Parameters:
      T - the value type
      Parameters:
      value - the value to inspect; may be null
      message - the exception message; must not be null or empty
      Returns:
      the original value if it is empty
      Throws:
      IllegalArgumentException - if the value is not empty
      IllegalArgumentException - if message is null or empty
      Since:
      1.3
    • requireEmpty

      public static <T> T requireEmpty(@Nullable T value, String message, @Nullable Object... args)
      Requires the given value to be empty.

      Emptiness is defined for CharSequence, Collection, Map, and arrays. All other non-null objects are considered not empty. If the value is not empty, an IllegalArgumentException is thrown. The message may contain String.format(String, Object...) placeholders, which are resolved using the supplied args. If formatting fails, the raw message is used. Otherwise, the original value is returned unchanged.

      Type Parameters:
      T - the value type
      Parameters:
      value - the value to inspect; may be null
      message - the exception message or format string; must not be null or empty
      args - optional arguments used to format the message
      Returns:
      the original value if it is empty
      Throws:
      IllegalArgumentException - if the value is not empty
      IllegalArgumentException - if message is null or empty
      Since:
      1.3
    • requireNotEmpty

      public static <T> T requireNotEmpty(@Nullable T value, String message)
      Requires the given value to be not empty.

      Emptiness is defined for CharSequence, Collection, Map, and arrays. All other non-null objects are considered not empty. If the value is empty, an IllegalArgumentException is thrown. Otherwise, the original value is returned unchanged.

      Type Parameters:
      T - the value type
      Parameters:
      value - the value to inspect; may be null
      message - the exception message; must not be null or empty
      Returns:
      the original value if it is not empty
      Throws:
      IllegalArgumentException - if the value is null or empty
      IllegalArgumentException - if message is null or empty
      Since:
      1.3
    • requireNotEmpty

      public static <T> T requireNotEmpty(@Nullable T value, String message, @Nullable Object... args)
      Requires the given value to be not empty.

      Emptiness is defined for CharSequence, Collection, Map, and arrays. All other non-null objects are considered not empty. If the value is empty, an IllegalArgumentException is thrown. The message may contain String.format(String, Object...) placeholders, which are resolved using the supplied args. If formatting fails, the raw message is used. Otherwise, the original value is returned unchanged.

      Type Parameters:
      T - the value type
      Parameters:
      value - the value to inspect; may be null
      message - the exception message or format string; must not be null or empty
      args - optional arguments used to format the message
      Returns:
      the original value if it is not empty
      Throws:
      IllegalArgumentException - if the value is null or empty
      IllegalArgumentException - if message is null or empty
      Since:
      1.3