|
Assists in validating arguments. The class is based along the lines of JUnit. If an argument value is deemed invalid, an IllegalArgumentException is thrown. For example: Validate.isTrue( i>0, "The value must be greater than zero: ", i); Validate.notNull( surname, "The surname must not be null"); Constructor Detailpublic Validate() Constructor. This class should not normally be instantiated. Method Detail
Validate an argument, throwing IllegalArgumentException if the test result is false. This is used when validating according to an arbitrary boolean expression, such as validating a primitive number or using your own custom validation expression. Validate.isTrue( myObject.isOk(), "The object is not OK: ", myObject); For performance reasons, the object is passed as a separate parameter and appended to the message string only in the case of an error. Parameters: expressiona boolean expression messagethe exception message you would like to see if the expression is false valuethe value to append to the message in case of error Throws: java.lang.IllegalArgumentExceptionif expression is false public static void isTrue(boolean expression, java.lang.String message, long value) Validate an argument, throwing IllegalArgumentException if the test result is false. This is used 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: ", i); For performance reasons, the object is passed as a separate parameter and appended to the message string only in the case of an error. Parameters: expressiona boolean expression messagethe exception message you would like to see if the expression is false valuethe value to append to the message in case of error Throws: java.lang.IllegalArgumentExceptionif expression is false public static void isTrue(boolean expression, java.lang.String message, double value) Validate an argument, throwing IllegalArgumentException if the test result is false. This is used when validating according to an arbitrary boolean expression, such as validating a primitive number or using your own custom validation expression. Validate.isTrue( d>0.0, "The value must be greater than zero: ", d); For performance reasons, the object is passed as a separate parameter and appended to the message string only in the case of an error. Parameters: expressiona boolean expression messagethe exception message you would like to see if the expression is false valuethe value to append to the message in case of error Throws: java.lang.IllegalArgumentExceptionif expression is false public static void isTrue(boolean expression, java.lang.String message) Validate an argument, throwing IllegalArgumentException if the test result is false. This is used 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"); For performance reasons, the message string should not involve a string append, instead use the isTrue(boolean, String, Object) method. Parameters: expressiona boolean expression messagethe exception message you would like to see if the expression is false Throws: java.lang.IllegalArgumentExceptionif expression is false public static void isTrue(boolean expression) Validate an argument, throwing IllegalArgumentException if the test result is false. This is used 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 ); Validate.isTrue( myObject.isOk() ); The message in the exception is 'The validated expression is false'. Parameters: expressiona boolean expression Throws: java.lang.IllegalArgumentExceptionif expression is false public static void notNull(java.lang.Object object, java.lang.String message) Validate an argument, throwing IllegalArgumentException if the argument is null. Validate.notNull(myObject, "The object must not be null"); Parameters: objectthe object to check is not null messagethe exception message you would like to see if the object is null Throws: java.lang.IllegalArgumentExceptionif the object is null public static void notNull(java.lang.Object object) Validate an argument, throwing IllegalArgumentException if the argument is null. Validate.notNull(myObject); The message in the exception is 'The validated object is null'. Parameters: objectthe object to check is not null Throws: java.lang.IllegalArgumentExceptionif the object is null public static void notEmpty(java.lang.Object[] array, java.lang.String message) Validate an argument, throwing IllegalArgumentException if the argument array is empty (null or no elements). Validate.notEmpty(myArray, "The array must not be empty"); Parameters: arraythe array to check is not empty messagethe exception message you would like to see if the array is empty Throws: java.lang.IllegalArgumentExceptionif the array is empty public static void notEmpty(java.lang.Object[] array) Validate an argument, throwing IllegalArgumentException if the argument array is empty (null or no elements). Validate.notEmpty(myArray); The message in the exception is 'The validated array is empty'. Parameters: arraythe array to check is not empty Throws: java.lang.IllegalArgumentExceptionif the array is empty public static void notEmpty(java.util.Collection collection, java.lang.String message) Validate an argument, throwing IllegalArgumentException if the argument Collection is empty (null or no elements). Validate.notEmpty(myCollection, "The collection must not be empty"); Parameters: collectionthe collection to check is not empty messagethe exception message you would like to see if the collection is empty Throws: java.lang.IllegalArgumentExceptionif the collection is empty public static void notEmpty(java.util.Collection collection) Validate an argument, throwing IllegalArgumentException if the argument Collection is empty (null or no elements). Validate.notEmpty(myCollection); The message in the exception is 'The validated collection is empty'. Parameters: collectionthe collection to check is not empty Throws: java.lang.IllegalArgumentExceptionif the collection is empty public static void notEmpty(java.util.Map map, java.lang.String message) Validate an argument, throwing IllegalArgumentException if the argument Map is empty (null or no elements). Validate.notEmpty(myMap, "The collection must not be empty"); Parameters: mapthe map to check is not empty messagethe exception message you would like to see if the map is empty Throws: java.lang.IllegalArgumentExceptionif the map is empty public static void notEmpty(java.util.Map map) Validate an argument, throwing IllegalArgumentException if the argument Map is empty (null or no elements). Validate.notEmpty(myMap); The message in the exception is 'The validated map is empty'. Parameters: mapthe map to check is not empty Throws: java.lang.IllegalArgumentExceptionif the map is empty public static void notEmpty(java.lang.String string, java.lang.String message) Validate an argument, throwing IllegalArgumentException if the argument String is empty (null or zero length). Validate.notEmpty(myString, "The string must not be empty"); Parameters: stringthe string to check is not empty messagethe exception message you would like to see if the string is empty Throws: java.lang.IllegalArgumentExceptionif the string is empty public static void notEmpty(java.lang.String string) Validate an argument, throwing IllegalArgumentException if the argument String is empty (null or zero length). Validate.notEmpty(myString); The message in the exception is 'The validated string is empty'. Parameters: stringthe string to check is not empty Throws: java.lang.IllegalArgumentExceptionif the string is empty public static void noNullElements(java.lang.Object[] array, java.lang.String message) Validate an argument, throwing IllegalArgumentException if the argument array has null elements or is null. Validate.notEmpty(myArray, "The array must not contain null elements"); Parameters: arraythe array to check messagethe exception message if the array has null elements Throws: java.lang.IllegalArgumentExceptionif the array has null elements or is null public static void noNullElements(java.lang.Object[] array) Validate an argument, throwing IllegalArgumentException if the argument array has null elements or is null. Validate.notEmpty(myArray); The message in the exception is 'The validated array contains null element at index:'. Parameters: arraythe array to check Throws: java.lang.IllegalArgumentExceptionif the array has null elements or is null public static void noNullElements(java.util.Collection collection, java.lang.String message) Validate an argument, throwing IllegalArgumentException if the argument collection has null elements or is null. Validate.notEmpty(myCollection, "The collection must not contain null elements"); Parameters: collectionthe collection to check messagethe exception message if the array has null elements Throws: java.lang.IllegalArgumentExceptionif the collection has null elements or is null public static void noNullElements(java.util.Collection collection) Validate an argument, throwing IllegalArgumentException if the argument collection has null elements or is null. Validate.notEmpty(myCollection); The message in the exception is 'The validated collection contains null element at index:'. Parameters: collectionthe collection to check Throws: java.lang.IllegalArgumentExceptionif the collection has null elements or is null |
|