All Downloads are FREE. Search and download functionalities are using the official Maven repository.

uk.gov.service.payments.commons.api.validation.MapKeyLengthValidator Maven / Gradle / Ivy

There is a newer version: 1.0.20241216100655
Show newest version
package uk.gov.service.payments.commons.api.validation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Map;

public class MapKeyLengthValidator implements ConstraintValidator> {

    private int max;
    private int min;

    @Override
    public void initialize(MapKeyLength constraintAnnotation) {
        max = constraintAnnotation.max();
        min = constraintAnnotation.min();
    }

    @Override
    public boolean isValid(Map theMap, ConstraintValidatorContext context) {
        if (theMap == null) {
            return true;
        }

        return theMap.keySet().stream()
                .noneMatch(key -> key.length() < min || key.length() > max);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy