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
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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.vaadin.featurepack.data.Validator
Validator.EmptyValueException, Validator.InvalidValueException -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the maximum value of the rangeGets the minimum value of the rangegetType()booleanChecks if the maximum value is part of the accepted rangebooleanChecks if the minimum value is part of the accepted rangeprotected booleanisValidValue(T value) Internally check the validity of a value.voidsetMaxValue(T maxValue) Sets the maximum value of the range.voidsetMaxValueIncluded(boolean maxValueIncluded) Sets if the maximum value is part of the accepted rangevoidsetMinValue(T minValue) Sets the minimum value of the range.voidsetMinValueIncluded(boolean minValueIncluded) Sets if the minimum value is part of the accepted rangeMethods inherited from class com.vaadin.featurepack.data.validator.AbstractValidator
getErrorMessage, isValid, isValidType, setErrorMessage, validate
-
Constructor Details
-
RangeValidator
Creates a new range validator of the given type.- Parameters:
errorMessage- The error message to use if validation failstype- The type of object the validator can validate.minValue- The minimum value that should be accepted or null for no limitmaxValue- 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
Gets the minimum value of the range- Returns:
- the minimum value
-
setMinValue
Sets the minimum value of the range. UsesetMinValueIncluded(boolean)to control whether this value is part of the range or not.- Parameters:
minValue- the minimum value
-
getMaxValue
Gets the maximum value of the range- Returns:
- the maximum value
-
setMaxValue
Sets the maximum value of the range. UsesetMaxValueIncluded(boolean)to control whether this value is part of the range or not.- Parameters:
maxValue- the maximum value
-
isValidValue
Description copied from class:AbstractValidatorInternally 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 overrideAbstractValidator.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:
isValidValuein classAbstractValidator<T extends Comparable>- Parameters:
value-- Returns:
-
getType
- Specified by:
getTypein classAbstractValidator<T extends Comparable>
-