Interface PropertyConstraint<T>

Type Parameters:
T - Type of value to handle

public interface PropertyConstraint<T>
Validates the value of a property.
Author:
Clément Fournier
Since:
6.10.0
See Also:
  • Method Details

    • validate

      void validate(T value)
      Checks that the value conforms to this constraint. Throws if that is not the case.
      Parameters:
      value - The value to validate
      Throws:
      ConstraintViolatedException - If this constraint is violated
    • getConstraintDescription

      String getConstraintDescription()
      Returns a description of the constraint imposed by this validator on the values. E.g. "Should be positive", or "Should be one of A | B | C."

      This is used to generate documentation.

      Returns:
      A description of the constraint
    • getXmlConstraint

      default Map<String,String> getXmlConstraint()
      Serializes this constraint as XML attributes, that are part of the property element of a rule definition.

      Note: This is only used for constraints, which can be defined in a rule definition in a ruleset (e.g. for XPath rules).

      Returns:
      a map with attribute name and attribute value, suitable to be used in XML.
      See Also:
      • SchemaConstants.PROPERTY_MIN
      • SchemaConstants.PROPERTY_MAX
    • toOptionalConstraint

      default PropertyConstraint<Optional<? extends T>> toOptionalConstraint()
      Returns a constraint that validates an Optional<T> by checking that the value conforms to this constraint if it is non-empty.
    • toCollectionConstraint

      default PropertyConstraint<Iterable<? extends T>> toCollectionConstraint()
      Returns a constraint that validates a collection of Ts by checking each component conforms to this validator.
      Returns:
      A collection validator
    • fromPredicate

      static <U> PropertyConstraint<U> fromPredicate(Predicate<? super U> pred, String constraintDescription)
      Builds a new validator from a predicate, and description.
      Type Parameters:
      U - Type of value to validate
      Parameters:
      pred - The predicate. If it returns false on a value, then the value is deemed to have a problem
      constraintDescription - Description of the constraint, see getConstraintDescription().
      Returns:
      A new validator
    • fromPredicate

      static <U> PropertyConstraint<U> fromPredicate(Predicate<? super U> pred, String constraintDescription, Map<String,String> xmlConstraint)
      Builds a new constraint from a predicate, a description and xml attributes to serialize the constraint.
      See Also: