Package org.hawaiiframework.validation
Class ValidationResult
- java.lang.Object
-
- org.hawaiiframework.validation.ValidationResult
-
public class ValidationResult extends Object
Stores validation errors for a specific object.This class is heavily inspired on Spring's
Errors
interface. The main difference is that Hawaii'sValidationResult
does not bind or require the target object being validated.- Since:
- 2.0.0
- Author:
- Marcel Overdijk, Rutger Lubbers
-
-
Field Summary
Fields Modifier and Type Field Description static String
NESTED_PATH_INDEX_PREFIX
static String
NESTED_PATH_INDEX_SUFFIX
static String
NESTED_PATH_SEPARATOR
The separator between path elements in a nested path, for example in "name" or "address.street".
-
Constructor Summary
Constructors Constructor Description ValidationResult()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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
.List<ValidationError>
getErrors()
Returns the validation errors.String
getNestedPath()
Returns the current nested path of thisValidationResult
.boolean
hasErrors()
Returnstrue
if this validation result contains errors.void
popNestedPath()
void
pushNestedPath(String path)
void
pushNestedPath(String path, int index)
void
reject(String code)
<T> FieldRejection<T>
rejectField(String field, T actual)
Reject afield
with valueactual
in a fluent manner.void
rejectIf(boolean expr, String code)
<T> void
rejectIf(T actual, Matcher<? super T> matcher, String code)
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, Matcher<? super T> matcher, String code)
<T> void
rejectValueIf(T actual, Matcher<? super T> matcher, String field, String code)
String
toString()
-
-
-
Field Detail
-
NESTED_PATH_SEPARATOR
public static final String NESTED_PATH_SEPARATOR
The separator between path elements in a nested path, for example in "name" or "address.street".- See Also:
- Constant Field Values
-
NESTED_PATH_INDEX_PREFIX
public static final String NESTED_PATH_INDEX_PREFIX
- See Also:
- Constant Field Values
-
NESTED_PATH_INDEX_SUFFIX
public static final String NESTED_PATH_INDEX_SUFFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
getNestedPath
public String getNestedPath()
Returns the current nested path of thisValidationResult
.- Returns:
- the current nested path
-
pushNestedPath
public void pushNestedPath(String path)
-
pushNestedPath
public void pushNestedPath(String path, int index)
-
popNestedPath
public void popNestedPath() throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
hasErrors
public boolean hasErrors()
Returnstrue
if this validation result contains errors.- Returns:
true
if this validation result contains errors
-
getErrors
public List<ValidationError> getErrors()
Returns the validation errors.- Returns:
- the validation errors
-
reject
public void reject(String code)
-
rejectIf
public void rejectIf(boolean expr, String code)
-
rejectValue
public void rejectValue(String code)
-
rejectValueIf
public void rejectValueIf(boolean expr, String code)
-
rejectValueIf
public <T> void rejectValueIf(T actual, Matcher<? super T> matcher, String field, String code)
-
rejectField
public <T> FieldRejection<T> rejectField(String field, T actual)
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
public void addError(ValidationError error)
Adds the suppliedValidationError
to thisValidationResult
.- Parameters:
error
- the validation error
-
addAllErrors
public void addAllErrors(List<ValidationError> errors)
Adds the suppliedValidationError
s to thisValidationResult
.- Parameters:
errors
- the validation errors
-
addAllErrors
public void addAllErrors(ValidationResult validationResult)
Adds all errors from the suppliedValidationResult
to thisValidationResult
.- Parameters:
validationResult
- the validation result to merge in
-
-