Package org.dellroad.stuff.validation
Class AbstractValidator<C extends Annotation,T>
java.lang.Object
org.dellroad.stuff.validation.AbstractValidator<C,T>
- All Implemented Interfaces:
jakarta.validation.ConstraintValidator<C,
T>
- Direct Known Subclasses:
PatternValidator
,SelfValidatingValidator
,SortedValidator
,UniqueValidator
public abstract class AbstractValidator<C extends Annotation,T>
extends Object
implements jakarta.validation.ConstraintValidator<C,T>
Support superclass for validators.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
initialize
(C annotation) protected boolean
isCollectionValid
(Collection<? extends T> collection, jakarta.validation.ConstraintValidatorContext context) Apply this constraint to all values in a collection.protected void
setViolation
(jakarta.validation.ConstraintValidatorContext context, String message) Convenience method to add a constraint violation described bymessage
and disable the default violation.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
isValid
-
Field Details
-
annotation
The constraint being checked by this instance.
-
-
Constructor Details
-
AbstractValidator
public AbstractValidator()
-
-
Method Details
-
initialize
- Specified by:
initialize
in interfacejakarta.validation.ConstraintValidator<C extends Annotation,
T>
-
setViolation
Convenience method to add a constraint violation described bymessage
and disable the default violation.- Parameters:
context
- validation contextmessage
- violation message
-
isCollectionValid
protected boolean isCollectionValid(Collection<? extends T> collection, jakarta.validation.ConstraintValidatorContext context) Apply this constraint to all values in a collection. This is a convenience method for validators that want to work with both simple properties and collection properties.- Parameters:
collection
- collection of objects to validatecontext
- validation context- Returns:
- true if all objects are valid
-