Class ValidationUtils
-
- All Implemented Interfaces:
public class ValidationUtils
Utility class for validating method arguments.
-
-
Method Summary
Modifier and Type Method Description static void
ensureEq(Object lhs, Object rhs, String format, Array<Object> args)
Ensure that the two values are equal. static <T> T
ensureNotNull(T object, String name)
Ensures that the given object is not null. static <T> T
ensureNotNull(T object, String format, Array<Object> args)
Ensures that the given object is not null. static <T extends Collection<out Object>> T
ensureNotEmpty(T collection, String name)
Ensures that the given collection is not null and not empty. static <T> Array<T>
ensureNotEmpty(Array<T> array, String name)
Ensures that the given array is not null and not empty. static <K, V> Map<K, V>
ensureNotEmpty(Map<K, V> map, String name)
Ensures that the given map is not null and not empty. static String
ensureNotBlank(String string, String name)
Ensures that the given string is not null and not blank. static void
ensureTrue(boolean expression, String msg)
Ensures that the given expression is true. static int
ensureGreaterThanZero(Integer i, String name)
Ensures that the given expression is true. static double
ensureGreaterThanZero(Double i, String name)
Ensures that the given expression is true. static double
ensureBetween(Double d, double min, double max, String name)
Ensures that the given Double value is in [min, max]
.static int
ensureBetween(Integer i, int min, int max, String name)
Ensures that the given Integer value is in [min, max]
.static long
ensureBetween(Long i, long min, long max, String name)
Ensures that the given Long value is in [min, max]
.-
-
Method Detail
-
ensureEq
static void ensureEq(Object lhs, Object rhs, String format, Array<Object> args)
Ensure that the two values are equal.
- Parameters:
lhs
- the left hand side value.rhs
- the right hand side value.format
- the format string for the exception message.args
- the format arguments for the exception message.
-
ensureNotNull
static <T> T ensureNotNull(T object, String name)
Ensures that the given object is not null.
- Parameters:
object
- The object to check.name
- The name of the object to be used in the exception message.- Returns:
The object if it is not null.
-
ensureNotNull
static <T> T ensureNotNull(T object, String format, Array<Object> args)
Ensures that the given object is not null.
- Parameters:
object
- The object to check.format
- The format of the exception message.args
- The arguments for the exception message.- Returns:
The object if it is not null.
-
ensureNotEmpty
static <T extends Collection<out Object>> T ensureNotEmpty(T collection, String name)
Ensures that the given collection is not null and not empty.
- Parameters:
collection
- The collection to check.name
- The name of the collection to be used in the exception message.- Returns:
The collection if it is not null and not empty.
-
ensureNotEmpty
static <T> Array<T> ensureNotEmpty(Array<T> array, String name)
Ensures that the given array is not null and not empty.
- Parameters:
array
- The array to check.name
- The name of the array to be used in the exception message.- Returns:
The array if it is not null and not empty.
-
ensureNotEmpty
static <K, V> Map<K, V> ensureNotEmpty(Map<K, V> map, String name)
Ensures that the given map is not null and not empty.
- Parameters:
map
- The map to check.name
- The name of the map to be used in the exception message.- Returns:
The map if it is not null and not empty.
-
ensureNotBlank
static String ensureNotBlank(String string, String name)
Ensures that the given string is not null and not blank.
- Parameters:
string
- The string to check.name
- The name of the string to be used in the exception message.- Returns:
The string if it is not null and not blank.
-
ensureTrue
static void ensureTrue(boolean expression, String msg)
Ensures that the given expression is true.
- Parameters:
expression
- The expression to check.msg
- The message to be used in the exception.
-
ensureGreaterThanZero
static int ensureGreaterThanZero(Integer i, String name)
Ensures that the given expression is true.
- Parameters:
i
- The expression to check.name
- The message to be used in the exception.- Returns:
The value if it is greater than zero.
-
ensureGreaterThanZero
static double ensureGreaterThanZero(Double i, String name)
Ensures that the given expression is true.
- Parameters:
i
- The expression to check.name
- The message to be used in the exception.- Returns:
The value if it is greater than zero.
-
ensureBetween
static double ensureBetween(Double d, double min, double max, String name)
Ensures that the given Double value is in
[min, max]
.- Parameters:
d
- The value to check.min
- The minimum value.max
- The maximum value.name
- The value name to be used in the exception.- Returns:
The value if it is in
[min, max]
.
-
ensureBetween
static int ensureBetween(Integer i, int min, int max, String name)
Ensures that the given Integer value is in
[min, max]
.- Parameters:
i
- The value to check.min
- The minimum value.max
- The maximum value.name
- The value name to be used in the exception.- Returns:
The value if it is in
[min, max]
.
-
ensureBetween
static long ensureBetween(Long i, long min, long max, String name)
Ensures that the given Long value is in
[min, max]
.- Parameters:
i
- The value to check.min
- The minimum value.max
- The maximum value.name
- The value name to be used in the exception.- Returns:
The value if it is in
[min, max]
.
-
-
-
-