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
-
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
Remove the nested path.void
pushNestedPath
(String path) Push the nested path.void
pushNestedPath
(String path, int index) Push the nested path.void
Reject the value.<T> FieldRejection<T>
rejectField
(String field, T actual) Reject afield
with valueactual
in a fluent manner.void
Reject the valueexpr
istrue
.<T> void
Reject the valueactual
if thematcher
matches.void
rejectValue
(String code) Reject the value withcode
error.void
rejectValue
(String field, String code) Reject the value forfield
withcode
error.void
rejectValueIf
(boolean expr, String code) Reject the value ifexpr
istrue
.void
rejectValueIf
(boolean expr, String field, String code) Reject the value ifexpr
istrue
.<T> void
rejectValueIf
(T actual, org.hamcrest.Matcher<? super T> matcher, String code) Reject the value ifmatcher
matches the valueactual
.<T> void
rejectValueIf
(T actual, org.hamcrest.Matcher<? super T> matcher, String field, String code) Reject the value if the value matches thematcher
.toString()
-
Constructor Details
-
ValidationResult
public ValidationResult()
-
-
Method Details
-
getNestedPath
Returns the current nested path of thisValidationResult
.- Returns:
- the current nested path
-
pushNestedPath
Push the nested path. -
pushNestedPath
Push the nested path. -
popNestedPath
public void popNestedPath()Remove the nested path. -
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
Reject the value. -
rejectIf
Reject the valueexpr
istrue
. -
rejectIf
Reject the valueactual
if thematcher
matches. -
rejectValue
Reject the value withcode
error. -
rejectValue
Reject the value forfield
withcode
error. -
rejectValueIf
Reject the value ifexpr
istrue
. Will return thecode
error. -
rejectValueIf
Reject the value ifmatcher
matches the valueactual
. Will return thecode
error on thefield
. -
rejectValueIf
Reject the value ifexpr
istrue
. Will return thecode
error on thefield
. -
rejectValueIf
public <T> void rejectValueIf(T actual, org.hamcrest.Matcher<? super T> matcher, String field, String code) Reject the value if the value matches thematcher
. Will return thecode
error on thefield
. -
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
-