public final class PreConditions extends Object
Modifier and Type | Method and Description |
---|---|
static <T extends Number> |
isPositive(T nb,
String message,
Object... params)
Check if given number is strictly positive (strictly greater than zero).
|
static File |
isReadable(File file,
String message,
Object... params)
Check that a given file exist and is readable.
|
static File |
isWritable(File file,
String message,
Object... params)
Check that a given file exist and is writable.
|
static String |
notBlank(String val,
String message,
Object... params)
Ensures that a string is:
Not
null .
Not empty.
Not blank (i.e contains at least one character other than space).
|
static <T> Iterable<T> |
notEmpty(Iterable<T> val,
String message,
Object... params)
Ensures that iterable element is:
Not
null .
Not empty.
|
static <T,U> Map<T,U> |
notEmpty(Map<T,U> val,
String message,
Object... params)
Ensures that map is:
Not
null .
Not empty.
|
static <T> T[] |
notEmpty(T[] val,
String message,
Object... params)
Ensures that array is:
Not
null .
Not empty.
|
static <T> T |
notNull(T val,
String message,
Object... params)
Ensures that an object reference passed as a parameter to the calling method is not
null . |
public static <T> T notNull(T val, String message, Object... params)
null
.T
- Type of parameter.val
- Value to check.message
- Message passed to NullPointerException
.params
- Message parameters (formatted with String.format(String, Object...)
).null
.NullPointerException
- If val
is null.public static String notBlank(String val, String message, Object... params)
null
.val
- Value to check.message
- Message passed to thrown exception.params
- Message parameters (formatted with String.format(String, Object...)
).null
.NullPointerException
- If val
is null
.IllegalArgumentException
- If val
is empty or blank.public static <T> T[] notEmpty(T[] val, String message, Object... params)
null
.val
- Value to check.message
- Message passed to thrown exception.params
- Message parameters (formatted with String.format(String, Object...)
).NullPointerException
- If val
is null
.IllegalArgumentException
- If val
is empty.public static <T,U> Map<T,U> notEmpty(Map<T,U> val, String message, Object... params)
null
.val
- Value to check.message
- Message passed to thrown exception.params
- Message parameters (formatted with String.format(String, Object...)
).NullPointerException
- If val
is null
.IllegalArgumentException
- If val
is empty.public static <T> Iterable<T> notEmpty(Iterable<T> val, String message, Object... params)
null
.val
- Value to check.message
- Message passed to thrown exception.params
- Message parameters (formatted with String.format(String, Object...)
).NullPointerException
- If val
is null
.IllegalArgumentException
- If val
is empty.public static <T extends Number> T isPositive(T nb, String message, Object... params)
T
- Type of number.nb
- Number.message
- Error message.params
- Message parameters (formatted with String.format(String, Object...)
).NullPointerException
- If nb
is null
.IllegalArgumentException
- If nb
is less than or equal to zero.public static File isReadable(File file, String message, Object... params)
file
- File to check.message
- Error message.params
- Message parameters (formatted with String.format(String, Object...)
).NullPointerException
- If file
is null
.UnreadableFileException
- If file
does not exist.UnreadableFileException
- If file
cannot be read.public static File isWritable(File file, String message, Object... params)
file
- File to check.message
- Error message.params
- Message parameters (formatted with String.format(String, Object...)
).NullPointerException
- If file
is null
.UnreadableFileException
- If file
does not exist.UnreadableFileException
- If file
cannot be updated.Copyright © 2016. All Rights Reserved.