Class Requires
java.lang.Object
io.github.torand.javacommons.contract.Requires
Provides factory methods to test the state of variables.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
precondition
(Requirement requirement, String msg, Object... args) Checks that the specified requirement is fulfilled.static void
require
(Requirement requirement, String msg, Object... args) Checks that the specified requirement is fulfilled.static String
requireNonBlank
(String string, String msg, Object... args) Checks that the specified string is not null and contains at least one character.static int[]
requireNonEmpty
(int[] array, String msg, Object... args) Checks that the specified 'int' array is not null and contains at least one element.static long[]
requireNonEmpty
(long[] array, String msg, Object... args) Checks that the specified 'long' array is not null and contains at least one element.static <T> Optional
<T> requireNonEmpty
(Optional<T> optional, String msg, Object... args) Checks that the specified optional object is not null and is not empty.static <T> T[]
requireNonEmpty
(T[] array, String msg, Object... args) Checks that the specified object array is not null and contains at least one element.static <T extends Collection<?>>
TrequireNonEmpty
(T collection, String msg, Object... args) Checks that the specified object collection is not null and contains at least one element.
-
Method Details
-
requireNonEmpty
Checks that the specified 'int' array is not null and contains at least one element. Throws a customized NullPointerException or IllegalArgumentException if it is.- Parameters:
array
- the array to check.msg
- the exception message.args
- the exception message parameters.- Returns:
- the array if not null or empty.
-
requireNonEmpty
Checks that the specified 'long' array is not null and contains at least one element. Throws a customized NullPointerException or IllegalArgumentException if it is.- Parameters:
array
- the array to check.msg
- the exception message.args
- the exception message parameters.- Returns:
- the array if not null or empty.
-
requireNonEmpty
Checks that the specified object array is not null and contains at least one element. Throws a customized NullPointerException or IllegalArgumentException if it is.- Type Parameters:
T
- the object type.- Parameters:
array
- the array to check.msg
- the exception message.args
- the exception message parameters.- Returns:
- the array if not null or empty.
-
requireNonEmpty
Checks that the specified object collection is not null and contains at least one element. Throws a customized NullPointerException or IllegalArgumentException if it is.- Type Parameters:
T
- the object type.- Parameters:
collection
- the collection to check.msg
- the exception message.args
- the exception message parameters.- Returns:
- the collection if not null or empty.
-
requireNonBlank
Checks that the specified string is not null and contains at least one character. Throws a customized NullPointerException or IllegalArgumentException if it is.- Parameters:
string
- the string to check.msg
- the exception message.args
- the exception message parameters.- Returns:
- the string if not null or blank.
-
requireNonEmpty
Checks that the specified optional object is not null and is not empty. Throws a customized NullPointerException or IllegalArgumentException if it is.- Type Parameters:
T
- the object type.- Parameters:
optional
- the optional to check.msg
- the exception message.args
- the exception message parameters.- Returns:
- the optional if not null or empty.
-
require
Checks that the specified requirement is fulfilled. Throws a customized IllegalArgumentException if it is.- Parameters:
requirement
- the requirement.msg
- the exception message.args
- the exception message parameters.
-
precondition
Checks that the specified requirement is fulfilled. Throws a customized IllegalStateException if it is.- Parameters:
requirement
- the requirement.msg
- the exception message.args
- the exception message parameters.
-