Class Validation

java.lang.Object
org.brapi.schematools.core.validiation.Validation

public class Validation extends Object
Provides the results of a validation
  • Constructor Details

    • Validation

      public Validation()
  • Method Details

    • valid

      public static Validation valid()
      Get a valid instant of the Validation
      Returns:
      a valid instant of the Validation
    • assertNotNull

      public Validation assertNotNull(Object value, String errorMessage, Object... args)
      Checks if the value is non-null.
      Parameters:
      value - the value to be tested
      errorMessage - the error message to be used if the value is null
      args - argument for te error message, See String.format(String, Object...) to see the options
      Returns:
      The validation with the appended error if there was one generated.
    • assertMutuallyExclusive

      public Validation assertMutuallyExclusive(Object value, String... properties)
      Validate that only one of the provided properties is non-null
      Parameters:
      value - the value to be tested
      properties - the array of properties to be checked
      Returns:
      this Validation
    • assertClass

      public Validation assertClass(Object value, List<Class<?>> classes)
      Checks that the provided value is one of the provided classes
      Parameters:
      value - the value to be checked
      classes - the list of permitted classes that the provided value must adhere to
      Returns:
      this Validation
    • isValid

      public boolean isValid()
      Was the validation successful,
      Returns:
      true if the validation was successful, false otherwise
    • merge

      public Validation merge(Validatable validatable)
      Merge the objects to Validation, by calling the Validatable.validate() method and adding any errors to this Validation
      Parameters:
      validatable - the object to be validated
      Returns:
      this Validation
    • merge

      public Validation merge(Response<?> response)
      Merge the Response to Validation, by adding any errors to this Validation
      Parameters:
      response - the object to be validated
      Returns:
      this Validation
    • merge

      public Validation merge(Validatable validatable, String prefixMessage)
      Merge the objects to Validation, by calling the Validatable.validate() method and adding any errors to this Validation
      Parameters:
      validatable - the object to be validated
      prefixMessage - prefix any errors with this message
      Returns:
      this Validation
    • mergeOnCondition

      public Validation mergeOnCondition(boolean condition, Validatable validatable)
      If the condition is true, merge the objects to Validation, by calling the Validatable.validate() method and adding any errors to this Validation
      Parameters:
      condition - if true merge, otherwise don't
      validatable - the object to be validated
      Returns:
      this Validation
    • mergeOnCondition

      public Validation mergeOnCondition(boolean condition, Validatable validatable, String prefixMessage)
      If the condition is true, merge the objects to Validation, by calling the Validatable.validate() method and adding any errors to this Validation
      Parameters:
      condition - if true merge, otherwise don't
      validatable - the object to be validated
      prefixMessage - prefix any errors with this message
      Returns:
      this Validation
    • getErrorMessages

      public List<String> getErrorMessages()
      Gets a list of all error messages or an empty list if there are no errors.
      Returns:
      a list of all error messages or an empty list if there are no errors.
    • getAllErrorsMessage

      public String getAllErrorsMessage()
      Gets concatenated a list of all error messages or null if there are no errors.
      Returns:
      a concatenated a list of all error messages or null if there are no errors.
    • merge

      public <T extends Validatable> Validation merge(List<T> validatableList)
      Merge the objects to Validation, by calling the Validatable.validate() method in each object and adding any errors to this Validation
      Type Parameters:
      T - the class of Validatable object
      Parameters:
      validatableList - the options to be validated
      Returns:
      this Validation
    • asResponse

      public <U> Response<U> asResponse()
      Returns this Validation as a Response
      Type Parameters:
      U - The type of the result
      Returns:
      this Validation as a Response