A - The constraint annotation type.T - The type to validate.public abstract class BaseValidator<A extends Annotation,T> extends Object implements ConstraintValidator<A,T>
| Modifier | Constructor and Description |
|---|---|
protected |
BaseValidator(Function<A,BiPredicate<T,ClockProvider>> predicateExtractor)
Creates a new validator.
|
| Modifier and Type | Method and Description |
|---|---|
void |
initialize(A constraintAnnotation) |
boolean |
isValid(T value,
ConstraintValidatorContext context) |
protected static Instant |
minus(Instant instant,
TemporalAmount amount)
Subtracts a
TemporalAmount from an Instant. |
protected static <T> BiPredicate<T,T> |
not(BiPredicate<T,T> predicate)
Negates a predicate.
|
protected static Instant |
plus(Instant instant,
TemporalAmount amount)
Adds a
TemporalAmount to an Instant. |
protected void |
useReplacementMessageTemplate(Function<A,String> messageExtractor,
String defaultMessage,
String replacementMessageTemplate)
Specifies that a replacement message template should be used, but only if the default message has not been changed.
|
protected BaseValidator(Function<A,BiPredicate<T,ClockProvider>> predicateExtractor)
predicateExtractor - A function that extracts a predicate from a constraint annotation.
This predicate will be called from isValid(Object, ConstraintValidatorContext),
with as arguments the value to validate and the ClockProvider returned by
ConstraintValidatorContext.getClockProvider().protected final void useReplacementMessageTemplate(Function<A,String> messageExtractor, String defaultMessage, String replacementMessageTemplate)
messageExtractor - A function that extracts the message from a constraint annotation.defaultMessage - The default message.replacementMessageTemplate - The replacement message.public void initialize(A constraintAnnotation)
initialize in interface ConstraintValidator<A extends Annotation,T>public boolean isValid(T value, ConstraintValidatorContext context)
isValid in interface ConstraintValidator<A extends Annotation,T>protected static <T> BiPredicate<T,T> not(BiPredicate<T,T> predicate)
predicate.negate(), and is equivalent to the static method that was
added to Predicate in Java 11.
This method can be used with method references. Example: not(LocalDate::isAfter).
T - The type to test.predicate - The predicate to negate.NullPointerException - If the given predicate is null.protected static Instant plus(Instant instant, TemporalAmount amount)
TemporalAmount to an Instant.
Unlike Instant.plus(TemporalAmount), this method supports not only Duration but also other TemporalAmounts like
Period. If the TemporalAmount is not a Duration, this method first converts the Instant to a
ZonedDateTime using ZoneId.systemDefault(), then adds the TemporalAmount, then converts the ZonedDateTime back
to an Instant.
instant - The Instant to add a TemporalAmount to.amount - The TemporalAmount to add.TemporalAmount to the Instant.protected static Instant minus(Instant instant, TemporalAmount amount)
TemporalAmount from an Instant.
Unlike Instant.minus(TemporalAmount), this method supports not only Duration but also other TemporalAmounts like
Period. If the TemporalAmount is not a Duration, this method first converts the Instant to a
ZonedDateTime using ZoneId.systemDefault(), then subtracts the TemporalAmount, then converts the ZonedDateTime
back to an Instant.
instant - The Instant to subtract a TemporalAmount from.amount - The TemporalAmount to subtract.TemporalAmount from the Instant.Copyright © 2021–2022. All rights reserved.