public final class PreConditions
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static <T extends java.lang.Number> |
isPositive(T nb,
java.lang.String message,
java.lang.Object... params)
Check if given number is strictly positive (strictly greater than zero).
|
static java.io.File |
isReadable(java.io.File file,
java.lang.String message,
java.lang.Object... params)
Check that a given file exist and is readable.
|
static java.io.File |
isWritable(java.io.File file,
java.lang.String message,
java.lang.Object... params)
Check that a given file exist and is writable.
|
static java.lang.String |
notBlank(java.lang.String val,
java.lang.String message,
java.lang.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> java.lang.Iterable<T> |
notEmpty(java.lang.Iterable<T> val,
java.lang.String message,
java.lang.Object... params)
Ensures that iterable element is:
Not
null .
Not empty.
|
static <T,U> java.util.Map<T,U> |
notEmpty(java.util.Map<T,U> val,
java.lang.String message,
java.lang.Object... params)
Ensures that map is:
Not
null .
Not empty.
|
static <T> T[] |
notEmpty(T[] val,
java.lang.String message,
java.lang.Object... params)
Ensures that array is:
Not
null .
Not empty.
|
static <T> T |
notNull(T val,
java.lang.String message,
java.lang.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, java.lang.String message, java.lang.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
.java.lang.NullPointerException
- If val
is null.public static java.lang.String notBlank(java.lang.String val, java.lang.String message, java.lang.Object... params)
null
.val
- Value to check.message
- Message passed to thrown exception.params
- Message parameters (formatted with String.format(String, Object...)
).null
.java.lang.NullPointerException
- If val
is null
.java.lang.IllegalArgumentException
- If val
is empty or blank.public static <T> T[] notEmpty(T[] val, java.lang.String message, java.lang.Object... params)
null
.T
- Type of elements in array.val
- Value to check.message
- Message passed to thrown exception.params
- Message parameters (formatted with String.format(String, Object...)
).java.lang.NullPointerException
- If val
is null
.java.lang.IllegalArgumentException
- If val
is empty.public static <T,U> java.util.Map<T,U> notEmpty(java.util.Map<T,U> val, java.lang.String message, java.lang.Object... params)
null
.T
- Type of keys in map.U
- Type of values in map.val
- Value to check.message
- Message passed to thrown exception.params
- Message parameters (formatted with String.format(String, Object...)
).java.lang.NullPointerException
- If val
is null
.java.lang.IllegalArgumentException
- If val
is empty.public static <T> java.lang.Iterable<T> notEmpty(java.lang.Iterable<T> val, java.lang.String message, java.lang.Object... params)
null
.T
- Type of elements in iterable structure.val
- Value to check.message
- Message passed to thrown exception.params
- Message parameters (formatted with String.format(String, Object...)
).java.lang.NullPointerException
- If val
is null
.java.lang.IllegalArgumentException
- If val
is empty.public static <T extends java.lang.Number> T isPositive(T nb, java.lang.String message, java.lang.Object... params)
T
- Type of number.nb
- Number.message
- Error message.params
- Message parameters (formatted with String.format(String, Object...)
).java.lang.NullPointerException
- If nb
is null
.java.lang.IllegalArgumentException
- If nb
is less than or equal to zero.public static java.io.File isReadable(java.io.File file, java.lang.String message, java.lang.Object... params)
file
- File to check.message
- Error message.params
- Message parameters (formatted with String.format(String, Object...)
).java.lang.NullPointerException
- If file
is null
.UnreadableFileException
- If file
does not exist.UnreadableFileException
- If file
cannot be read.public static java.io.File isWritable(java.io.File file, java.lang.String message, java.lang.Object... params)
file
- File to check.message
- Error message.params
- Message parameters (formatted with String.format(String, Object...)
).java.lang.NullPointerException
- If file
is null
.UnreadableFileException
- If file
does not exist.UnreadableFileException
- If file
cannot be updated.Copyright © 2018. All Rights Reserved.