com.vaadin.data.validator
Class RangeValidator<T extends Comparable>

java.lang.Object
  extended by com.vaadin.data.validator.AbstractValidator<T>
      extended by 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:
DateRangeValidator, DoubleRangeValidator, IntegerRangeValidator

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).

Since:
7.0
Version:
7.0.0.alpha3
Author:
Vaadin Ltd.
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.vaadin.data.Validator
Validator.EmptyValueException, Validator.InvalidValueException
 
Constructor Summary
RangeValidator(String errorMessage, Class<T> type, T minValue, T maxValue)
          Creates a new range validator of the given type.
 
Method Summary
 T getMaxValue()
          Gets the maximum value of the range
 T getMinValue()
          Gets the minimum value of the range
 Class<T> getType()
           
 boolean isMaxValueIncluded()
          Checks if the maximum value is part of the accepted range
 boolean isMinValueIncluded()
          Checks if the minimum value is part of the accepted range
protected  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 range
 void 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 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 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. 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>
Returns:

getType

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


Copyright © 2000-2011 Vaadin Ltd. All Rights Reserved.