Class FieldRejection<T>
java.lang.Object
org.hawaiiframework.validation.field.FieldRejection<T>
- Type Parameters:
T
- The type of the value to evaluate.
Reject a field based on a few conditions.
For instance:
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.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionFieldRejection
(ValidationResult validationResult, String field, T actual) Construct a new field rejection. -
Method Summary
Modifier and TypeMethodDescriptionor()
Syntactic sugar, allows the use ofor().when(...).or().when(...)
syntaxis.<R> FieldRejection<T>
Rejects the field when thematcher
matches the result of thefunction
.<R> FieldRejection<T>
Rejects the field when thematcher
matches the result of thefunction
.Rejects the field when thepredicate
evaluates totrue
.Rejects the field when thepredicate
evaluates totrue
.Rejects the field when thematcher
matches theactual
value.Rejects the field when thematcher
matches theactual
value.<R> FieldRejection<T>
Rejects the field when thematcher
matches the result of thefunction
.<R> FieldRejection<T>
Rejects the field when thematcher
matches the result of thefunction
.Rejects the field when thepredicate
evaluates totrue
.Rejects the field when thepredicate
evaluates totrue
.Rejects the field when thematcher
matches theactual
value.Rejects the field when thematcher
matches theactual
value.<R> FieldRejection<T>
Rejects the field when thematcher
matches the result of thefunction
.<R> FieldRejection<T>
Rejects the field when thematcher
matches the result of thefunction
.Rejects the field when thepredicate
evaluates totrue
.Rejects the field when thepredicate
evaluates totrue
.Rejects the field when thematcher
matches theactual
value.Rejects the field when thematcher
matches theactual
value.whenNull()
Rejects the field when theactual
isnull
.Rejects the field when theactual
isnull
.
-
Field Details
-
REQUIRED
- See Also:
-
INVALID
- See Also:
-
-
Constructor Details
-
FieldRejection
Construct a new field rejection.- Parameters:
validationResult
- The validation result.field
- The field name (property name).actual
- The field's value.
-
-
Method Details
-
or
Syntactic sugar, allows the use ofor().when(...).or().when(...)
syntaxis.- Returns:
- The current field rejection.
-
or
Rejects the field when thematcher
matches theactual
value. This will reject the field with the error codeinvalid
.- Parameters:
matcher
- The matcher to use.- Returns:
- The current field rejection.
-
or
Rejects the field when thematcher
matches theactual
value. This will reject the field with supplied the error codecode
.- Parameters:
matcher
- The matcher to use.- Returns:
- The current field rejection.
-
or
Rejects the field when thepredicate
evaluates totrue
. This will reject the field with the error codeinvalid
.- Parameters:
predicate
- The predicate to use.- Returns:
- The current field rejection.
-
or
Rejects the field when thepredicate
evaluates totrue
. This will reject the field with supplied the error codecode
.- Parameters:
predicate
- The predicate to use.- Returns:
- The current field rejection.
-
or
Rejects the field when thematcher
matches the result of thefunction
. This will reject the field with the error codeinvalid
.- Parameters:
function
- The function to apply to theactual
value.matcher
- The matcher to use against the return value of thefunction
.- Returns:
- The current field rejection.
-
or
public <R> FieldRejection<T> or(Function<T, R> function, org.hamcrest.Matcher<R> matcher, String code) Rejects the field when thematcher
matches the result of thefunction
. This will reject the field with supplied the error codecode
.- Parameters:
function
- The function to apply to theactual
value.matcher
- The matcher to use against the return value of thefunction
.- Returns:
- The current field rejection.
-
whenNull
Rejects the field when theactual
isnull
. This will reject the field with the error coderequired
.- Returns:
- The current field rejection.
-
whenNull
Rejects the field when theactual
isnull
. This will reject the field with supplied the error codecode
.- Parameters:
code
- The error code to set if the actual value isnull
.- Returns:
- The current field rejection.
-
when
Rejects the field when thematcher
matches theactual
value. This will reject the field with the error codeinvalid
.- Parameters:
matcher
- The matcher to use.- Returns:
- The current field rejection.
-
when
Rejects the field when thematcher
matches theactual
value. This will reject the field with supplied the error codecode
.- Parameters:
matcher
- The matcher to use.- Returns:
- The current field rejection.
-
when
Rejects the field when thepredicate
evaluates totrue
. This will reject the field with the error codeinvalid
.- Parameters:
predicate
- The predicate to use.- Returns:
- The current field rejection.
-
when
Rejects the field when thematcher
matches the result of thefunction
. This will reject the field with the error codeinvalid
.- Parameters:
function
- The function to apply to theactual
value.matcher
- The matcher to use against the return value of thefunction
.- Returns:
- The current field rejection.
-
when
public <R> FieldRejection<T> when(Function<T, R> function, org.hamcrest.Matcher<R> matcher, String code) Rejects the field when thematcher
matches the result of thefunction
. This will reject the field with supplied the error codecode
.- Parameters:
function
- The function to apply to theactual
value.matcher
- The matcher to use against the return value of thefunction
.- Returns:
- The current field rejection.
-
when
Rejects the field when thepredicate
evaluates totrue
. This will reject the field with supplied the error codecode
.- Parameters:
predicate
- The predicate to use.- Returns:
- The current field rejection.
-
orWhen
Rejects the field when thematcher
matches theactual
value. This will reject the field with the error codeinvalid
.- Parameters:
matcher
- The matcher to use.- Returns:
- The current field rejection.
-
orWhen
Rejects the field when thematcher
matches theactual
value. This will reject the field with supplied the error codecode
.- Parameters:
matcher
- The matcher to use.- Returns:
- The current field rejection.
-
orWhen
Rejects the field when thepredicate
evaluates totrue
. This will reject the field with the error codeinvalid
.- Parameters:
predicate
- The predicate to use.- Returns:
- The current field rejection.
-
orWhen
Rejects the field when thepredicate
evaluates totrue
. This will reject the field with supplied the error codecode
.- Parameters:
predicate
- The predicate to use.- Returns:
- The current field rejection.
-
orWhen
Rejects the field when thematcher
matches the result of thefunction
. This will reject the field with the error codeinvalid
.- Parameters:
function
- The function to apply to theactual
value.matcher
- The matcher to use against the return value of thefunction
.- Returns:
- The current field rejection.
-
orWhen
public <R> FieldRejection<T> orWhen(Function<T, R> function, org.hamcrest.Matcher<R> matcher, String code) Rejects the field when thematcher
matches the result of thefunction
. This will reject the field with supplied the error codecode
.- Parameters:
function
- The function to apply to theactual
value.matcher
- The matcher to use against the return value of thefunction
.- Returns:
- The current field rejection.
-