Class ValidationResult

java.lang.Object
org.hawaiiframework.validation.ValidationResult
All Implemented Interfaces:
Serializable

public class ValidationResult extends Object implements 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 Details

    • ValidationResult

      public ValidationResult()
  • Method Details

    • getNestedPath

      public String getNestedPath()
      Returns the current nested path of this ValidationResult.
      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()
      Returns true 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)
    • rejectIf

      public <T> void rejectIf(T actual, org.hamcrest.Matcher<? super T> matcher, String code)
    • rejectValue

      public void rejectValue(String code)
    • rejectValue

      public void rejectValue(String field, String code)
    • rejectValueIf

      public void rejectValueIf(boolean expr, String code)
    • rejectValueIf

      public <T> void rejectValueIf(T actual, org.hamcrest.Matcher<? super T> matcher, String code)
    • rejectValueIf

      public void rejectValueIf(boolean expr, String field, String code)
    • rejectValueIf

      public <T> void rejectValueIf(T actual, org.hamcrest.Matcher<? super T> matcher, String field, String code)
    • rejectField

      public <T> FieldRejection<T> rejectField(String field, T actual)
      Reject a field with value actual 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 supplied ValidationError to this ValidationResult.
      Parameters:
      error - the validation error
    • addAllErrors

      public void addAllErrors(List<ValidationError> errors)
      Adds the supplied ValidationErrors to this ValidationResult.
      Parameters:
      errors - the validation errors
    • addAllErrors

      public void addAllErrors(ValidationResult validationResult)
      Adds all errors from the supplied ValidationResult to this ValidationResult.
      Parameters:
      validationResult - the validation result to merge in
    • toString

      public String toString()
      Overrides:
      toString in class Object