Package com.castlabs.utils
Class Validate
java.lang.Object
com.castlabs.utils.Validate
Helper class that can be used to validate input.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanRecursively check the bundles for equalitystatic <T> TinstanceOf(Throwable cause, Class<T> cl) Search for the specific cause recursivelystatic voidValidate that the argument condition istrue; otherwise throwing an exception with the specified message.static voidValidate that the specified argument is notnull; otherwise throwing an exception.static voidValidate that the specified argument is notnull; otherwise throwing an exception with the specified message.
-
Constructor Details
-
Validate
public Validate()
-
-
Method Details
-
notNull
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 isnull
-
notNull
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 checkmessage- the exception message if invalid
-
isTrue
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 checkmessage- the exception message if invalid- Throws:
IllegalArgumentException- if expression isfalse
-
areEqual
Recursively check the bundles for equality
- Parameters:
b1- the Bundle to compareb2- the Bundle to compare- Returns:
trueif the bundles are identical orfalseotherwise
-
instanceOf
Search for the specific cause recursively- Type Parameters:
T- Specific cause type to search for- Parameters:
cause- Specified container causecl- Specific cause class to search for- Returns:
- Specific cause instance if it was found in the container cause, otherwise
null
-