Class FieldRejection<T>
- java.lang.Object
- 
- org.hawaiiframework.validation.field.FieldRejection<T>
 
- 
- Type Parameters:
- T- The type of the value to evaluate.
 
 public class FieldRejection<T> extends Object 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 codeparameters have the valueinvalid, except thewhenNull(), this has therequiredcode 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. - Author:
- Rutger Lubbers
 
- 
- 
Constructor SummaryConstructors Constructor Description FieldRejection(ValidationResult validationResult, String field, T actual)Construct a new field rejection.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description FieldRejection<T>or()Syntactic sugar, allows the use ofor().when(...).or().when(...)syntaxis.<R> FieldRejection<T>or(Function<T,R> function, Matcher<R> matcher)Rejects the field when thematchermatches the result of thefunction.<R> FieldRejection<T>or(Function<T,R> function, Matcher<R> matcher, String code)Rejects the field when thematchermatches the result of thefunction.FieldRejection<T>or(Predicate<T> predicate)Rejects the field when thepredicateevaluates totrue.FieldRejection<T>or(Predicate<T> predicate, String code)Rejects the field when thepredicateevaluates totrue.FieldRejection<T>or(Matcher<T> matcher)Rejects the field when thematchermatches theactualvalue.FieldRejection<T>or(Matcher<T> matcher, String code)Rejects the field when thematchermatches theactualvalue.<R> FieldRejection<T>orWhen(Function<T,R> function, Matcher<R> matcher)Rejects the field when thematchermatches the result of thefunction.<R> FieldRejection<T>orWhen(Function<T,R> function, Matcher<R> matcher, String code)Rejects the field when thematchermatches the result of thefunction.FieldRejection<T>orWhen(Predicate<T> predicate)Rejects the field when thepredicateevaluates totrue.FieldRejection<T>orWhen(Predicate<T> predicate, String code)Rejects the field when thepredicateevaluates totrue.FieldRejection<T>orWhen(Matcher<T> matcher)Rejects the field when thematchermatches theactualvalue.FieldRejection<T>orWhen(Matcher<T> matcher, String code)Rejects the field when thematchermatches theactualvalue.<R> FieldRejection<T>when(Function<T,R> function, Matcher<R> matcher)Rejects the field when thematchermatches the result of thefunction.<R> FieldRejection<T>when(Function<T,R> function, Matcher<R> matcher, String code)Rejects the field when thematchermatches the result of thefunction.FieldRejection<T>when(Predicate<T> predicate)Rejects the field when thepredicateevaluates totrue.FieldRejection<T>when(Predicate<T> predicate, String code)Rejects the field when thepredicateevaluates totrue.FieldRejection<T>when(Matcher<T> matcher)Rejects the field when thematchermatches theactualvalue.FieldRejection<T>when(Matcher<T> matcher, String code)Rejects the field when thematchermatches theactualvalue.FieldRejection<T>whenNull()Rejects the field when theactualisnull.FieldRejection<T>whenNull(String code)Rejects the field when theactualisnull.
 
- 
- 
- 
Field Detail- 
REQUIREDpublic static final String REQUIRED - See Also:
- Constant Field Values
 
 - 
INVALIDpublic static final String INVALID - See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
FieldRejectionpublic FieldRejection(ValidationResult validationResult, String field, T actual) Construct a new field rejection.- Parameters:
- validationResult- The validation result.
- field- The field name (property name).
- actual- The field's value.
 
 
- 
 - 
Method Detail- 
orpublic FieldRejection<T> or() Syntactic sugar, allows the use ofor().when(...).or().when(...)syntaxis.- Returns:
- The current field rejection.
 
 - 
orpublic FieldRejection<T> or(Matcher<T> matcher) Rejects the field when thematchermatches theactualvalue. This will reject the field with the error codeinvalid.- Parameters:
- matcher- The matcher to use.
- Returns:
- The current field rejection.
 
 - 
orpublic FieldRejection<T> or(Matcher<T> matcher, String code) Rejects the field when thematchermatches theactualvalue. This will reject the field with supplied the error codecode.- Parameters:
- matcher- The matcher to use.
- Returns:
- The current field rejection.
 
 - 
orpublic FieldRejection<T> or(Predicate<T> predicate) Rejects the field when thepredicateevaluates totrue. This will reject the field with the error codeinvalid.- Parameters:
- predicate- The predicate to use.
- Returns:
- The current field rejection.
 
 - 
orpublic FieldRejection<T> or(Predicate<T> predicate, String code) Rejects the field when thepredicateevaluates totrue. This will reject the field with supplied the error codecode.- Parameters:
- predicate- The predicate to use.
- Returns:
- The current field rejection.
 
 - 
orpublic <R> FieldRejection<T> or(Function<T,R> function, Matcher<R> matcher) Rejects the field when thematchermatches the result of thefunction. This will reject the field with the error codeinvalid.- Parameters:
- function- The function to apply to the- actualvalue.
- matcher- The matcher to use against the return value of the- function.
- Returns:
- The current field rejection.
 
 - 
orpublic <R> FieldRejection<T> or(Function<T,R> function, Matcher<R> matcher, String code) Rejects the field when thematchermatches the result of thefunction. This will reject the field with supplied the error codecode.- Parameters:
- function- The function to apply to the- actualvalue.
- matcher- The matcher to use against the return value of the- function.
- Returns:
- The current field rejection.
 
 - 
whenNullpublic FieldRejection<T> whenNull() Rejects the field when theactualisnull. This will reject the field with the error coderequired.- Returns:
- The current field rejection.
 
 - 
whenNullpublic FieldRejection<T> whenNull(String code) Rejects the field when theactualisnull. This will reject the field with supplied the error codecode.- Parameters:
- code- The error code to set if the actual value is- null.
- Returns:
- The current field rejection.
 
 - 
whenpublic FieldRejection<T> when(Matcher<T> matcher) Rejects the field when thematchermatches theactualvalue. This will reject the field with the error codeinvalid.- Parameters:
- matcher- The matcher to use.
- Returns:
- The current field rejection.
 
 - 
whenpublic FieldRejection<T> when(Matcher<T> matcher, String code) Rejects the field when thematchermatches theactualvalue. This will reject the field with supplied the error codecode.- Parameters:
- matcher- The matcher to use.
- Returns:
- The current field rejection.
 
 - 
whenpublic FieldRejection<T> when(Predicate<T> predicate) Rejects the field when thepredicateevaluates totrue. This will reject the field with the error codeinvalid.- Parameters:
- predicate- The predicate to use.
- Returns:
- The current field rejection.
 
 - 
whenpublic <R> FieldRejection<T> when(Function<T,R> function, Matcher<R> matcher) Rejects the field when thematchermatches the result of thefunction. This will reject the field with the error codeinvalid.- Parameters:
- function- The function to apply to the- actualvalue.
- matcher- The matcher to use against the return value of the- function.
- Returns:
- The current field rejection.
 
 - 
whenpublic <R> FieldRejection<T> when(Function<T,R> function, Matcher<R> matcher, String code) Rejects the field when thematchermatches the result of thefunction. This will reject the field with supplied the error codecode.- Parameters:
- function- The function to apply to the- actualvalue.
- matcher- The matcher to use against the return value of the- function.
- Returns:
- The current field rejection.
 
 - 
whenpublic FieldRejection<T> when(Predicate<T> predicate, String code) Rejects the field when thepredicateevaluates totrue. This will reject the field with supplied the error codecode.- Parameters:
- predicate- The predicate to use.
- Returns:
- The current field rejection.
 
 - 
orWhenpublic FieldRejection<T> orWhen(Matcher<T> matcher) Rejects the field when thematchermatches theactualvalue. This will reject the field with the error codeinvalid.- Parameters:
- matcher- The matcher to use.
- Returns:
- The current field rejection.
 
 - 
orWhenpublic FieldRejection<T> orWhen(Matcher<T> matcher, String code) Rejects the field when thematchermatches theactualvalue. This will reject the field with supplied the error codecode.- Parameters:
- matcher- The matcher to use.
- Returns:
- The current field rejection.
 
 - 
orWhenpublic FieldRejection<T> orWhen(Predicate<T> predicate) Rejects the field when thepredicateevaluates totrue. This will reject the field with the error codeinvalid.- Parameters:
- predicate- The predicate to use.
- Returns:
- The current field rejection.
 
 - 
orWhenpublic FieldRejection<T> orWhen(Predicate<T> predicate, String code) Rejects the field when thepredicateevaluates totrue. This will reject the field with supplied the error codecode.- Parameters:
- predicate- The predicate to use.
- Returns:
- The current field rejection.
 
 - 
orWhenpublic <R> FieldRejection<T> orWhen(Function<T,R> function, Matcher<R> matcher) Rejects the field when thematchermatches the result of thefunction. This will reject the field with the error codeinvalid.- Parameters:
- function- The function to apply to the- actualvalue.
- matcher- The matcher to use against the return value of the- function.
- Returns:
- The current field rejection.
 
 - 
orWhenpublic <R> FieldRejection<T> orWhen(Function<T,R> function, Matcher<R> matcher, String code) Rejects the field when thematchermatches the result of thefunction. This will reject the field with supplied the error codecode.- Parameters:
- function- The function to apply to the- actualvalue.
- matcher- The matcher to use against the return value of the- function.
- Returns:
- The current field rejection.
 
 
- 
 
-