Class Validate


  • public class Validate
    extends Object
    Helper class that can be used to validate input.
    • Constructor Detail

      • Validate

        public Validate()
    • Method Detail

      • notNull

        public static void notNull​(Object object)

        Validate that the specified argument is not null; otherwise throwing an exception.

        Validate.notNull(myObject);

        The message of the exception is "The validated object is null".

        Parameters:
        object - the object to check
        Throws:
        IllegalArgumentException - if the object is null
      • notNull

        public static void notNull​(Object object,
                                   String message)

        Validate that the specified argument is not null; otherwise throwing an exception with the specified message.

        Validate.notNull(myObject, "The object must not be null");
        Parameters:
        object - the object to check
        message - the exception message if invalid
      • isTrue

        public static void isTrue​(boolean expression,
                                  String message)

        Validate that the argument condition is true; otherwise throwing an exception with the specified message. This method is useful when validating according to an arbitrary boolean expression, such as validating a primitive number or using your own custom validation expression.

         Validate.isTrue( (i > 0), "The value must be greater than zero");
         Validate.isTrue( myObject.isOk(), "The object is not OK");
         
        Parameters:
        expression - the boolean expression to check
        message - the exception message if invalid
        Throws:
        IllegalArgumentException - if expression is false
      • areEqual

        public static boolean areEqual​(@Nullable
                                       Bundle b1,
                                       @Nullable
                                       Bundle b2)

        Recursively check the bundles for equality

        Parameters:
        b1 - the Bundle to compare
        b2 - the Bundle to compare
        Returns:
        true if the bundles are identical or false otherwise
      • instanceOf

        @Nullable
        public static <T> T instanceOf​(@Nullable
                                       Throwable cause,
                                       @NonNull
                                       Class<T> cl)
        Search for the specific cause recursively
        Type Parameters:
        T - Specific cause type to search for
        Parameters:
        cause - Specified container cause
        cl - Specific cause class to search for
        Returns:
        Specific cause instance if it was found in the container cause, otherwise null