Package org.hawaiiframework.validation
Class ValidationResult
java.lang.Object
org.hawaiiframework.validation.ValidationResult
- All Implemented Interfaces:
Serializable
Stores validation errors for a specific object.
This class is heavily inspired on Spring's Errors
interface. The main difference is that Hawaii's
ValidationResult
does not bind or require the target object being validated.
- Since:
- 2.0.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAllErrors
(List<ValidationError> errors) Adds the suppliedValidationError
s to thisValidationResult
.void
addAllErrors
(ValidationResult validationResult) Adds all errors from the suppliedValidationResult
to thisValidationResult
.void
addError
(ValidationError error) Adds the suppliedValidationError
to thisValidationResult
.Returns the validation errors.Returns the current nested path of thisValidationResult
.boolean
Returnstrue
if this validation result contains errors.void
void
pushNestedPath
(String path) void
pushNestedPath
(String path, int index) void
<T> FieldRejection<T>
rejectField
(String field, T actual) Reject afield
with valueactual
in a fluent manner.void
<T> void
void
rejectValue
(String code) void
rejectValue
(String field, String code) void
rejectValueIf
(boolean expr, String code) void
rejectValueIf
(boolean expr, String field, String code) <T> void
rejectValueIf
(T actual, org.hamcrest.Matcher<? super T> matcher, String code) <T> void
rejectValueIf
(T actual, org.hamcrest.Matcher<? super T> matcher, String field, String code) toString()
-
Constructor Details
-
ValidationResult
public ValidationResult()
-
-
Method Details
-
getNestedPath
Returns the current nested path of thisValidationResult
.- Returns:
- the current nested path
-
pushNestedPath
-
pushNestedPath
-
popNestedPath
- Throws:
IllegalArgumentException
-
hasErrors
public boolean hasErrors()Returnstrue
if this validation result contains errors.- Returns:
true
if this validation result contains errors
-
getErrors
Returns the validation errors.- Returns:
- the validation errors
-
reject
-
rejectIf
-
rejectIf
-
rejectValue
-
rejectValue
-
rejectValueIf
-
rejectValueIf
-
rejectValueIf
-
rejectValueIf
-
rejectField
Reject afield
with valueactual
in a fluent manner.For instance:
validationResult.rejectField("houseNumber", "13-a") .whenNull() .orWhen(containsString("a")) .orWhen(h -> h.length() > 4);
- Type Parameters:
T
- The type of the value.- Parameters:
field
- The field name to evaluate.actual
- The value to evaluate.- Returns:
- a new field rejection.
-
addError
Adds the suppliedValidationError
to thisValidationResult
.- Parameters:
error
- the validation error
-
addAllErrors
Adds the suppliedValidationError
s to thisValidationResult
.- Parameters:
errors
- the validation errors
-
addAllErrors
Adds all errors from the suppliedValidationResult
to thisValidationResult
.- Parameters:
validationResult
- the validation result to merge in
-
toString
-