Interface PropertyConstraint<T>

  • Type Parameters:
    T - Type of value to handle

    @Experimental
    public interface PropertyConstraint<T>
    Validates the value of a property.

    This interface will change a lot with PMD 7.0.0, because of the switch to Java 8. Please use only the ready-made validators in NumericConstraints for now.

    Since:
    6.10.0
    Author:
    Clément Fournier
    • Method Detail

      • test

        boolean test​(T value)
      • validate

        String validate​(T value)
        Returns a diagnostic message if the value has a problem. Otherwise returns an empty optional.
        Parameters:
        value - The value to validate
        Returns:
        An optional diagnostic message
      • 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
      • toCollectionConstraint

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