class FilterModeValueValidator implements ServiceAttributeValidator {

    public boolean validate(Set<String> values) {
        boolean valid = true;
        boolean globalFound = false; //can only have zero or one global value

        if (CollectionUtils.isNotEmpty(values)) {
            for (String val : values) {

                if (!valid) {
                    break;
                }

                String trimmed = val.trim();

                Matcher matcher = pattern.matcher(trimmed);
                valid = matcher.matches();

                //now test for duplicate global value
                Matcher globalMatcher = globalPattern.matcher(trimmed);
                boolean globalMatch = globalMatcher.matches();

                //if value matches global and previously found one too
                if (globalFound && globalMatch && valid) {
                    valid = false; //more than one global value so invalid
                } else if (globalMatch && valid) {
                    globalFound = true; //found first global
                }
            }
        } else {
            valid = false;
        }
        
        if (valid) 
            valid = MapDuplicateKeyChecker.checkForNoDuplicateKeyInValue(values);
        return valid;
    }

}