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.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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
    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
  • Constructor Details

    • ObjectsUtil

      public ObjectsUtil()
  • 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
    • returnRequireNonNull

      @Nonnull public static <T> T returnRequireNonNull(@Nonnull 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
    • paramSizeNonZero

      @Nonnull public static <T> T[] paramSizeNonZero(@Nonnull 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(@Nonnull 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