Class UniqueElementsValidator

java.lang.Object
org.hibernate.validator.internal.constraintvalidators.hv.UniqueElementsValidator
All Implemented Interfaces:
jakarta.validation.ConstraintValidator<UniqueElements,Collection>

public class UniqueElementsValidator extends Object implements jakarta.validation.ConstraintValidator<UniqueElements,Collection>
Validates that the provided collection only contains unique elements, i.e. that we can't find 2 equal elements in the collection.

Uniqueness is defined by the equals() method of the objects being compared.

Author:
Tadhg Pearson, Guillaume Smet
  • Constructor Details

    • UniqueElementsValidator

      public UniqueElementsValidator()
  • Method Details

    • isValid

      public boolean isValid(Collection collection, jakarta.validation.ConstraintValidatorContext constraintValidatorContext)
      Specified by:
      isValid in interface jakarta.validation.ConstraintValidator<UniqueElements,Collection>
      Parameters:
      collection - the collection to validate
      constraintValidatorContext - context in which the constraint is evaluated
      Returns:
      true if the input collection is null or does not contain duplicate elements