Class PreConditions
java.lang.Object
com.thebuzzmedia.exiftool.commons.lang.PreConditions
Static PreConditions Utilities.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <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
Ensures that a string is: Notnull
. Not empty. Not blank (i.e contains at least one character other than space).static <T> Iterable<T>
Ensures that iterable element is: Notnull
. Not empty.static <T,
U> Map<T, U> Ensures that map is: Notnull
. Not empty.static <T> T[]
Ensures that array is: Notnull
. Not empty.static <T> T
Ensures that an object reference passed as a parameter to the calling method is notnull
.
-
Method Details
-
notNull
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
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
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
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
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
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
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
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.
-