Package com.vaadin.data.validator
Class RangeValidator<T extends Comparable>
- java.lang.Object
-
- com.vaadin.data.validator.AbstractValidator<T>
-
- com.vaadin.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
,ByteRangeValidator
,DateRangeValidator
,DoubleRangeValidator
,FloatRangeValidator
,IntegerRangeValidator
,LongRangeValidator
,ShortRangeValidator
public class RangeValidator<T extends Comparable> extends AbstractValidator<T>
An base implementation for validating any objects that implementComparable
. 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 likeIntegerRangeValidator
,DoubleRangeValidator
orDateRangeValidator
in applications.Note that
RangeValidator
always accept null values. Make a field required to ensure that no empty values are accepted or overrideisValidValue(Comparable)
.- Since:
- 7.0
- Author:
- Vaadin Ltd.
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.vaadin.data.Validator
Validator.EmptyValueException, Validator.InvalidValueException
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
getMaxValue()
Gets the maximum value of the rangeT
getMinValue()
Gets the minimum value of the rangeClass<T>
getType()
boolean
isMaxValueIncluded()
Checks if the maximum value is part of the accepted rangeboolean
isMinValueIncluded()
Checks if the minimum value is part of the accepted rangeprotected boolean
isValidValue(T value)
Internally check the validity of a value.void
setMaxValue(T maxValue)
Sets the maximum value of the range.void
setMaxValueIncluded(boolean maxValueIncluded)
Sets if the maximum value is part of the accepted rangevoid
setMinValue(T minValue)
Sets the minimum value of the range.void
setMinValueIncluded(boolean minValueIncluded)
Sets if the minimum value is part of the accepted range-
Methods inherited from class com.vaadin.data.validator.AbstractValidator
getErrorMessage, isValid, isValidType, setErrorMessage, validate
-
-
-
-
Constructor Detail
-
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 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 Detail
-
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. UsesetMinValueIncluded(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. UsesetMaxValueIncluded(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 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:
isValidValue
in classAbstractValidator<T extends Comparable>
- Returns:
-
getType
public Class<T> getType()
- Specified by:
getType
in classAbstractValidator<T extends Comparable>
-
-