Class PreConditions
- java.lang.Object
-
- com.thebuzzmedia.exiftool.commons.lang.PreConditions
-
public final class PreConditions extends Object
Static PreConditions Utilities.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends Number>
TisPositive(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: Notnull
. 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: Notnull
. Not empty.static <T,U>
Map<T,U>notEmpty(Map<T,U> val, String message, Object... params)
Ensures that map is: Notnull
. Not empty.static <T> T[]
notEmpty(T[] val, String message, Object... params)
Ensures that array is: Notnull
. 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 notnull
.
-
-
-
Method Detail
-
notNull
public static <T> T notNull(T val, String message, Object... params)
Ensures that an object reference passed as a parameter to the calling method is notnull
.- Type Parameters:
T
- Type of parameter.- Parameters:
val
- Value to check.message
- Message passed toNullPointerException
.params
- Message parameters (formatted withString.format(String, Object...)
).- Returns:
- Original value if it is not
null
. - Throws:
NullPointerException
- Ifval
is null.
-
notBlank
public 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).
- Parameters:
val
- Value to check.message
- Message passed to thrown exception.params
- Message parameters (formatted withString.format(String, Object...)
).- Returns:
- Original value if it is not
null
. - Throws:
NullPointerException
- Ifval
isnull
.IllegalArgumentException
- Ifval
is empty or blank.
- Not
-
notEmpty
public static <T> T[] notEmpty(T[] val, String message, Object... params)
Ensures that array is:- Not
null
. - Not empty.
- Type Parameters:
T
- Type of elements in array.- Parameters:
val
- Value to check.message
- Message passed to thrown exception.params
- Message parameters (formatted withString.format(String, Object...)
).- Returns:
- Original value if it is not empty.
- Throws:
NullPointerException
- Ifval
isnull
.IllegalArgumentException
- Ifval
is empty.
- Not
-
notEmpty
public static <T,U> Map<T,U> notEmpty(Map<T,U> val, String message, Object... params)
Ensures that map is:- Not
null
. - Not empty.
- Type Parameters:
T
- Type of keys in map.U
- Type of values in map.- Parameters:
val
- Value to check.message
- Message passed to thrown exception.params
- Message parameters (formatted withString.format(String, Object...)
).- Returns:
- Original value if it is not empty.
- Throws:
NullPointerException
- Ifval
isnull
.IllegalArgumentException
- Ifval
is empty.
- Not
-
notEmpty
public static <T> Iterable<T> notEmpty(Iterable<T> val, String message, Object... params)
Ensures that iterable element is:- Not
null
. - Not empty.
- Type Parameters:
T
- Type of elements in iterable structure.- Parameters:
val
- Value to check.message
- Message passed to thrown exception.params
- Message parameters (formatted withString.format(String, Object...)
).- Returns:
- Original value if it is not empty.
- Throws:
NullPointerException
- Ifval
isnull
.IllegalArgumentException
- Ifval
is empty.
- Not
-
isPositive
public static <T extends Number> T isPositive(T nb, String message, Object... params)
Check if given number is strictly positive (strictly greater than zero).- Type Parameters:
T
- Type of number.- Parameters:
nb
- Number.message
- Error message.params
- Message parameters (formatted withString.format(String, Object...)
).- Returns:
- Original number.
- Throws:
NullPointerException
- Ifnb
isnull
.IllegalArgumentException
- Ifnb
is less than or equal to zero.
-
isReadable
public static File isReadable(File file, String message, Object... params)
Check that a given file exist and is readable.- Parameters:
file
- File to check.message
- Error message.params
- Message parameters (formatted withString.format(String, Object...)
).- Returns:
- Original file.
- Throws:
NullPointerException
- Iffile
isnull
.UnreadableFileException
- Iffile
does not exist.UnreadableFileException
- Iffile
cannot be read.
-
isWritable
public static File isWritable(File file, String message, Object... params)
Check that a given file exist and is writable.- Parameters:
file
- File to check.message
- Error message.params
- Message parameters (formatted withString.format(String, Object...)
).- Returns:
- Original file.
- Throws:
NullPointerException
- Iffile
isnull
.UnreadableFileException
- Iffile
does not exist.UnreadableFileException
- Iffile
cannot be updated.
-
-