Interface ValueConstraint<T>

Type Parameters:
T - the value type
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@DoNotImplement @FunctionalInterface public interface ValueConstraint<T>
For constraining the set of allowed values.
  • Method Details

    • validate

      @Nullable String validate(T value)
      Checks if a value is valid.
      Parameters:
      value - the value to check
      Returns:
      null if valid, an error message if invalid
    • isValid

      default boolean isValid(T value)
      Tests if a value is allowed.
      Parameters:
      value - a value
      Returns:
      true is the value is allowed
    • getAllowedValuesDescription

      default @Nullable String getAllowedValuesDescription(ValueStringifier<T> stringifier)
      Returns a description of the allowed values.
      Parameters:
      stringifier - for converting values to strings
      Returns:
      a description of the allowed values
    • getAllowedValues

      default @Nullable List<T> getAllowedValues()
      Returns the list of allowed values, if available.
      Returns:
      the list of allowed values, or null if not available
    • forOptionalValues

      default ValueConstraint<Optional<T>> forOptionalValues()
      Converts this ValueConstraint<T> to ValueConstraint<Optional<T>>.
      Returns:
      the new constraint for optional values
    • withExtraValidation

      default ValueConstraint<T> withExtraValidation(ValueConstraint<T> extraConstraint)
      Creates a new composite constraint.
      Parameters:
      extraConstraint - an additional constraint
      Returns:
      the combined constraint