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 thejava.timepackage.- Author:
- Alaa Nassef, Guillaume Smet
-
-
Field Summary
Fields Modifier and Type Field Description protected ClockreferenceClock
-
Constructor Summary
Constructors Constructor Description AbstractJavaTimeValidator()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract DurationgetEffectiveTemporalValidationTolerance(Duration absoluteTemporalValidationTolerance)Returns the temporal validation tolerance to apply.protected abstract TgetReferenceValue(Clock reference)Returns an object of the validated type corresponding to the current time reference as provided by theClockProvider.voidinitialize(ConstraintDescriptor<C> constraintDescriptor, HibernateConstraintValidatorInitializationContext initializationContext)Initializes the validator in preparation forConstraintValidator.isValid(Object, ConstraintValidatorContext)calls.protected abstract booleanisValid(int result)Returns whether the result of the comparison between the validated value and the time reference is considered valid.booleanisValid(T value, ConstraintValidatorContext context)Implements the validation logic.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jakarta.validation.ConstraintValidator
initialize
-
-
-
-
Field Detail
-
referenceClock
protected Clock referenceClock
-
-
Method Detail
-
initialize
public void initialize(ConstraintDescriptor<C> constraintDescriptor, HibernateConstraintValidatorInitializationContext initializationContext)
Description copied from interface:HibernateConstraintValidatorInitializes 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 usingHibernateConstraintValidatoruser 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:
initializein 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
public boolean isValid(T value, ConstraintValidatorContext context)
Description copied from interface:ConstraintValidatorImplements the validation logic. The state ofvaluemust not be altered.This method can be accessed concurrently, thread-safety must be ensured by the implementation.
- Specified by:
isValidin interfaceConstraintValidator<C extends Annotation,T extends TemporalAccessor & Comparable<? super T>>- Parameters:
value- object to validatecontext- context in which the constraint is evaluated- Returns:
falseifvaluedoes not pass the constraint
-
getEffectiveTemporalValidationTolerance
protected abstract Duration getEffectiveTemporalValidationTolerance(Duration absoluteTemporalValidationTolerance)
Returns the temporal validation tolerance to apply.
-
getReferenceValue
protected abstract T getReferenceValue(Clock reference)
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.
-
-