public final class RequirementVerifier extends Object implements Verifier
Unlike Requirements, instances of this class can be configured prior to initiating
verification. Doing so causes the same configuration to get reused across runs.
| Constructor and Description |
|---|
RequirementVerifier()
Creates a new requirement verifier.
|
| Modifier and Type | Method and Description |
|---|---|
RequirementVerifier |
addContext(String key,
Object value)
Appends contextual information to the exception message.
|
BigDecimalRequirements |
requireThat(BigDecimal parameter,
String name)
Verifies requirements of a
BigDecimal. |
<T> ClassRequirements<T> |
requireThat(Class<T> parameter,
String name)
Verifies requirements of a
Class. |
<E> CollectionRequirements<E> |
requireThat(Collection<E> parameter,
String name)
Verifies requirements of a
Collection. |
DoubleRequirements |
requireThat(Double parameter,
String name)
Verifies requirements of a
Double. |
<K,V> MapRequirements<K,V> |
requireThat(Map<K,V> parameter,
String name)
Verifies requirements of a
Map. |
ObjectRequirements<Object> |
requireThat(Object parameter,
String name)
Verifies requirements of an
Object. |
OptionalRequirements |
requireThat(Optional<?> parameter,
String name)
Verifies requirements of an
Optional. |
PathRequirements |
requireThat(Path parameter,
String name)
Verifies requirements of a
Path. |
StringRequirements |
requireThat(String parameter,
String name)
Verifies requirements of a
String. |
<T extends Comparable<? super T>> |
requireThat(T parameter,
String name)
Verifies requirements of a
Comparable. |
<T extends Number & Comparable<? super T>> |
requireThat(T parameter,
String name)
Verifies requirements of a
Number. |
UriRequirements |
requireThat(URI parameter,
String name)
Verifies requirements of a
Uri. |
RequirementVerifier |
withContext(List<Map.Entry<String,Object>> context)
Sets the contextual information to append to the exception message.
|
RequirementVerifier |
withException(Class<? extends RuntimeException> exception)
Overrides the type of exception that will get thrown if a requirement fails.
|
public RequirementVerifier()
public RequirementVerifier withException(Class<? extends RuntimeException> exception)
VerifierThe exception class must define the following constructors:
<init>(String message)
<init>(String message, Throwable cause)
withException in interface Verifierexception - the type of exception to throw, null to throw the default exception
type@Beta public RequirementVerifier addContext(String key, Object value) throws NullPointerException
VerifieraddContext in interface Verifierkey - a keyvalue - a valueNullPointerException - if key is null@Beta public RequirementVerifier withContext(List<Map.Entry<String,Object>> context) throws NullPointerException
VerifierwithContext in interface Verifiercontext - the contextual informationNullPointerException - if context is nullpublic ObjectRequirements<Object> requireThat(Object parameter, String name) throws NullPointerException, IllegalArgumentException
Object.parameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptypublic <E> CollectionRequirements<E> requireThat(Collection<E> parameter, String name) throws NullPointerException, IllegalArgumentException
Collection.E - the type of element in the collectionparameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptypublic <T extends Comparable<? super T>> ComparableRequirements<T> requireThat(T parameter, String name) throws NullPointerException, IllegalArgumentException
Comparable.T - the type of objects that the parameter may be compared toparameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptypublic <T extends Number & Comparable<? super T>> NumberRequirements<T> requireThat(T parameter, String name) throws NullPointerException, IllegalArgumentException
Number.T - the type of the numberparameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptypublic DoubleRequirements requireThat(Double parameter, String name) throws NullPointerException, IllegalArgumentException
Double.parameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptypublic BigDecimalRequirements requireThat(BigDecimal parameter, String name) throws NullPointerException, IllegalArgumentException
BigDecimal.parameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptypublic <K,V> MapRequirements<K,V> requireThat(Map<K,V> parameter, String name) throws NullPointerException, IllegalArgumentException
Map.K - the type of key in the mapV - the type of value in the mapparameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptypublic PathRequirements requireThat(Path parameter, String name) throws NullPointerException, IllegalArgumentException
Path.parameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptypublic StringRequirements requireThat(String parameter, String name) throws NullPointerException, IllegalArgumentException
String.parameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptypublic UriRequirements requireThat(URI parameter, String name) throws NullPointerException, IllegalArgumentException
Uri.parameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptypublic <T> ClassRequirements<T> requireThat(Class<T> parameter, String name) throws NullPointerException, IllegalArgumentException
Class.T - the type of classparameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptypublic OptionalRequirements requireThat(Optional<?> parameter, String name) throws NullPointerException, IllegalArgumentException
Optional.parameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptyCopyright © 2016. All rights reserved.