Package com.castlabs.utils
Class Validate
- java.lang.Object
-
- com.castlabs.utils.Validate
-
public class Validate extends Object
Helper class that can be used to validate input.
-
-
Constructor Summary
Constructors Constructor Description Validate()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanareEqual(Bundle b1, Bundle b2)Recursively check the bundles for equalitystatic <T> TinstanceOf(Throwable cause, Class<T> cl)Search for the specific cause recursivelystatic voidisTrue(boolean expression, String message)Validate that the argument condition istrue; otherwise throwing an exception with the specified message.static voidnotNull(Object object)Validate that the specified argument is notnull; otherwise throwing an exception.static voidnotNull(Object object, String message)Validate that the specified argument is notnull; otherwise throwing an exception with the specified message.
-
-
-
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 isnull
-
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 checkmessage- 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 checkmessage- the exception message if invalid- Throws:
IllegalArgumentException- if expression isfalse
-
areEqual
public static boolean areEqual(@Nullable Bundle b1, @Nullable Bundle b2)Recursively check the bundles for equality
- Parameters:
b1- the Bundle to compareb2- the Bundle to compare- Returns:
trueif the bundles are identical orfalseotherwise
-
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 causecl- Specific cause class to search for- Returns:
- Specific cause instance if it was found in the container cause, otherwise
null
-
-