Class AbstractJavaTimeValidator<C extends Annotation,T extends TemporalAccessor & Comparable<? super T>>
java.lang.Object
org.hibernate.validator.internal.constraintvalidators.bv.time.AbstractJavaTimeValidator<C,T>
- All Implemented Interfaces:
ConstraintValidator<C,
,T> HibernateConstraintValidator<C,
T>
- Direct Known Subclasses:
AbstractFutureJavaTimeValidator
,AbstractFutureOrPresentJavaTimeValidator
,AbstractPastJavaTimeValidator
,AbstractPastOrPresentJavaTimeValidator
public abstract class AbstractJavaTimeValidator<C extends Annotation,T extends TemporalAccessor & Comparable<? super T>>
extends Object
implements HibernateConstraintValidator<C,T>
Base class for all time validators that are based on the
java.time
package.- Author:
- Alaa Nassef, Guillaume Smet
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract Duration
getEffectiveTemporalValidationTolerance
(Duration absoluteTemporalValidationTolerance) Returns the temporal validation tolerance to apply.protected abstract T
getReferenceValue
(Clock reference) Returns an object of the validated type corresponding to the current time reference as provided by theClockProvider
.void
initialize
(ConstraintDescriptor<C> constraintDescriptor, HibernateConstraintValidatorInitializationContext initializationContext) Initializes the validator in preparation forConstraintValidator.isValid(Object, ConstraintValidatorContext)
calls.protected abstract boolean
isValid
(int result) Returns whether the result of the comparison between the validated value and the time reference is considered valid.boolean
isValid
(T value, ConstraintValidatorContext context) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface javax.validation.ConstraintValidator
initialize
-
Field Details
-
referenceClock
-
-
Constructor Details
-
AbstractJavaTimeValidator
public AbstractJavaTimeValidator()
-
-
Method Details
-
initialize
public void initialize(ConstraintDescriptor<C> constraintDescriptor, HibernateConstraintValidatorInitializationContext initializationContext) Description copied from interface:HibernateConstraintValidator
Initializes the validator in preparation forConstraintValidator.isValid(Object, ConstraintValidatorContext)
calls. It is an alternative toConstraintValidator.initialize(Annotation)
method. Should be used if any additional information except annotation is needed to initialize a validator. Note, when usingHibernateConstraintValidator
user should only override one of the methods, eitherHibernateConstraintValidator.initialize(ConstraintDescriptor, HibernateConstraintValidatorInitializationContext)
orConstraintValidator.initialize(Annotation)
. Both methods will be called during initialization, starting withHibernateConstraintValidator.initialize(ConstraintDescriptor, HibernateConstraintValidatorInitializationContext)
.- Specified by:
initialize
in interfaceHibernateConstraintValidator<C extends Annotation,
T extends TemporalAccessor & Comparable<? super T>> - Parameters:
constraintDescriptor
- a constraint descriptor for a given constraint declarationinitializationContext
- an initialization context for a currentConstraintValidatorFactory
-
isValid
- Specified by:
isValid
in interfaceConstraintValidator<C extends Annotation,
T extends TemporalAccessor & Comparable<? super T>>
-
getEffectiveTemporalValidationTolerance
protected abstract Duration getEffectiveTemporalValidationTolerance(Duration absoluteTemporalValidationTolerance) Returns the temporal validation tolerance to apply. -
getReferenceValue
Returns an object of the validated type corresponding to the current time reference as provided by theClockProvider
. -
isValid
protected abstract boolean isValid(int result) Returns whether the result of the comparison between the validated value and the time reference is considered valid.
-