Interface PropertyConstraint<T>

  • Type Parameters:
    T - Type of value to handle

    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.

    Clément Fournier
    • Method Detail

      • test

        default boolean test​(T t)
      • validate

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

        A description of the constraint
      • toCollectionConstraint

        default PropertyConstraint<Iterable<? extends T>> toCollectionConstraint()
        Returns a constraint that validates a collection of Ts by checking each component conforms to this constraint.
      • 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
        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().
        A new validator