public final class Validate
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static void |
argumentNotNull(java.lang.Object object,
java.lang.String name)
Checks if the object is not
null . |
static void |
isTrue(boolean expression,
java.lang.String message)
Validate that the argument condition is
true ; otherwise
throwing an exception with the specified message. |
public static void argumentNotNull(java.lang.Object object, java.lang.String name) throws java.lang.IllegalArgumentException
null
. If it is null
throws IllegalArgumentException
.object
- argument to be validated.name
- argument name, used in exception message.java.lang.IllegalArgumentException
- if object
is null.public static void isTrue(boolean expression, java.lang.String message) throws java.lang.IllegalArgumentException
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");
expression
- the boolean expression to checkmessage
- the exception message if invalidjava.lang.IllegalArgumentException
- if expression is false