T
- The type of the value to evaluate.public class FieldRejection<T> extends Object
new FieldRejection(validationResult, "houseNumber", "13-a") .whenNull() .orWhen(h -> h.contains("a")) .orWhen(h -> h.length() > 10);If used with the ValidationResult class this will look like:
validationResult.rejectField("houseNumber", "13-a") .whenNull() .orWhen(h -> h.contains("a')) .orWhen(h -> h.length() > 10);The rejections without
code
parameters have the value invalid
, except the
whenNull()
, this has the required
code value.
The chain will stop evaluating the rejection clauses after the first matching clause. In the examples above
the chain will not evaluate the length of the house number.Modifier and Type | Field and Description |
---|---|
static String |
INVALID |
static String |
REQUIRED |
Constructor and Description |
---|
FieldRejection(ValidationResult validationResult,
String field,
T actual)
Construct a new field rejection.
|
Modifier and Type | Method and Description |
---|---|
FieldRejection<T> |
or()
Syntactic sugar, allows the use of
or().when(...).or().when(...) syntaxis. |
<R> FieldRejection<T> |
or(Function<T,R> function,
Matcher<R> matcher)
Rejects the field when the
matcher matches the result of the function . |
<R> FieldRejection<T> |
or(Function<T,R> function,
Matcher<R> matcher,
String code)
Rejects the field when the
matcher matches the result of the function . |
FieldRejection<T> |
or(Matcher<T> matcher)
Rejects the field when the
matcher matches the actual value. |
FieldRejection<T> |
or(Matcher<T> matcher,
String code)
Rejects the field when the
matcher matches the actual value. |
FieldRejection<T> |
or(Predicate<T> predicate)
Rejects the field when the
predicate evaluates to true . |
FieldRejection<T> |
or(Predicate<T> predicate,
String code)
Rejects the field when the
predicate evaluates to true . |
<R> FieldRejection<T> |
orWhen(Function<T,R> function,
Matcher<R> matcher)
Rejects the field when the
matcher matches the result of the function . |
<R> FieldRejection<T> |
orWhen(Function<T,R> function,
Matcher<R> matcher,
String code)
Rejects the field when the
matcher matches the result of the function . |
FieldRejection<T> |
orWhen(Matcher<T> matcher)
Rejects the field when the
matcher matches the actual value. |
FieldRejection<T> |
orWhen(Matcher<T> matcher,
String code)
Rejects the field when the
matcher matches the actual value. |
FieldRejection<T> |
orWhen(Predicate<T> predicate)
Rejects the field when the
predicate evaluates to true . |
FieldRejection<T> |
orWhen(Predicate<T> predicate,
String code)
Rejects the field when the
predicate evaluates to true . |
<R> FieldRejection<T> |
when(Function<T,R> function,
Matcher<R> matcher)
Rejects the field when the
matcher matches the result of the function . |
<R> FieldRejection<T> |
when(Function<T,R> function,
Matcher<R> matcher,
String code)
Rejects the field when the
matcher matches the result of the function . |
FieldRejection<T> |
when(Matcher<T> matcher)
Rejects the field when the
matcher matches the actual value. |
FieldRejection<T> |
when(Matcher<T> matcher,
String code)
Rejects the field when the
matcher matches the actual value. |
FieldRejection<T> |
when(Predicate<T> predicate)
Rejects the field when the
predicate evaluates to true . |
FieldRejection<T> |
when(Predicate<T> predicate,
String code)
Rejects the field when the
predicate evaluates to true . |
FieldRejection<T> |
whenNull()
Rejects the field when the
actual is null . |
FieldRejection<T> |
whenNull(String code)
Rejects the field when the
actual is null . |
public static final String REQUIRED
public static final String INVALID
public FieldRejection(ValidationResult validationResult, String field, T actual)
validationResult
- The validation result.field
- The field name (property name).actual
- The field's value.public FieldRejection<T> or()
or().when(...).or().when(...)
syntaxis.public FieldRejection<T> or(Matcher<T> matcher)
matcher
matches the actual
value. This will reject the field with the error
code invalid
.matcher
- The matcher to use.public FieldRejection<T> or(Matcher<T> matcher, String code)
matcher
matches the actual
value. This will reject the field
with supplied the error code code
.matcher
- The matcher to use.public FieldRejection<T> or(Predicate<T> predicate)
predicate
evaluates to true
. This will reject the field with the error
code invalid
.predicate
- The predicate to use.public FieldRejection<T> or(Predicate<T> predicate, String code)
predicate
evaluates to true
. This will reject the field
with supplied the error code code
.predicate
- The predicate to use.public <R> FieldRejection<T> or(Function<T,R> function, Matcher<R> matcher)
matcher
matches the result of the function
.
This will reject the field with the error code invalid
.function
- The function to apply to the actual
value.matcher
- The matcher to use against the return value of the function
.public <R> FieldRejection<T> or(Function<T,R> function, Matcher<R> matcher, String code)
matcher
matches the result of the function
.
This will reject the field with supplied the error code code
.function
- The function to apply to the actual
value.matcher
- The matcher to use against the return value of the function
.public FieldRejection<T> whenNull()
actual
is null
. This will reject the field with the error
code required
.public FieldRejection<T> whenNull(String code)
actual
is null
. This will reject the field
with supplied the error code code
.code
- The error code to set if the actual value is null
.public FieldRejection<T> when(Matcher<T> matcher)
matcher
matches the actual
value. This will reject the field with the error
code invalid
.matcher
- The matcher to use.public FieldRejection<T> when(Matcher<T> matcher, String code)
matcher
matches the actual
value. This will reject the field
with supplied the error code code
.matcher
- The matcher to use.public FieldRejection<T> when(Predicate<T> predicate)
predicate
evaluates to true
. This will reject the field with the error
code invalid
.predicate
- The predicate to use.public <R> FieldRejection<T> when(Function<T,R> function, Matcher<R> matcher)
matcher
matches the result of the function
.
This will reject the field with the error code invalid
.function
- The function to apply to the actual
value.matcher
- The matcher to use against the return value of the function
.public <R> FieldRejection<T> when(Function<T,R> function, Matcher<R> matcher, String code)
matcher
matches the result of the function
.
This will reject the field with supplied the error code code
.function
- The function to apply to the actual
value.matcher
- The matcher to use against the return value of the function
.public FieldRejection<T> when(Predicate<T> predicate, String code)
predicate
evaluates to true
. This will reject the field
with supplied the error code code
.predicate
- The predicate to use.public FieldRejection<T> orWhen(Matcher<T> matcher)
matcher
matches the actual
value. This will reject the field with the error
code invalid
.matcher
- The matcher to use.public FieldRejection<T> orWhen(Matcher<T> matcher, String code)
matcher
matches the actual
value. This will reject the field
with supplied the error code code
.matcher
- The matcher to use.public FieldRejection<T> orWhen(Predicate<T> predicate)
predicate
evaluates to true
. This will reject the field with the error
code invalid
.predicate
- The predicate to use.public FieldRejection<T> orWhen(Predicate<T> predicate, String code)
predicate
evaluates to true
. This will reject the field
with supplied the error code code
.predicate
- The predicate to use.public <R> FieldRejection<T> orWhen(Function<T,R> function, Matcher<R> matcher)
matcher
matches the result of the function
.
This will reject the field with the error code invalid
.function
- The function to apply to the actual
value.matcher
- The matcher to use against the return value of the function
.public <R> FieldRejection<T> orWhen(Function<T,R> function, Matcher<R> matcher, String code)
matcher
matches the result of the function
.
This will reject the field with supplied the error code code
.function
- The function to apply to the actual
value.matcher
- The matcher to use against the return value of the function
.