uk.gov.service.payments.commons.api.validation.MapKeyInsensitiveUniqueValidator Maven / Gradle / Ivy
package uk.gov.service.payments.commons.api.validation;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Map;
public class MapKeyInsensitiveUniqueValidator implements ConstraintValidator> {
@Override
public boolean isValid(Map theMap, ConstraintValidatorContext context) {
if (theMap == null) {
return true;
}
return theMap.keySet()
.stream()
.map(String::toLowerCase)
.distinct()
.count() == theMap.keySet().size();
}
}