public enum Validate extends Enum<Validate>
Argument validation.
Modifier and Type | Method and Description |
---|---|
static long |
inclusiveBetween(long minimum,
long maximum,
long value,
String reason,
Object... values)
Throw
IllegalArgumentException if value is strictly less than minimum or strictly
greater than maximum. |
static <T> T |
isInstanceOf(Class<?> clazz,
T o,
String reason,
Object... values)
Throw
IllegalArgumentException if the object is not an instance of the class. |
static void |
isTrue(boolean condition,
String reason,
Object... values)
Throw
IllegalArgumentException if the condition is false. |
static <T> T[] |
noNullElements(T[] array,
String reason,
Object... values)
Throw
IllegalArgumentException if one of the array elements is null. |
static String |
notBlank(String s,
String reason,
Object... values)
Throw @
NullPointerException if the string is null, or IllegalArgumentException if the string is just whitespace. |
static <T> T[] |
notEmpty(T[] array,
String reason,
Object... values)
Throw
IllegalArgumentException if the array is empty |
static <T> T |
notNull(T o,
String reason,
Object... values)
Throw
NullPointerException if the object is null. |
static Validate |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static Validate[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static Validate[] values()
for (Validate c : Validate.values()) System.out.println(c);
public static Validate valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic static <T> T notNull(T o, String reason, Object... values)
Throw NullPointerException
if the object is null.
o
- object that has to be non-nullreason
- exception messagevalues
- values to be put in placeholders in reason (e.g. “%s”).NullPointerException
- if the object is nullpublic static <T> T isInstanceOf(Class<?> clazz, T o, String reason, Object... values)
Throw IllegalArgumentException
if the object is not an instance of the class.
clazz
- the class the object has to beo
- the objectreason
- the exception messagevalues
- values to be put in placeholders in reason (e.g. “%s”).IllegalArgumentException
- if the object is not an instance of the classpublic static String notBlank(String s, String reason, Object... values)
Throw @NullPointerException
if the string is null, or IllegalArgumentException
if the string is just whitespace.
s
- stringreason
- exception messagevalues
- values to be put in placeholders in reason (e.g. “%s”).NullPointerException
- if the object is nullIllegalArgumentException
- if the object is just whitespace.public static void isTrue(boolean condition, String reason, Object... values)
Throw IllegalArgumentException
if the condition is false.
condition
- the conditionreason
- exception messagevalues
- values to be put in placeholders in reason (e.g. “%s”).NullPointerException
- if the condition is falsepublic static long inclusiveBetween(long minimum, long maximum, long value, String reason, Object... values)
Throw IllegalArgumentException
if value is strictly less than minimum or strictly
greater than maximum.
minimum
- the minimum, inclusivemaximum
- the maximum, inclusivevalue
- the value to checkreason
- the exception messagevalues
- values to be put in placeholders in reason (e.g. “%s”).IllegalArgumentException
- if the value is out of boundspublic static <T> T[] noNullElements(T[] array, String reason, Object... values)
Throw IllegalArgumentException
if one of the array elements is null.
T
- array element typearray
- array to checkreason
- exception messagevalues
- values to be put in placeholders in reason (e.g. “%s”).IllegalArgumentException
- if one of the array elements is nullpublic static <T> T[] notEmpty(T[] array, String reason, Object... values)
Throw IllegalArgumentException
if the array is empty
T
- array element typearray
- array to checkreason
- exception messagevalues
- values to be put in placeholders in reason (e.g. “%s”).IllegalArgumentException
- if the array is emptyCopyright © 2016–2024. All rights reserved.