Class Validator


  • public final class Validator
    extends java.lang.Object
    This class assists in validating arguments.
    If an argument value is deemed invalid, an IllegalArgumentException is thrown.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void isNull​(java.lang.Object object, java.lang.String message)
      Validates that the specified argument is null; otherwise throwing an exception with the specified message.
      static void isTrue​(boolean expression, java.lang.String message)
      Validates that the argument condition is true; otherwise throwing an exception with the specified message.
      static void notEmpty​(java.lang.Object[] array, java.lang.String message)
      Validates that the specified argument array is neither null nor a length of zero (no elements); otherwise throwing an exception with the specified message.
      static void notEmpty​(java.lang.String string, java.lang.String message)
      Validator that the specified argument string is neither null nor a length of zero (no characters); otherwise throwing an exception with the specified message.
      static void notEmpty​(java.util.Collection collection, java.lang.String message)
      Validates that the specified argument collection is neither null nor a size of zero (no elements); otherwise throwing an exception with the specified message.
      static void notNull​(java.lang.Object object, java.lang.String message)
      Validates that the specified argument is not null; otherwise throwing an exception with the specified message.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isTrue

        public static void isTrue​(boolean expression,
                                  java.lang.String message)
        Validates 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.
        Parameters:
        expression - the boolean expression to check
        message - the exception message if invalid
        Throws:
        java.lang.IllegalArgumentException - if expression is false
      • notEmpty

        public static void notEmpty​(java.util.Collection collection,
                                    java.lang.String message)
        Validates that the specified argument collection is neither null nor a size of zero (no elements); otherwise throwing an exception with the specified message.
        Parameters:
        collection - the collection to check
        message - the exception message if invalid
        Throws:
        java.lang.IllegalArgumentException - if the collection is empty
      • notEmpty

        public static void notEmpty​(java.lang.Object[] array,
                                    java.lang.String message)
        Validates that the specified argument array is neither null nor a length of zero (no elements); otherwise throwing an exception with the specified message.
        Parameters:
        array - the array to check
        message - the exception message if invalid
        Throws:
        java.lang.IllegalArgumentException - if the array is empty
      • notEmpty

        public static void notEmpty​(java.lang.String string,
                                    java.lang.String message)
        Validator that the specified argument string is neither null nor a length of zero (no characters); otherwise throwing an exception with the specified message.
        Parameters:
        string - the string to check
        message - the exception message if invalid
        Throws:
        java.lang.IllegalArgumentException - if the string is empty
      • notNull

        public static void notNull​(java.lang.Object object,
                                   java.lang.String message)
        Validates that the specified argument is not null; otherwise throwing an exception with the specified message.
        Parameters:
        object - the object to check
        message - the exception message if invalid
      • isNull

        public static void isNull​(java.lang.Object object,
                                  java.lang.String message)
        Validates that the specified argument is null; otherwise throwing an exception with the specified message.
        Parameters:
        object - the object to check
        message - the exception message if invalid