Top Description Constructors Methods
org.hibernate.validator.internal.constraintvalidators.hv

public Class UniqueElementsValidator

extends Object
implements ConstraintValidator<UniqueElements, Collection<E>>
Class Inheritance
All Implemented Interfaces
jakarta.validation.ConstraintValidator
Annotations
@SuppressWarnings:rawtypes
Static Imports
java.util.stream.Collectors.toList

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.

Authors
Tadhg Pearson, Guillaume Smet

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private List<Object>
findDuplicates(Collection<?> collection)

public boolean

Returns:

true if the input collection is null or does not contain duplicate elements
isValid
(Collection<E>
the collection to validate
collection
,
ConstraintValidatorContext
context in which the constraint is evaluated
constraintValidatorContext
)

Implements jakarta.validation.ConstraintValidator.isValid.

Implements the validation logic.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

UniqueElementsValidatorback to summary
public UniqueElementsValidator()

Method Detail

findDuplicatesback to summary
private List<Object> findDuplicates(Collection<?> collection)
isValidback to summary
public boolean isValid(Collection<E> collection, ConstraintValidatorContext constraintValidatorContext)

Implements jakarta.validation.ConstraintValidator.isValid.

Doc from jakarta.validation.ConstraintValidator.isValid.

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.

Parameters
collection:Collection<E>

the collection to validate

constraintValidatorContext:ConstraintValidatorContext

context in which the constraint is evaluated

Returns:boolean

true if the input collection is null or does not contain duplicate elements

Annotations
@Override