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 Summary

    Modifier and Type
    Method
    Description
    static void
    paramRequireNonNull(Object object1, Object object2, Object... objects)
    Validates multiple arguments are not null and throws NullPointerException if null.
    static <T> T
    Validates the argument is not null and throws NullPointerException if null.
    static <T> Collection<T>
    Validates the size of the para collection is not zero and throws IllegalArgumentException if zero.
    static <T> T[]
    paramSizeNonZero(T[] objects)
    Validates the length of the param array is not zero and throws IllegalArgumentException if zero.
    static <T> T
    requireNonEmpty(T object)
    Validates the variable is not null or blank("") and throws RequireNonEmptyException.
    static <T> T
    requireNonNull(T object)
    Validates the variable is not null and throws NullPointerException if null.
    static <T> T
    Validates the return value is not null and throws NullPointerException if null.

    Methods inherited from class java.lang.Object

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

    • paramRequireNonNull

      @Nonnull public static <T> T paramRequireNonNull(@RequireNonnull T object)
      Validates the argument is not null and throws NullPointerException if null.

      This is used for arguments of the method or constructor parameters as you can see it from the name of the method.

      Type Parameters:
      T - The class of the argument
      Parameters:
      object - Any object
      Returns:
      the argument
    • paramRequireNonNull

      @Nonnull public static void paramRequireNonNull(@RequireNonnull Object object1, @RequireNonnull Object object2, @RequireNonnull Object... objects)
      Validates multiple arguments are not null and throws NullPointerException if null.

      This is used to validate multiple arguments at one time.

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

      @Nonnull public static <T> T returnRequireNonNull(@RequireNonnull T object)
      Validates the return value is not null and throws NullPointerException if null.

      This is used for return values of the method or constructor parameters as you can see it from the name of the method.

      Type Parameters:
      T - The class of the argument
      Parameters:
      object - Any object
      Returns:
      the argument
    • requireNonNull

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

      @Nonnull public static <T> T requireNonEmpty(@RequireNonempty T object)
      Validates the variable is not null or blank("") and throws RequireNonEmptyException.

      It is valid only for String. For other datatatypes it's better to use requireNonnull(Object). But it's too strict for this method to throw an exception when the datatype is not String, so then validate whether it's null or not and throw the same exception if null.

      Type Parameters:
      T - The class of the argument
      Parameters:
      object - Any object
      Returns:
      the argument
    • paramSizeNonZero

      @Nonnull public static <T> T[] paramSizeNonZero(@RequireNonnull T[] objects)
      Validates the length of the param array is not zero and throws IllegalArgumentException if zero.
      Type Parameters:
      T - The class of the argument array
      Parameters:
      objects - Any object
      Returns:
      the argument
    • paramSizeNonZero

      @Nonnull public static <T> Collection<T> paramSizeNonZero(@RequireNonnull Collection<T> colleciton)
      Validates the size of the para collection is not zero and throws IllegalArgumentException if zero.
      Type Parameters:
      T - The class of the argument collection
      Parameters:
      colleciton - Any colleciton
      Returns:
      the argument