public class ValidationUtils extends Object
Modifier and Type | Method and Description |
---|---|
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] . |
static void |
ensureEq(Object lhs,
Object rhs,
String format,
Object... args)
Ensure that the two values are equal.
|
static int |
ensureGreaterThanZero(Integer i,
String name)
Ensures that the given expression is true.
|
static String |
ensureNotBlank(String string,
String name)
Ensures that the given string is not null and not blank.
|
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 <T extends Collection<?>> |
ensureNotEmpty(T collection,
String name)
Ensures that the given collection is not null and not empty.
|
static <T> T |
ensureNotNull(T object,
String name)
Ensures that the given object is not null.
|
static <T> T |
ensureNotNull(T object,
String format,
Object... args)
Ensures that the given object is not null.
|
static void |
ensureTrue(boolean expression,
String msg)
Ensures that the given expression is true.
|
public static void ensureEq(Object lhs, Object rhs, String format, Object... args)
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.public static <T> T ensureNotNull(T object, String name)
T
- The type of the object.object
- The object to check.name
- The name of the object to be used in the exception message.IllegalArgumentException
- if the object is null.public static <T> T ensureNotNull(T object, String format, Object... args)
T
- The type of the object.object
- The object to check.format
- The format of the exception message.args
- The arguments for the exception message.public static <T extends Collection<?>> T ensureNotEmpty(T collection, String name)
T
- The type of the collection.collection
- The collection to check.name
- The name of the collection to be used in the exception message.IllegalArgumentException
- if the collection is null or empty.public static <K,V> Map<K,V> ensureNotEmpty(Map<K,V> map, String name)
K
- The type of the key.V
- The type of the value.map
- The map to check.name
- The name of the map to be used in the exception message.IllegalArgumentException
- if the collection is null or empty.public static String ensureNotBlank(String string, String name)
string
- The string to check.name
- The name of the string to be used in the exception message.IllegalArgumentException
- if the string is null or blank.public static void ensureTrue(boolean expression, String msg)
expression
- The expression to check.msg
- The message to be used in the exception.IllegalArgumentException
- if the expression is false.public static int ensureGreaterThanZero(Integer i, String name)
i
- The expression to check.name
- The message to be used in the exception.IllegalArgumentException
- if the expression is false.public static double ensureBetween(Double d, double min, double max, String name)
[min, max]
.d
- The value to check.min
- The minimum value.max
- The maximum value.name
- The value name to be used in the exception.[min, max]
.IllegalArgumentException
- if the value is not in [min, max]
.public static int ensureBetween(Integer i, int min, int max, String name)
[min, max]
.i
- The value to check.min
- The minimum value.max
- The maximum value.name
- The value name to be used in the exception.[min, max]
.IllegalArgumentException
- if the value is not in [min, max]
.public static long ensureBetween(Long i, long min, long max, String name)
[min, max]
.i
- The value to check.min
- The minimum value.max
- The maximum value.name
- The value name to be used in the exception.[min, max]
.IllegalArgumentException
- if the value is not in [min, max]
.Copyright © 2024. All rights reserved.