Interface ValidationResult

All Superinterfaces:
Composable<ValidationResult>, Iterable<ValidationResult>, Localizable, LocalizableObject
All Known Implementing Classes:
AbstractValidationResult, ComposedValidationFailure, ValidationFailure, ValidationResultValid

public interface ValidationResult extends Composable<ValidationResult>, Localizable
Result of a validation. If valid is true, the message is null. Otherwise the message shall be filled and explain the reason of the failure in a understandable but short form to end-users. Examples are "Value may not be blank." or "Value has to be in the range from 5 to 9.". Depending on the usage the message may also contain additional context information in order to determine the source of the problem.
Since:
1.0.0
  • Method Details

    • isValid

      default boolean isValid()
      Returns:
      true if the validation was successful, false otherwise. A successful ValidationResult is always empty. All other methods will not return any resonable result.
    • getSource

      String getSource()
      Returns:
      the optional validation source describing the origin of the value that has been validated. May be null. If present this may be the filename where the value was read from, an XPath where the value was located in an XML document, the label of a widget of the UI containing the value, etc. This will help to find the problem easier.
    • getCode

      String getCode()
      Returns:
      the failure code or null if valid. For a single ValidationFailure this will be the ID of the failing Validator. The code is a stable identifier that indicates the type of the failure. It can be used for automated testing in order to make the test-cases independent from the actual message texts so they are maintainable and will not break e.g. if typos are fixed in the messages.
      See Also:
    • getMessage

      default String getMessage()
      Specified by:
      getMessage in interface Localizable
      See Also:
    • getMessage

      default String getMessage(boolean verbose)
      Parameters:
      verbose -
      Returns:
      the localized message.
      See Also:
    • getLocalizedMessage

      default String getLocalizedMessage(boolean verbose)
      This method gets the resolved and localized message.
      Parameters:
      verbose - the verbose flag (to include code(s), etc.
      Returns:
      the localized message.
    • getLocalizedMessage

      default String getLocalizedMessage(Locale locale, boolean verbose)
      This method gets the resolved and localized message.
      Parameters:
      locale - is the Locale to translate to.
      verbose - the verbose flag (to include code(s), etc.
      Returns:
      the localized message.
    • getLocalizedMessage

      default void getLocalizedMessage(Locale locale, Appendable buffer)
      Specified by:
      getLocalizedMessage in interface Localizable
      See Also:
    • getLocalizedMessage

      void getLocalizedMessage(Locale locale, Appendable buffer, boolean verbose)
      Parameters:
      locale - is the Locale to translate to.
      buffer - the Appendable where to write the message to.
      verbose - the verbose flag (to include code(s), etc.
      See Also:
    • add

      Parameters:
      result - another ValidationResult to combine with this one.
      Returns:
      the ValidationResult composed out of this with the given result.
      See Also:
    • containsCode

      default boolean containsCode(String code)
      Parameters:
      code - the code to check for.
      Returns:
      true if this ValidationResult itself has the given code or recursively contains such ValidationResults, false otherwise.