Class RangeValidator<T extends Comparable>

java.lang.Object
com.vaadin.featurepack.data.validator.AbstractValidator<T>
com.vaadin.featurepack.data.validator.RangeValidator<T>
Type Parameters:
T - The type of Number to validate. Must implement Comparable so that minimum and maximum checks work.
All Implemented Interfaces:
Validator, Serializable
Direct Known Subclasses:
BigDecimalRangeValidator, BigIntegerRangeValidator, DateRangeValidator, DoubleRangeValidator, FloatRangeValidator, IntegerRangeValidator, LongRangeValidator, ShortRangeValidator

public class RangeValidator<T extends Comparable> extends AbstractValidator<T>
An base implementation for validating any objects that implement Comparable. Verifies that the value is of the given type and within the (optionally) given limits. Typically you want to use a sub class of this like IntegerRangeValidator, DoubleRangeValidator or DateRangeValidator in applications.

Note that RangeValidator always accept null values. Make a field required to ensure that no empty values are accepted or override isValidValue(Comparable).

Author:
Vaadin Ltd.
See Also:
  • Constructor Details

    • RangeValidator

      public RangeValidator(String errorMessage, Class<T> type, T minValue, T maxValue)
      Creates a new range validator of the given type.
      Parameters:
      errorMessage - The error message to use if validation fails
      type - The type of object the validator can validate.
      minValue - The minimum value that should be accepted or null for no limit
      maxValue - The maximum value that should be accepted or null for no limit
  • Method Details

    • isMinValueIncluded

      public boolean isMinValueIncluded()
      Checks if the minimum value is part of the accepted range
      Returns:
      true if the minimum value is part of the range, false otherwise
    • setMinValueIncluded

      public void setMinValueIncluded(boolean minValueIncluded)
      Sets if the minimum value is part of the accepted range
      Parameters:
      minValueIncluded - true if the minimum value should be part of the range, false otherwise
    • isMaxValueIncluded

      public boolean isMaxValueIncluded()
      Checks if the maximum value is part of the accepted range
      Returns:
      true if the maximum value is part of the range, false otherwise
    • setMaxValueIncluded

      public void setMaxValueIncluded(boolean maxValueIncluded)
      Sets if the maximum value is part of the accepted range
      Parameters:
      maxValueIncluded - true if the maximum value should be part of the range, false otherwise
    • getMinValue

      public T getMinValue()
      Gets the minimum value of the range
      Returns:
      the minimum value
    • setMinValue

      public void setMinValue(T minValue)
      Sets the minimum value of the range. Use setMinValueIncluded(boolean) to control whether this value is part of the range or not.
      Parameters:
      minValue - the minimum value
    • getMaxValue

      public T getMaxValue()
      Gets the maximum value of the range
      Returns:
      the maximum value
    • setMaxValue

      public void setMaxValue(T maxValue)
      Sets the maximum value of the range. Use setMaxValueIncluded(boolean) to control whether this value is part of the range or not.
      Parameters:
      maxValue - the maximum value
    • isValidValue

      protected boolean isValidValue(T value)
      Description copied from class: AbstractValidator
      Internally check the validity of a value. This method can be used to perform validation in subclasses if customization of the error message is not needed. Otherwise, subclasses should override AbstractValidator.validate(Object) and the return value of this method is ignored. This method should not be called from outside the validator class itself.
      Specified by:
      isValidValue in class AbstractValidator<T extends Comparable>
      Parameters:
      value -
      Returns:
    • getType

      public Class<T> getType()
      Specified by:
      getType in class AbstractValidator<T extends Comparable>