public class Validate extends Object
| 构造器和说明 |
|---|
Validate() |
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
isTrue(boolean expression)
Validate that the argument condition is
true; otherwise
throwing an exception. |
static void |
isTrue(boolean expression,
String message,
double value)
Validate that the argument condition is
true; otherwise
throwing an exception with the specified message. |
static void |
isTrue(boolean expression,
String message,
long value)
Validate that the argument condition is
true; otherwise
throwing an exception with the specified message. |
static void |
isTrue(boolean expression,
String message,
Object... values)
Validate that the argument condition is
true; otherwise
throwing an exception with the specified message. |
static <T> T |
notNull(T object)
Validate that the specified argument is not
null;
otherwise throwing an exception. |
static <T> T |
notNull(T object,
String message,
Object... values)
Validate that the specified argument is not
null;
otherwise throwing an exception with the specified message. |
public static void isTrue(boolean expression,
String message,
long value)
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.0, "The value must be greater than zero: %d", i);
For performance reasons, the long value is passed as a separate parameter and appended to the exception message only in the case of an error.
expression - the boolean expression to checkmessage - the String.format(String, Object...) exception message if invalid, not nullvalue - the value to append to the message when invalidIllegalArgumentException - if expression is falseisTrue(boolean),
isTrue(boolean, String, double),
isTrue(boolean, String, Object...)public static void isTrue(boolean expression,
String message,
double value)
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(d > 0.0, "The value must be greater than zero: %s", d);
For performance reasons, the double value is passed as a separate parameter and appended to the exception message only in the case of an error.
expression - the boolean expression to checkmessage - the String.format(String, Object...) exception message if invalid, not nullvalue - the value to append to the message when invalidIllegalArgumentException - if expression is falseisTrue(boolean),
isTrue(boolean, String, long),
isTrue(boolean, String, Object...)public static void isTrue(boolean expression,
String message,
Object... values)
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 >= min && i <= max, "The value must be between %d and %d", min, max); Validate.isTrue(myObject.isOk(), "The object is not okay");
expression - the boolean expression to checkmessage - the String.format(String, Object...) exception message if invalid, not nullvalues - the optional values for the formatted exception message, null array not recommendedIllegalArgumentException - if expression is falseisTrue(boolean),
isTrue(boolean, String, long),
isTrue(boolean, String, double)public static void isTrue(boolean expression)
Validate that the argument condition is true; otherwise
throwing an exception. 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); Validate.isTrue(myObject.isOk());
The message of the exception is "The validated expression is false".
expression - the boolean expression to checkIllegalArgumentException - if expression is falseisTrue(boolean, String, long),
isTrue(boolean, String, double),
isTrue(boolean, String, Object...)public static <T> T notNull(T object)
Validate that the specified argument is not null;
otherwise throwing an exception.
Validate.notNull(myObject, "The object must not be null");
The message of the exception is "The validated object is null".
T - the object typeobject - the object to checknull for method chaining)NullPointerException - if the object is nullnotNull(Object, String, Object...)public static <T> T notNull(T object,
String message,
Object... values)
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");
T - the object typeobject - the object to checkmessage - the String.format(String, Object...) exception message if invalid, not nullvalues - the optional values for the formatted exception messagenull for method chaining)NullPointerException - if the object is nullnotNull(Object)Copyright © 2018–2022 Alibaba Group. All rights reserved.