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

    Fields
    Modifier and Type
    Field
    Description
    protected C
    The constraint being checked by this instance.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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 by message 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

      protected C extends Annotation annotation
      The constraint being checked by this instance.
  • Constructor Details

    • AbstractValidator

      public AbstractValidator()
  • Method Details

    • initialize

      public void initialize(C annotation)
      Specified by:
      initialize in interface jakarta.validation.ConstraintValidator<C extends Annotation,T>
    • setViolation

      protected void setViolation(jakarta.validation.ConstraintValidatorContext context, String message)
      Convenience method to add a constraint violation described by message and disable the default violation.
      Parameters:
      context - validation context
      message - 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 validate
      context - validation context
      Returns:
      true if all objects are valid