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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanisValid(Collection collection, ConstraintValidatorContext constraintValidatorContext) Implements the validation logic.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jakarta.validation.ConstraintValidator
initialize
-
Constructor Details
-
UniqueElementsValidator
public UniqueElementsValidator()
-
-
Method Details
-
isValid
public boolean isValid(Collection collection, ConstraintValidatorContext constraintValidatorContext) Description copied from interface:ConstraintValidatorImplements the validation logic. The state ofvaluemust not be altered.This method can be accessed concurrently, thread-safety must be ensured by the implementation.
- Specified by:
isValidin interfaceConstraintValidator<UniqueElements,Collection> - Parameters:
collection- the collection to validateconstraintValidatorContext- context in which the constraint is evaluated- Returns:
- true if the input collection is null or does not contain duplicate elements
-