Package com.avoka.core.util
Class Contract
java.lang.Object
com.avoka.core.util.Contract
Provides design by contract programming validation functions.
- Since:
- 17.10.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Ensure the specified condition value is false, or throw an IllegalArgumentExcpetion if true.static void
Ensure the specified condition value is true, or throw an IllegalArgumentExcpetion if false.static void
Validate specified is not null, or blank throw a IllegalArgumentException if null or blank.static void
Validate that the specified argument array is neithernull
nor a length of zero (no elements); otherwise throwing an exception with the specified message.static void
notEmpty
(Collection collection, String message, Object... args) Validate that the specified argument collection is neithernull
nor a size of zero (no elements); otherwise throwing an exception with the specified message.static void
Validate that the specified argument map is neithernull
nor a size of zero (no elements); otherwise throwing an exception with the specified message.static void
Validate specified value is not null, throw a IllegalArgumentException if null.
-
Method Details
-
isTrue
Ensure the specified condition value is true, or throw an IllegalArgumentExcpetion if false.- Parameters:
value
- the conditional value to testmessage
- the IllegalArgumentException message if the conditional value is falseargs
- the optional message format arguments (optional)
-
isFalse
Ensure the specified condition value is false, or throw an IllegalArgumentExcpetion if true.- Parameters:
value
- the conditional value to testmessage
- the IllegalArgumentException message if the conditional value is trueargs
- the optional message format arguments (optional)
-
notNull
Validate specified value is not null, throw a IllegalArgumentException if null.- Parameters:
value
- the value to verify not nullmessage
- the IllegalArgumentException message if the conditional value is not null
-
notBlank
Validate specified is not null, or blank throw a IllegalArgumentException if null or blank.- Parameters:
value
- the value to verify not null, or blankmessage
- the IllegalArgumentException message if the conditional value is null or blank
-
notEmpty
Validate that the specified argument map is neither
null
nor a size of zero (no elements); otherwise throwing an exception with the specified message.Contract.notEmpty(myMap, "The map must not be empty");
- Parameters:
map
- the map to check, validated not null by this methodmessage
- theString.format(String, Object...)
exception message if invalid, not nullargs
- the optional values for the formatted exception message, null array not recommended- Throws:
IllegalArgumentException
- if the map is empty- Since:
- 18.11.0
-
notEmpty
Validate that the specified argument collection is neither
null
nor a size of zero (no elements); otherwise throwing an exception with the specified message.Contract.notEmpty(myCollection, "The collection must not be empty");
- Parameters:
collection
- the collection to check, validated not null by this methodmessage
- theString.format(String, Object...)
exception message if invalid, not nullargs
- the optional values for the formatted exception message, null array not recommended- Throws:
NullPointerException
- if the collection isnull
IllegalArgumentException
- if the collection is empty- Since:
- 18.11.0
-
notEmpty
Validate that the specified argument array is neither
null
nor a length of zero (no elements); otherwise throwing an exception with the specified message.Validate.notEmpty(myArray, "The array must not be empty");
- Parameters:
array
- the array to check, validated not null by this methodmessage
- theString.format(String, Object...)
exception message if invalid, not null- Throws:
NullPointerException
- if the array isnull
IllegalArgumentException
- if the array is empty- Since:
- 18.11.0
-