Class UniqueElementsValidator

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

public class UniqueElementsValidator extends Object implements 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, ConstraintValidatorContext constraintValidatorContext)
      Description copied from interface: ConstraintValidator
      Implements the validation logic. The state of value must not be altered.

      This method can be accessed concurrently, thread-safety must be ensured by the implementation.

      Specified by:
      isValid in interface 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