至今单身的牛排 · Oops!!! - 简书· 1 年前 · |
玩篮球的四季豆 · AddJavaScriptTag ...· 1 年前 · |
从容的青蛙 · jQuery框架安装及jQuery特点介绍- ...· 1 年前 · |
精明的手套 · C++编程笔记:dll的生成与使用_c++使 ...· 1 年前 · |
憨厚的墨镜 · SQL COUNT函数-之路教程· 1 年前 · |
public class Validate extends Object
null
argument causes a
NullPointerException
.
null
argument causes an
IllegalArgumentException
.
IndexOutOfBoundsException
.
All exceptions messages are format strings as defined by the Java platform. For example: Validate.isTrue(i > 0, "The value must be greater than zero: %d", i); Validate.notNull(surname, "The surname must not be %s", null);
#ThreadSafe#
String.format(String, Object...)
static void
exclusiveBetween
(double start,
double end,
double value,
String
message)
static void
exclusiveBetween
(long start,
long end,
long value)
static void
exclusiveBetween
(long start,
long end,
long value,
String
message)
static <T> void
exclusiveBetween
(T start,
T end,
Comparable
<T> value)
static <T> void
exclusiveBetween
(T start,
T end,
Comparable
<T> value,
String
message,
Object
... values)
static void
finite
(double value)
static void
finite
(double value,
String
message,
Object
... values)
static void
inclusiveBetween
(double start,
double end,
double value)
static void
inclusiveBetween
(double start,
double end,
double value,
String
message)
static void
inclusiveBetween
(long start,
long end,
long value)
static void
inclusiveBetween
(long start,
long end,
long value,
String
message)
static <T> void
inclusiveBetween
(T start,
T end,
Comparable
<T> value)
static <T> void
inclusiveBetween
(T start,
T end,
Comparable
<T> value,
String
message,
Object
... values)
static void
isAssignableFrom
(
Class
<?> superType,
Class
<?> type)
static void
isAssignableFrom
(
Class
<?> superType,
Class
<?> type,
String
message,
Object
... values)
static void
isInstanceOf
(
Class
<?> type,
Object
obj)
static void
isInstanceOf
(
Class
<?> type,
Object
obj,
String
message,
Object
... values)
static void
isTrue
(boolean expression)
true
; otherwise
throwing an exception.
static void
isTrue
(boolean expression,
String
message,
double value)
true
; otherwise
throwing an exception with the specified message.
static void
isTrue
(boolean expression,
String
message,
long value)
true
; otherwise
throwing an exception with the specified message.
static void
isTrue
(boolean expression,
String
message,
Object
... values)
true
; otherwise
throwing an exception with the specified message.
static void
matchesPattern
(
CharSequence
input,
String
pattern)
static void
matchesPattern
(
CharSequence
input,
String
pattern,
String
message,
Object
... values)
static <T extends
Iterable
<?>>
T
noNullElements
(T iterable)
null
nor contains any elements that are
null
;
otherwise throwing an exception.
static <T> T[]
noNullElements
(T[] array)
null
nor contains any elements that are
null
;
otherwise throwing an exception.
static <T> T[]
noNullElements
(T[] array,
String
message,
Object
... values)
null
nor contains any elements that are
null
;
otherwise throwing an exception with the specified message.
static <T extends
Iterable
<?>>
T
noNullElements
(T iterable,
String
message,
Object
... values)
null
nor contains any elements that are
null
;
otherwise throwing an exception with the specified message.
static <T extends
CharSequence
>
T
notBlank
(T chars)
null
, a length of zero (no characters), empty
nor whitespace; otherwise throwing an exception.
static <T extends
CharSequence
>
T
notBlank
(T chars,
String
message,
Object
... values)
null
, a length of zero (no characters), empty
nor whitespace; otherwise throwing an exception with the specified
message.
static <T extends
CharSequence
>
T
notEmpty
(T chars)
null
nor a length of zero (no characters);
otherwise throwing an exception with the specified message.
static <T extends
Collection
<?>>
T
notEmpty
(T collection)
null
nor a size of zero (no elements); otherwise throwing an exception.
static <T extends
Map
<?,?>>
T
notEmpty
(T map)
null
nor a size of zero (no elements); otherwise throwing an exception.
static <T> T[]
notEmpty
(T[] array)
null
nor a length of zero (no elements); otherwise throwing an exception.
static <T> T[]
notEmpty
(T[] array,
String
message,
Object
... values)
null
nor a length of zero (no elements); otherwise throwing an exception
with the specified message.
static <T extends
CharSequence
>
T
notEmpty
(T chars,
String
message,
Object
... values)
null
nor a length of zero (no characters);
otherwise throwing an exception with the specified message.
static <T extends
Collection
<?>>
T
notEmpty
(T collection,
String
message,
Object
... values)
null
nor a size of zero (no elements); otherwise throwing an exception
with the specified message.
static <T extends
Map
<?,?>>
T
notEmpty
(T map,
String
message,
Object
... values)
null
nor a size of zero (no elements); otherwise throwing an exception
with the specified message.
static void
notNaN
(double value)
static void
notNaN
(double value,
String
message,
Object
... values)
static <T> T
notNull
(T object)
validIndex
(T[] array,
int index)
static <T> T[]
validIndex
(T[] array,
int index,
String
message,
Object
... values)
static <T extends
CharSequence
>
T
validIndex
(T chars,
int index)
static <T extends
Collection
<?>>
T
validIndex
(T collection,
int index)
static <T extends
CharSequence
>
T
validIndex
(T chars,
int index,
String
message,
Object
... values)
static <T extends
Collection
<?>>
T
validIndex
(T collection,
int index,
String
message,
Object
... values)
static void
validState
(boolean expression)
true
; otherwise
throwing an exception.
static void
validState
(boolean expression,
String
message,
Object
... values)
true
; otherwise
throwing an exception with the specified message.
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 check
message
- the
String.format(String, Object...)
exception message if invalid, not null
value
- the value to append to the message when invalid
IllegalArgumentException
- if expression is
false
isTrue(boolean)
,
isTrue(boolean, String, double)
,
isTrue(boolean, String, Object...)
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 check
message
- the
String.format(String, Object...)
exception message if invalid, not null
value
- the value to append to the message when invalid
IllegalArgumentException
- if expression is
false
isTrue(boolean)
,
isTrue(boolean, String, long)
,
isTrue(boolean, String, Object...)
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);
expression
- the boolean expression to check
message
- the
String.format(String, Object...)
exception message if invalid, not null
values
- the optional values for the formatted exception message, null array not recommended
IllegalArgumentException
- if expression is
false
isTrue(boolean)
,
isTrue(boolean, String, long)
,
isTrue(boolean, String, double)
public static void isTrue(boolean expression)
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 check
IllegalArgumentException
- if expression is
false
isTrue(boolean, String, long)
,
isTrue(boolean, String, double)
,
isTrue(boolean, String, Object...)
@Deprecated public static <T> T notNull(T object)
Objects.requireNonNull(Object)
.
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 type
object
- the object to check
null
for method chaining)
NullPointerException
- if the object is
null
notNull(Object, String, Object...)
null
;
otherwise throwing an exception with the specified message.
Validate.notNull(myObject, "The object must not be null");
T
- the object type
object
- the object to check
message
- the
String.format(String, Object...)
exception message if invalid, not null
values
- the optional values for the formatted exception message
null
for method chaining)
NullPointerException
- if the object is
null
Objects.requireNonNull(Object)
Validate that the specified argument array is neither
null
nor a length of zero (no elements); otherwise throwing an exception
with the specified message.
Validate.notEmpty(myArray, "The array must not be empty");
T
- the array type
array
- the array to check, validated not null by this method
message
- the
String.format(String, Object...)
exception message if invalid, not null
values
- the optional values for the formatted exception message, null array not recommended
null
method for chaining)
NullPointerException
- if the array is
null
IllegalArgumentException
- if the array is empty
notEmpty(Object[])
public static <T> T[] notEmpty(T[] array)
Validate that the specified argument array is neither
null
nor a length of zero (no elements); otherwise throwing an exception.
Validate.notEmpty(myArray);
The message in the exception is "The validated array is empty".
T
- the array type
array
- the array to check, validated not null by this method
null
method for chaining)
NullPointerException
- if the array is
null
IllegalArgumentException
- if the array is empty
notEmpty(Object[], String, Object...)
public static <T extends Collection<?>> T notEmpty(T collection, String message, Object... values)
Validate that the specified argument collection is neither
null
nor a size of zero (no elements); otherwise throwing an exception
with the specified message.
Validate.notEmpty(myCollection, "The collection must not be empty");
T
- the collection type
collection
- the collection to check, validated not null by this method
message
- the
String.format(String, Object...)
exception message if invalid, not null
values
- the optional values for the formatted exception message, null array not recommended
null
method for chaining)
NullPointerException
- if the collection is
null
IllegalArgumentException
- if the collection is empty
notEmpty(Object[])
public static <T extends Collection<?>> T notEmpty(T collection)
Validate that the specified argument collection is neither
null
nor a size of zero (no elements); otherwise throwing an exception.
Validate.notEmpty(myCollection);
The message in the exception is "The validated collection is empty".
T
- the collection type
collection
- the collection to check, validated not null by this method
null
method for chaining)
NullPointerException
- if the collection is
null
IllegalArgumentException
- if the collection is empty
notEmpty(Collection, String, Object...)
null
nor a size of zero (no elements); otherwise throwing an exception
with the specified message.
Validate.notEmpty(myMap, "The map must not be empty");
T
- the map type
map
- the map to check, validated not null by this method
message
- the
String.format(String, Object...)
exception message if invalid, not null
values
- the optional values for the formatted exception message, null array not recommended
null
method for chaining)
NullPointerException
- if the map is
null
IllegalArgumentException
- if the map is empty
notEmpty(Object[])
public static <T extends Map<?,?>> T notEmpty(T map)
Validate that the specified argument map is neither
null
nor a size of zero (no elements); otherwise throwing an exception.
Validate.notEmpty(myMap);
The message in the exception is "The validated map is empty".
T
- the map type
map
- the map to check, validated not null by this method
null
method for chaining)
NullPointerException
- if the map is
null
IllegalArgumentException
- if the map is empty
notEmpty(Map, String, Object...)
public static <T extends CharSequence> T notEmpty(T chars, String message, Object... values)
null
nor a length of zero (no characters);
otherwise throwing an exception with the specified message.
Validate.notEmpty(myString, "The string must not be empty");
T
- the character sequence type
chars
- the character sequence to check, validated not null by this method
message
- the
String.format(String, Object...)
exception message if invalid, not null
values
- the optional values for the formatted exception message, null array not recommended
null
method for chaining)
NullPointerException
- if the character sequence is
null
IllegalArgumentException
- if the character sequence is empty
notEmpty(CharSequence)
public static <T extends CharSequence> T notEmpty(T chars)
Validate that the specified argument character sequence is
neither
null
nor a length of zero (no characters);
otherwise throwing an exception with the specified message.
Validate.notEmpty(myString);
The message in the exception is "The validated character sequence is empty".
T
- the character sequence type
chars
- the character sequence to check, validated not null by this method
null
method for chaining)
NullPointerException
- if the character sequence is
null
IllegalArgumentException
- if the character sequence is empty
notEmpty(CharSequence, String, Object...)
public static <T extends CharSequence> T notBlank(T chars, String message, Object... values)
null
, a length of zero (no characters), empty
nor whitespace; otherwise throwing an exception with the specified
message.
Validate.notBlank(myString, "The string must not be blank");
T
- the character sequence type
chars
- the character sequence to check, validated not null by this method
message
- the
String.format(String, Object...)
exception message if invalid, not null
values
- the optional values for the formatted exception message, null array not recommended
null
method for chaining)
NullPointerException
- if the character sequence is
null
IllegalArgumentException
- if the character sequence is blank
notBlank(CharSequence)
public static <T extends CharSequence> T notBlank(T chars)
Validate that the specified argument character sequence is
neither
null
, a length of zero (no characters), empty
nor whitespace; otherwise throwing an exception.
Validate.notBlank(myString);
The message in the exception is "The validated character sequence is blank".
T
- the character sequence type
chars
- the character sequence to check, validated not null by this method
null
method for chaining)
NullPointerException
- if the character sequence is
null
IllegalArgumentException
- if the character sequence is blank
notBlank(CharSequence, String, Object...)
null
nor contains any elements that are
null
;
otherwise throwing an exception with the specified message.
Validate.noNullElements(myArray, "The array contain null at position %d");
If the array is
null
, then the message in the exception
is "The validated object is null".
If the array has a
null
element, then the iteration
index of the invalid element is appended to the
values
argument.
T
- the array type
array
- the array to check, validated not null by this method
message
- the
String.format(String, Object...)
exception message if invalid, not null
values
- the optional values for the formatted exception message, null array not recommended
null
method for chaining)
NullPointerException
- if the array is
null
IllegalArgumentException
- if an element is
null
noNullElements(Object[])
public static <T> T[] noNullElements(T[] array)
null
nor contains any elements that are
null
;
otherwise throwing an exception.
Validate.noNullElements(myArray);
If the array is
null
, then the message in the exception
is "The validated object is null".
If the array has a
null
element, then the message in the
exception is "The validated array contains null element at index:
" followed by the index.
T
- the array type
array
- the array to check, validated not null by this method
null
method for chaining)
NullPointerException
- if the array is
null
IllegalArgumentException
- if an element is
null
noNullElements(Object[], String, Object...)
public static <T extends Iterable<?>> T noNullElements(T iterable, String message, Object... values)
null
nor contains any elements that are
null
;
otherwise throwing an exception with the specified message.
Validate.noNullElements(myCollection, "The collection contains null at position %d");
If the iterable is
null
, then the message in the exception
is "The validated object is null".
If the iterable has a
null
element, then the iteration
index of the invalid element is appended to the
values
argument.
T
- the iterable type
iterable
- the iterable to check, validated not null by this method
message
- the
String.format(String, Object...)
exception message if invalid, not null
values
- the optional values for the formatted exception message, null array not recommended
null
method for chaining)
NullPointerException
- if the array is
null
IllegalArgumentException
- if an element is
null
noNullElements(Iterable)
public static <T extends Iterable<?>> T noNullElements(T iterable)
null
nor contains any elements that are
null
;
otherwise throwing an exception.
Validate.noNullElements(myCollection);
If the iterable is
null
, then the message in the exception
is "The validated object is null".
If the array has a
null
element, then the message in the
exception is "The validated iterable contains null element at index:
" followed by the index.
T
- the iterable type
iterable
- the iterable to check, validated not null by this method
null
method for chaining)
NullPointerException
- if the array is
null
IllegalArgumentException
- if an element is
null
noNullElements(Iterable, String, Object...)
Validate.validIndex(myArray, 2, "The array index is invalid: ");
If the array is
null
, then the message of the exception
is "The validated object is null".
T
- the array type
array
- the array to check, validated not null by this method
index
- the index to check
message
- the
String.format(String, Object...)
exception message if invalid, not null
values
- the optional values for the formatted exception message, null array not recommended
null
for method chaining)
NullPointerException
- if the array is
null
IndexOutOfBoundsException
- if the index is invalid
validIndex(Object[], int)
public static <T> T[] validIndex(T[] array, int index)
Validate.validIndex(myArray, 2);
If the array is
null
, then the message of the exception
is "The validated object is null".
If the index is invalid, then the message of the exception is "The validated array index is invalid: " followed by the index.
T
- the array type
array
- the array to check, validated not null by this method
index
- the index to check
null
for method chaining)
NullPointerException
- if the array is
null
IndexOutOfBoundsException
- if the index is invalid
validIndex(Object[], int, String, Object...)
public static <T extends Collection<?>> T validIndex(T collection, int index, String message, Object... values)
Validate.validIndex(myCollection, 2, "The collection index is invalid: ");
If the collection is
null
, then the message of the
exception is "The validated object is null".
T
- the collection type
collection
- the collection to check, validated not null by this method
index
- the index to check
message
- the
String.format(String, Object...)
exception message if invalid, not null
values
- the optional values for the formatted exception message, null array not recommended
null
for chaining)
NullPointerException
- if the collection is
null
IndexOutOfBoundsException
- if the index is invalid
validIndex(Collection, int)
public static <T extends Collection<?>> T validIndex(T collection, int index)
Validate.validIndex(myCollection, 2);
If the index is invalid, then the message of the exception is "The validated collection index is invalid: " followed by the index.
T
- the collection type
collection
- the collection to check, validated not null by this method
index
- the index to check
null
for method chaining)
NullPointerException
- if the collection is
null
IndexOutOfBoundsException
- if the index is invalid
validIndex(Collection, int, String, Object...)
Validate.validIndex(myStr, 2, "The string index is invalid: ");
If the character sequence is
null
, then the message
of the exception is "The validated object is null".
T
- the character sequence type
chars
- the character sequence to check, validated not null by this method
index
- the index to check
message
- the
String.format(String, Object...)
exception message if invalid, not null
values
- the optional values for the formatted exception message, null array not recommended
null
for method chaining)
NullPointerException
- if the character sequence is
null
IndexOutOfBoundsException
- if the index is invalid
validIndex(CharSequence, int)
public static <T extends CharSequence> T validIndex(T chars, int index)
Validate.validIndex(myStr, 2);
If the character sequence is
null
, then the message
of the exception is "The validated object is
null".
If the index is invalid, then the message of the exception is "The validated character sequence index is invalid: " followed by the index.
T
- the character sequence type
chars
- the character sequence to check, validated not null by this method
index
- the index to check
null
for method chaining)
NullPointerException
- if the character sequence is
null
IndexOutOfBoundsException
- if the index is invalid
validIndex(CharSequence, int, String, Object...)
public static void validState(boolean expression)
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.validState(field > 0);
Validate.validState(this.isOk());
The message of the exception is "The validated state is false".
expression
- the boolean expression to check
IllegalStateException
- if expression is
false
validState(boolean, String, Object...)
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.validState(this.isOk(), "The state is not OK: %s", myObject);
expression
- the boolean expression to check
message
- the
String.format(String, Object...)
exception message if invalid, not null
values
- the optional values for the formatted exception message, null array not recommended
IllegalStateException
- if expression is
false
validState(boolean)
public static void matchesPattern(CharSequence input, String pattern)
Validate.matchesPattern("hi", "[a-z]*");
The syntax of the pattern is the one used in the
Pattern
class.
input
- the character sequence to validate, not null
pattern
- the regular expression pattern, not null
IllegalArgumentException
- if the character sequence does not match the pattern
matchesPattern(CharSequence, String, String, Object...)
public static void matchesPattern(CharSequence input, String pattern, String message, Object... values)
Validate.matchesPattern("hi", "[a-z]*", "%s does not match %s", "hi" "[a-z]*");
The syntax of the pattern is the one used in the
Pattern
class.
input
- the character sequence to validate, not null
pattern
- the regular expression pattern, not null
message
- the
String.format(String, Object...)
exception message if invalid, not null
values
- the optional values for the formatted exception message, null array not recommended
IllegalArgumentException
- if the character sequence does not match the pattern
matchesPattern(CharSequence, String)
public static void notNaN(double value)
Validate.notNaN(myDouble);
The message of the exception is "The validated value is not a number".
value
- the value to validate
IllegalArgumentException
- if the value is not a number
notNaN(double, String, Object...)
Validate.notNaN(myDouble, "The value must be a number");
value
- the value to validate
message
- the
String.format(String, Object...)
exception message if invalid, not null
values
- the optional values for the formatted exception message
IllegalArgumentException
- if the value is not a number
notNaN(double)
public static void finite(double value)
Validate.finite(myDouble);
The message of the exception is "The value is invalid: %f".
value
- the value to validate
IllegalArgumentException
- if the value is infinite or Not-a-Number (NaN)
finite(double, String, Object...)
Validate.finite(myDouble, "The argument must contain a numeric value");
value
- the value to validate
message
- the
String.format(String, Object...)
exception message if invalid, not null
values
- the optional values for the formatted exception message
IllegalArgumentException
- if the value is infinite or Not-a-Number (NaN)
finite(double)
Validate.inclusiveBetween(0, 2, 1);
T
- the type of the argument object
start
- the inclusive start value, not null
end
- the inclusive end value, not null
value
- the object to validate, not null
IllegalArgumentException
- if the value falls outside the boundaries
inclusiveBetween(Object, Object, Comparable, String, Object...)
Validate.inclusiveBetween(0, 2, 1, "Not in boundaries");
T
- the type of the argument object
start
- the inclusive start value, not null
end
- the inclusive end value, not null
value
- the object to validate, not null
message
- the
String.format(String, Object...)
exception message if invalid, not null
values
- the optional values for the formatted exception message, null array not recommended
IllegalArgumentException
- if the value falls outside the boundaries
inclusiveBetween(Object, Object, Comparable)
Validate.inclusiveBetween(0, 2, 1);
start
- the inclusive start value
end
- the inclusive end value
value
- the value to validate
IllegalArgumentException
- if the value falls outside the boundaries (inclusive)
Validate.inclusiveBetween(0, 2, 1, "Not in range");
start
- the inclusive start value
end
- the inclusive end value
value
- the value to validate
message
- the exception message if invalid, not null
IllegalArgumentException
- if the value falls outside the boundaries
Validate.inclusiveBetween(0.1, 2.1, 1.1);
start
- the inclusive start value
end
- the inclusive end value
value
- the value to validate
IllegalArgumentException
- if the value falls outside the boundaries (inclusive)
Validate.inclusiveBetween(0.1, 2.1, 1.1, "Not in range");
start
- the inclusive start value
end
- the inclusive end value
value
- the value to validate
message
- the exception message if invalid, not null
IllegalArgumentException
- if the value falls outside the boundaries
Validate.exclusiveBetween(0, 2, 1);
T
- the type of the argument object
start
- the exclusive start value, not null
end
- the exclusive end value, not null
value
- the object to validate, not null
IllegalArgumentException
- if the value falls outside the boundaries
exclusiveBetween(Object, Object, Comparable, String, Object...)
Validate.exclusiveBetween(0, 2, 1, "Not in boundaries");
T
- the type of the argument object
start
- the exclusive start value, not null
end
- the exclusive end value, not null
value
- the object to validate, not null
message
- the
String.format(String, Object...)
exception message if invalid, not null
values
- the optional values for the formatted exception message, null array not recommended
IllegalArgumentException
- if the value falls outside the boundaries
exclusiveBetween(Object, Object, Comparable)
Validate.exclusiveBetween(0, 2, 1);
start
- the exclusive start value
end
- the exclusive end value
value
- the value to validate
IllegalArgumentException
- if the value falls out of the boundaries
Validate.exclusiveBetween(0, 2, 1, "Not in range");
start
- the exclusive start value
end
- the exclusive end value
value
- the value to validate
message
- the exception message if invalid, not null
IllegalArgumentException
- if the value falls outside the boundaries
Validate.exclusiveBetween(0.1, 2.1, 1.1);
start
- the exclusive start value
end
- the exclusive end value
value
- the value to validate
IllegalArgumentException
- if the value falls out of the boundaries
Validate.exclusiveBetween(0.1, 2.1, 1.1, "Not in range");
start
- the exclusive start value
end
- the exclusive end value
value
- the value to validate
message
- the exception message if invalid, not null
IllegalArgumentException
- if the value falls outside the boundaries
public static void isInstanceOf(Class<?> type, Object obj)
This method is useful when validating according to an arbitrary class
Validate.isInstanceOf(OkClass.class, object);
The message of the exception is "Expected type: {type}, actual: {obj_type}"
type
- the class the object must be validated against, not null
obj
- the object to check, null throws an exception
IllegalArgumentException
- if argument is not of specified class
isInstanceOf(Class, Object, String, Object...)
Validate.isInstanceOf(OkClass.class, object, "Wrong class, object is of class %s", object.getClass().getName());
type
- the class the object must be validated against, not null
obj
- the object to check, null throws an exception
message
- the
String.format(String, Object...)
exception message if invalid, not null
values
- the optional values for the formatted exception message, null array not recommended
IllegalArgumentException
- if argument is not of specified class
isInstanceOf(Class, Object)
public static void isAssignableFrom(Class<?> superType, Class<?> type)
This method is useful when validating that there will be no casting errors.
Validate.isAssignableFrom(SuperClass.class, object.getClass());
The message format of the exception is "Cannot assign {type} to {superType}"
superType
- the class must be validated against, not null
type
- the class to check, not null
IllegalArgumentException
- if type argument is not assignable to the specified superType
isAssignableFrom(Class, Class, String, Object...)
This method is useful when validating if there will be no casting errors.
Validate.isAssignableFrom(SuperClass.class, object.getClass());
The message of the exception is "The validated object can not be converted to the" followed by the name of the class and "class"
superType
- the class must be validated against, not null
type
- the class to check, not null
message
- the
String.format(String, Object...)
exception message if invalid, not null
values
- the optional values for the formatted exception message, null array not recommended
IllegalArgumentException
- if argument can not be converted to the specified class
isAssignableFrom(Class, Class)
至今单身的牛排 · Oops!!! - 简书 1 年前 |
玩篮球的四季豆 · AddJavaScriptTag works in traditional, how to get it working in reactive | OutSystems 1 年前 |
憨厚的墨镜 · SQL COUNT函数-之路教程 1 年前 |