Class AbstractComparableRangeValidator<V extends Comparable<V>>
- Type Parameters:
V
- The value type this validator supports.
- All Implemented Interfaces:
com.globalmentor.beans.PropertyBindable
,com.globalmentor.beans.PropertyConstrainable
,RangeValidator<V>
,Validator<V>
- Direct Known Subclasses:
DateRangeValidator
,DecimalRangeValidator
,IntegerRangeValidator
,LongRangeValidator
- Author:
- Garret Wilson
- See Also:
-
Field Summary
Fields inherited from class com.globalmentor.beans.BoundPropertyObject
NO_PROPERTY_CHANGE_LISTENERS, NO_VETOABLE_CHANGE_LISTENERS
Fields inherited from interface io.guise.framework.validator.Validator
INVALID_VALUE_MESSAGE_PROPERTY, VALUE_REQUIRED_MESSAGE_PROPERTY, VALUE_REQUIRED_PROPERTY
-
Constructor Summary
ConstructorDescriptionAbstractComparableRangeValidator
(V minimum, V maximum, V step, boolean valueRequired) Minimum, maximum, step, and value required constructor. -
Method Summary
Methods inherited from class io.guise.framework.validator.AbstractRangeValidator
getMaximum, getMinimum, getStep
Methods inherited from class io.guise.framework.validator.AbstractValidator
getInvalidValueMessage, getValueRequiredMessage, isValid, isValueRequired, setInvalidValueMessage, setValueRequired, setValueRequiredMessage, throwInvalidValueValidationException, throwValueRequiredValidationException, toString
Methods inherited from class io.guise.framework.event.GuiseBoundPropertyObject
getSession
Methods inherited from class com.globalmentor.beans.BoundPropertyObject
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, createPostponedPropertyChangeEvent, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getForwardPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getRepeatPropertyChangeListener, getRepeatVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, getVetoableChangeSupport, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.globalmentor.beans.PropertyBindable
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, hasPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
Methods inherited from interface io.guise.framework.validator.Validator
getInvalidValueMessage, getSession, getValueRequiredMessage, isValid, setInvalidValueMessage, setValueRequiredMessage
-
Constructor Details
-
AbstractComparableRangeValidator
Minimum, maximum, step, and value required constructor.- Parameters:
minimum
- The minimum value, inclusive, ornull
if the range has no lower bound.maximum
- The maximum value, inclusive, ornull
if the range has no upper bound.step
- The step amount, ornull
if the range has no increment value specified.valueRequired
- Whether the value must be non-null
in order to be considered valid.
-
-
Method Details
-
validate
Checks whether a given value is valid, and throws an exception if not.The message of the thrown exception should be appropriate for display to the user, although it may include string resource references. If a child class has no specific message to return, that class may call
AbstractValidator.throwInvalidValueValidationException(Object)
as a convenience. A child class may also callAbstractValidator.throwValueRequiredValidationException(Object)
as a convenience, but this is usually not required if this version of the method, which provides a missing value check, is called first.This version checks whether a value is provided if values are required. Child classes should call this version as a convenience for checking non-
null
and required status.Adding new validation logic always requires overriding this method. Although
Validator.isValid(Object)
may be overridden to provide optimized fast-fail determinations, adding new logic toValidator.isValid(Object)
cannot be used in place of overriding this method.This version checks whether a value is provided if values are required. Child classes should call this version as a convenience for checking non-
null
and required status.Adding new validation logic always requires overriding this method. Although
AbstractValidator.isValid(Object)
may be overridden to provide optimized fast-fail determinations, adding new logic toAbstractValidator.isValid(Object)
cannot be used in place of overriding this method.This version checks for minimum and maximum compliance, and delegates to
isValidStep(Comparable, Comparable, Comparable)
for checking step compliance. Child classes will normally not override this class and instead merely implementisValidStep(Comparable, Comparable, Comparable)
.- Specified by:
validate
in interfaceValidator<V extends Comparable<V>>
- Overrides:
validate
in classAbstractValidator<V extends Comparable<V>>
- Parameters:
value
- The value to validate, which may benull
.- Throws:
ValidationException
- if the provided value is not valid.- See Also:
-
isValidStep
Determines whether the given value falls on the correct step amount relative to the base value.- Parameters:
value
- The value to validate.step
- The step value.base
- The base (either the minimum or maximum value), ornull
if zero should be used as a base.- Returns:
true
if the value is a valid step away from the given base.
-