public abstract class AbstractEpochBasedTimeValidator<C extends Annotation,T> extends Object implements HibernateConstraintValidator<C,T>
Modifier and Type | Field and Description |
---|---|
protected Clock |
referenceClock |
Constructor and Description |
---|
AbstractEpochBasedTimeValidator() |
Modifier and Type | Method and Description |
---|---|
protected abstract Duration |
getEffectiveTemporalValidationTolerance(Duration absoluteTemporalValidationTolerance)
Returns the temporal validation tolerance to apply.
|
protected abstract long |
getEpochMillis(T value,
Clock reference)
Returns the millisecond based instant measured from Epoch.
|
void |
initialize(ConstraintDescriptor<C> constraintDescriptor,
HibernateConstraintValidatorInitializationContext initializationContext)
Initializes the validator in preparation for
ConstraintValidator.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)
Implements the validation logic.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
initialize
protected Clock referenceClock
public void initialize(ConstraintDescriptor<C> constraintDescriptor, HibernateConstraintValidatorInitializationContext initializationContext)
HibernateConstraintValidator
ConstraintValidator.isValid(Object, ConstraintValidatorContext)
calls.
It is an alternative to ConstraintValidator.initialize(Annotation)
method. Should be used if any additional information
except annotation is needed to initialize a validator.
Note, when using HibernateConstraintValidator
user should only override one of the methods, either
HibernateConstraintValidator.initialize(ConstraintDescriptor, HibernateConstraintValidatorInitializationContext)
or ConstraintValidator.initialize(Annotation)
.
Both methods will be called during initialization, starting with
HibernateConstraintValidator.initialize(ConstraintDescriptor, HibernateConstraintValidatorInitializationContext)
.initialize
in interface HibernateConstraintValidator<C extends Annotation,T>
constraintDescriptor
- a constraint descriptor for a given constraint declarationinitializationContext
- an initialization context for a current ConstraintValidatorFactory
public boolean isValid(T value, ConstraintValidatorContext context)
ConstraintValidator
value
must not be altered.
This method can be accessed concurrently, thread-safety must be ensured by the implementation.
isValid
in interface ConstraintValidator<C extends Annotation,T>
value
- object to validatecontext
- context in which the constraint is evaluatedfalse
if value
does not pass the constraintprotected abstract Duration getEffectiveTemporalValidationTolerance(Duration absoluteTemporalValidationTolerance)
protected abstract long getEpochMillis(T value, Clock reference)
Clock
provided by the ClockProvider
.protected abstract boolean isValid(int result)
Copyright © 2021 JBoss by Red Hat. All rights reserved.