public final class ArgChecks
extends java.lang.Object
IllegalArgumentExceptions, NullArgumentException,
IndexOutOfBoundsExceptions etc..| Modifier and Type | Method and Description |
|---|---|
static void |
arrayLength(java.lang.Object array,
int minLength,
int maxLength,
java.lang.String parameterName)
Ensures that the given array has the specified minimum and maximum length.
|
static void |
arrayLength(java.lang.Object array,
int length,
java.lang.String parameterName)
Ensures that the given array has exactly the specified length.
|
static boolean |
check(boolean expression,
java.lang.String parameterName,
java.lang.String msg)
Rejects any expression that evaluates to
true. |
static void |
index(long index,
long length,
java.lang.String parameterName)
Ensures that the given index lies within the bounds of any list-like
structure with the specified length or size.
|
static <E> E[] |
length(E[] array,
int minLength,
int maxLength,
java.lang.String parameterName)
Ensures that the given array has the specified minimum and maximum length.
|
static <E> E[] |
length(E[] array,
int length,
java.lang.String parameterName)
Ensures that the given array has exactly the specified length.
|
static java.lang.String |
length(java.lang.String string,
int minLength,
int maxLength,
java.lang.String parameterName)
Ensures that the given string has the specified minimum and maximum length.
|
static java.lang.String |
length(java.lang.String string,
int length,
java.lang.String parameterName)
Ensures that the given string has exactly the specified length.
|
static <N extends java.lang.Number> |
max(N number,
double max,
java.lang.String parameterName)
Ensures that the given number is less than or equal to the specified value.
|
static <E> E[] |
maxLength(E[] array,
int maxLength,
java.lang.String parameterName)
Ensures that the given array has the specified maximum length.
|
static java.lang.String |
maxLength(java.lang.String string,
int maxLength,
java.lang.String parameterName)
Ensures that the given string has the specified maximum length.
|
static <E> java.util.Collection<E> |
maxSize(java.util.Collection<E> collection,
int maxSize,
java.lang.String parameterName)
Ensures that the given collection has the specified maximum size.
|
static <K,V> java.util.Map<K,V> |
maxSize(java.util.Map<K,V> map,
int maxSize,
java.lang.String parameterName)
Ensures that the given map has the specified maximum size.
|
static <N extends java.lang.Number> |
min(N number,
double min,
java.lang.String parameterName)
Ensures that the given number is greater than or equal to the specified
value.
|
static <E> E[] |
minLength(E[] array,
int minLength,
java.lang.String parameterName)
Ensures that the given array has the specified minimum length.
|
static java.lang.String |
minLength(java.lang.String string,
int minLength,
java.lang.String parameterName)
Ensures that the given string has the specified minimum length.
|
static <E> java.util.Collection<E> |
minSize(java.util.Collection<E> collection,
int minSize,
java.lang.String parameterName)
Ensures that the given collection has the specified minimum size.
|
static <K,V> java.util.Map<K,V> |
minSize(java.util.Map<K,V> map,
int minSize,
java.lang.String parameterName)
Ensures that the given map has the specified minimum size.
|
static java.lang.String[] |
noEmptys(java.lang.String[] array,
java.lang.String parameterName)
Ensures that the given array contains no empty strings.
|
static <K,V> java.util.Map<K,V> |
noNullKey(java.util.Map<K,V> map,
java.lang.String parameterName)
Ensures that the given map contains no null key.
|
static <E> java.util.Collection<E> |
noNulls(java.util.Collection<E> collection,
java.lang.String parameterName)
Ensures that the given collection contains no null values.
|
static <E> E[] |
noNulls(E[] array,
java.lang.String parameterName)
Ensures that the given array contains no null values.
|
static <K,V> java.util.Map<K,V> |
noNulls(java.util.Map<K,V> map,
java.lang.String parameterName)
Ensures that the given map contains neither a null key nor null values.
|
static <K,V> java.util.Map<K,V> |
noNullValues(java.util.Map<K,V> map,
java.lang.String parameterName)
Ensures that the given map contains no null values.
|
static java.lang.String |
notBlank(java.lang.String string,
java.lang.String parameterName)
Ensures that the given string is not blank.
|
static byte[] |
notEmpty(byte[] array,
java.lang.String parameterName)
Ensures that the given byte array is not empty.
|
static <E> java.util.Collection<E> |
notEmpty(java.util.Collection<E> collection,
java.lang.String parameterName)
Ensures that the given collection is not empty.
|
static <E> E[] |
notEmpty(E[] array,
java.lang.String parameterName)
Ensures that the given array is not empty.
|
static <K,V> java.util.Map<K,V> |
notEmpty(java.util.Map<K,V> map,
java.lang.String parameterName)
Ensures that the given map is not empty.
|
static java.lang.String |
notEmpty(java.lang.String string,
java.lang.String parameterName)
Ensures that the given string is not empty.
|
static <N extends java.lang.Number> |
notNegative(N number,
java.lang.String parameterName)
Ensures that the given number is not negative (i.e.
|
static <T> T |
notNull(T object,
java.lang.String parameterName)
Asserts that the parameter is not null.
|
static <N extends java.lang.Number> |
notZero(N number,
java.lang.String parameterName)
Ensures that the given number is not zero.
|
static java.lang.String |
noWhitespace(java.lang.String string,
java.lang.String parameterName)
Ensures that the given string contains no whitespace.
|
static java.lang.String |
nullOrNotEmpty(java.lang.String string,
java.lang.String parameterName)
Ensures that the given string is either
null or not empty. |
static <T> T |
oneOf(T object,
java.lang.String parameterName,
java.lang.Object... allowedValues)
Asserts that the parameter has one of the given values (by testing for
equality).
|
static <N extends java.lang.Number> |
positive(N number,
java.lang.String parameterName)
Ensures that the given number is positive (i.e.
|
static <E> java.util.Collection<E> |
size(java.util.Collection<E> collection,
int minSize,
int maxSize,
java.lang.String parameterName)
Ensures that the given collection has the specified minimum and maximum
size.
|
static <E> java.util.Collection<E> |
size(java.util.Collection<E> collection,
int size,
java.lang.String parameterName)
Ensures that the given collection has exactly the specified size.
|
static <K,V> java.util.Map<K,V> |
size(java.util.Map<K,V> map,
int minSize,
int maxSize,
java.lang.String parameterName)
Ensures that the given map has the specified minimum and maximum size.
|
static <K,V> java.util.Map<K,V> |
size(java.util.Map<K,V> map,
int size,
java.lang.String parameterName)
Ensures that the given map has exactly the specified size.
|
public static boolean check(boolean expression,
java.lang.String parameterName,
java.lang.String msg)
true. This method is
rather generic and can be used if no other method of this class fits the
need.expression - true will be rejectedparameterName - name of the parameter being checkedmsg - the exception message in case the expression does not evaluate
to falsepublic static <T> T notNull(T object,
java.lang.String parameterName)
object - The object to be tested.parameterName - The name of the parameter.NullArgumentException - if the given object is null.public static <T> T oneOf(T object,
java.lang.String parameterName,
java.lang.Object... allowedValues)
object - The object to be testedparameterName - The name of the parameterallowedValues - The allowed values; may include nullNullArgumentException - if the given object is not one of the allowed
valuespublic static <N extends java.lang.Number> N notNegative(N number,
java.lang.String parameterName)
number - The number to be tested.parameterName - The name of the parameter.public static <N extends java.lang.Number> N positive(N number,
java.lang.String parameterName)
number - The number to be tested.parameterName - The name of the parameter.public static <N extends java.lang.Number> N notZero(N number,
java.lang.String parameterName)
number - The number to be tested.parameterName - The name of the parameter.public static <N extends java.lang.Number> N min(N number,
double min,
java.lang.String parameterName)
number - The number to be tested.min - The smallest acceptable value.parameterName - The name of the parameter.public static <N extends java.lang.Number> N max(N number,
double max,
java.lang.String parameterName)
number - The number to be tested.max - The largest acceptable value.parameterName - The name of the parameter.public static void index(long index,
long length,
java.lang.String parameterName)
index - The index to be tested.length - The length or size of the list.parameterName - The name of the parameter.public static java.lang.String notEmpty(java.lang.String string,
java.lang.String parameterName)
string - The string to be tested.parameterName - The name of the parameter.public static java.lang.String notBlank(java.lang.String string,
java.lang.String parameterName)
String.trim().string - The string to be tested.parameterName - The name of the parameter.public static java.lang.String nullOrNotEmpty(java.lang.String string,
java.lang.String parameterName)
null or not empty.string - The string to be tested.parameterName - The name of the parameter.public static java.lang.String noWhitespace(java.lang.String string,
java.lang.String parameterName)
Character.isWhitespace(char).string - The string to be tested.parameterName - The name of the parameter.public static java.lang.String minLength(java.lang.String string,
int minLength,
java.lang.String parameterName)
string - The string to be tested.minLength - The expected minimum length.parameterName - The name of the parameter.public static java.lang.String maxLength(java.lang.String string,
int maxLength,
java.lang.String parameterName)
string - The string to be tested.maxLength - The expected maximum length.parameterName - The name of the parameter.public static java.lang.String length(java.lang.String string,
int minLength,
int maxLength,
java.lang.String parameterName)
string - The string to be tested.minLength - The expected minimum length.maxLength - The expected maximum length.parameterName - The name of the parameter.public static java.lang.String length(java.lang.String string,
int length,
java.lang.String parameterName)
string - The string to be tested.length - The expected length.parameterName - The name of the parameter.public static <E> E[] noNulls(E[] array,
java.lang.String parameterName)
array - The array to be tested.parameterName - The name of the parameter.public static byte[] notEmpty(byte[] array,
java.lang.String parameterName)
array - The byte array to be tested.parameterName - The name of the parameter.public static <E> E[] notEmpty(E[] array,
java.lang.String parameterName)
array - The array to be tested.parameterName - The name of the parameter.public static java.lang.String[] noEmptys(java.lang.String[] array,
java.lang.String parameterName)
array - The strings to be tested.parameterName - The name of the parameter.public static <E> E[] minLength(E[] array,
int minLength,
java.lang.String parameterName)
array - The array to be tested.minLength - The expected minimum length.parameterName - The name of the parameter.public static <E> E[] maxLength(E[] array,
int maxLength,
java.lang.String parameterName)
array - The array to be tested.maxLength - The expected maximum length.parameterName - The name of the parameter.public static <E> E[] length(E[] array,
int minLength,
int maxLength,
java.lang.String parameterName)
array - The array to be tested.minLength - The expected minimum length.maxLength - The expected maximum length.parameterName - The name of the parameter.public static <E> E[] length(E[] array,
int length,
java.lang.String parameterName)
array - The array to be tested.length - The expected length.parameterName - The name of the parameter.public static void arrayLength(java.lang.Object array,
int minLength,
int maxLength,
java.lang.String parameterName)
array - The array to be tested.minLength - The expected minimum length.maxLength - The expected maximum length.parameterName - The name of the parameter.public static void arrayLength(java.lang.Object array,
int length,
java.lang.String parameterName)
array - The array to be tested.length - The expected length.parameterName - The name of the parameter.public static <E> java.util.Collection<E> noNulls(java.util.Collection<E> collection,
java.lang.String parameterName)
collection - The collection to be tested.parameterName - The name of the parameter.public static <E> java.util.Collection<E> notEmpty(java.util.Collection<E> collection,
java.lang.String parameterName)
collection - The collection to be tested.parameterName - The name of the parameter.public static <E> java.util.Collection<E> minSize(java.util.Collection<E> collection,
int minSize,
java.lang.String parameterName)
collection - The collection to be tested.minSize - The expected minimum size.parameterName - The name of the parameter.public static <E> java.util.Collection<E> maxSize(java.util.Collection<E> collection,
int maxSize,
java.lang.String parameterName)
collection - The collection to be tested.maxSize - The expected maximum size.parameterName - The name of the parameter.public static <E> java.util.Collection<E> size(java.util.Collection<E> collection,
int minSize,
int maxSize,
java.lang.String parameterName)
collection - The collection to be tested.minSize - The expected minimum size.maxSize - The expected maximum size.parameterName - The name of the parameter.public static <E> java.util.Collection<E> size(java.util.Collection<E> collection,
int size,
java.lang.String parameterName)
collection - The collection to be tested.size - The expected size.parameterName - The name of the parameter.public static <K,V> java.util.Map<K,V> noNulls(java.util.Map<K,V> map,
java.lang.String parameterName)
notNull(Object, String), noNullKey(Map, String)
and noNullValues(Map, String).map - The map to be tested.parameterName - The name of the parameter.public static <K,V> java.util.Map<K,V> notEmpty(java.util.Map<K,V> map,
java.lang.String parameterName)
map - The map to be tested.parameterName - The name of the parameter.public static <K,V> java.util.Map<K,V> noNullKey(java.util.Map<K,V> map,
java.lang.String parameterName)
map - The map to be tested.parameterName - The name of the parameter.public static <K,V> java.util.Map<K,V> noNullValues(java.util.Map<K,V> map,
java.lang.String parameterName)
map - The map to be tested.parameterName - The name of the parameter.public static <K,V> java.util.Map<K,V> minSize(java.util.Map<K,V> map,
int minSize,
java.lang.String parameterName)
map - The map to be tested.minSize - The expected minimum size.parameterName - The name of the parameter.public static <K,V> java.util.Map<K,V> maxSize(java.util.Map<K,V> map,
int maxSize,
java.lang.String parameterName)
map - The map to be tested.maxSize - The expected maximum size.parameterName - The name of the parameter.public static <K,V> java.util.Map<K,V> size(java.util.Map<K,V> map,
int minSize,
int maxSize,
java.lang.String parameterName)
map - The map to be tested.minSize - The expected minimum size.maxSize - The expected maximum size.parameterName - The name of the parameter.public static <K,V> java.util.Map<K,V> size(java.util.Map<K,V> map,
int size,
java.lang.String parameterName)
map - The map to be tested.size - The expected size.parameterName - The name of the parameter.