Class ObjectsUtil

java.lang.Object
jp.ecuacion.lib.core.util.ObjectsUtil

public class ObjectsUtil extends Object
Provides utility methods for Objects.requireNonnull and other checks.

Objects.requireNonnull throws NullPointerException and we can't see the difference whether it happens because of the parameter or return value check, or other reasons.
By using these methods you can see it by additional messages.

Several other methods provided to clarify an exception is thrown from ecuacion apps.

  • Method Details

    • requireNonNull

      @Nonnull public static <T> T requireNonNull(@RequireNonnull T object)
      Validates the argument is not null and throws RequireNonNullException if the argument value does not match the condition.
      Type Parameters:
      T - The class of the argument
      Parameters:
      object - Any object
      Returns:
      the argument
    • requireNonNull

      @Nonnull public static void requireNonNull(@RequireNonnull Object object1, @RequireNonnull Object object2, @RequireNonnull Object... objects)
      Validates multiple arguments are not null and throws RequireNonNullException if arguments value do not match the condition.

      This is used to validate multiple arguments at one time.

      Parameters:
      object1 - Any object
      object2 - Any object
      objects - Any objects
    • requireNonEmpty

      @Nonnull public static String requireNonEmpty(@RequireNonempty String string)
      Validates the argument is not null or blank("") and throws RequireNonEmptyException if the argument value does not match the condition.
      Parameters:
      string - Any string
      Returns:
      the argument
    • requireNonEmpty

      @Nonnull public static void requireNonEmpty(@RequireNonempty String string1, @RequireNonempty String string2, @RequireNonempty String... strings)
      Validates multiple arguments are not null or blank("") and throws RequireNonEmptyException if arguments value do not match the condition.
      Parameters:
      string1 - Any string
      string2 - Any string
      strings - Any strings
    • requireSizeNonZero

      @Nonnull public static <T> T[] requireSizeNonZero(@RequireSizeNonzero T[] objects)
      Validates the length of an array is not zero and throws RequireSizeNonZeroException if the argument value does not match the condition.
      Type Parameters:
      T - The class of the argument array
      Parameters:
      objects - Any object, null is acceptable.
      Returns:
      the argument
    • requireSizeNonZero

      @Nonnull public static <T> Collection<T> requireSizeNonZero(@RequireSizeNonzero Collection<T> collection)
      Validates the length of a collection is not zero and throws RequireSizeNonZeroException if the argument value does not match the condition.
      Type Parameters:
      T - The class of the argument collection
      Parameters:
      collection - Any collection, null is acceptable.
      Returns:
      the argument
    • requireElementNonNull

      @Nonnull public static <T> T[] requireElementNonNull(@RequireElementNonnull T[] objects)
      Validates elements of an array is not null and throws RequireElementNonNullException if the argument value does not match the condition.
      Type Parameters:
      T - The class of the argument array
      Parameters:
      objects - Any object, null is acceptable.
      Returns:
      the argument
    • requireElementNonNull

      @Nonnull public static <T> Collection<T> requireElementNonNull(@RequireElementNonnull Collection<T> collection)
      Validates elements of a collection is not null and throws RequireElementNonNullException if the argument value does not match the condition.
      Type Parameters:
      T - The class of the argument collection
      Parameters:
      collection - Any collection, null is acceptable.
      Returns:
      the argument
    • requireElementNonEmpty

      @Nonnull public static String[] requireElementNonEmpty(@RequireElementNonempty String[] strings)
      Validates elements of an array is not null and throws RequireElementNonEmptyException if the argument value does not match the condition.
      Parameters:
      strings - Any strings, null is acceptable.
      Returns:
      the argument
    • requireElementNonEmpty

      @Nonnull public static Collection<String> requireElementNonEmpty(@RequireElementNonempty Collection<String> collection)
      Validates elements of a collection is not null and throws RequireElementNonEmptyException if the argument value does not match the condition.
      Parameters:
      collection - Any collection, null is acceptable.
      Returns:
      the argument
    • requireElementsNonDuplicated

      @Nonnull public static <T> T[] requireElementsNonDuplicated(@RequireElementNonnull T[] objects)
      Validates elements of an array is not null and throws RequireElementNonNullException if the argument value does not match the condition.
      Type Parameters:
      T - The class of the argument array
      Parameters:
      objects - Any object, null is acceptable.
      Returns:
      the argument
    • requireElementsNonDuplicated

      @Nonnull public static <T> Collection<T> requireElementsNonDuplicated(@RequireElementNonnull Collection<T> collection)
      Validates elements of a collection is not null and throws RequireElementNonNullException if the argument value does not match the condition.
      Type Parameters:
      T - The class of the argument collection
      Parameters:
      collection - Any collection, null is acceptable.
      Returns:
      the argument