Check class for
parameter/value validation using a rich and expandable set of utility functions.
Checks can be performed on:
Failing checks result in an IllegalArgumentException, with a meaningful message which check has failed, including the parameter name.
Example:
java.lang.IllegalArgumentException: 'customer id' must have at least 6 characters
Check.required(url, "connection url");
Check.required(name, "name", CheckString.notBlank(), CheckString.max(20));
Check.optional(val, "value", CheckNumber.finite(), CheckNumber.greaterThan(0));
Check.required(items, "items", CheckCollection.notEmpty(), CheckCollection.noNullElements());
Check.required(token, "token", CheckString.format("[A-Z0-9]{32}", "alphanumeric uppercase"));
Verify functional interface. This interface also provides static methods
to create implementations based on Predicate and predefined or dynamic
failure messages.
Examples for custom validation:
Verify<ZonedDateTime> futureDate = d -> {
if (!d.isAfter(ZonedDateTime.now())) {
throw new IllegalArgumentException("must be in the future");
}
};
Check.required(date, "execution date", futureDate);
or Check.required(date, "execution date",
Verify.that(d -> !d.isAfter(ZonedDateTime.now()), "must be in the future"));
| Interface | Description |
|---|---|
| Verify<T> |
Verifier interface, for check to be performed with
Check. |
| Class | Description |
|---|---|
| Check |
Check class for input validation.
|
| CheckCollection |
Utility methods to perform checks on
Collection values. |
| CheckNumber |
Utility methods to perform checks on
Number values. |
| CheckString |
Utility methods to perform checks on
String values. |