private static Patterns processAnythingButValuesSetMatchExpression()

in src/main/software/amazon/event/ruler/JsonRuleCompiler.java [600:645]


    private static Patterns processAnythingButValuesSetMatchExpression(JsonParser parser, MatchType matchType)
            throws JsonParseException {
        JsonToken token;
        Set<String> values = new HashSet<>();
        try {
            while ((token = parser.nextToken()) != JsonToken.END_ARRAY) {
                switch (token) {
                    case VALUE_STRING:
                        String text = parser.getText();
                        if ((matchType == MatchType.ANYTHING_BUT_PREFIX || matchType ==  MatchType.ANYTHING_BUT_SUFFIX)
                                && text.isEmpty()) {
                            barf(parser, "Null prefix/suffix not allowed");
                        }
                        values.add(generateValueBasedOnMatchType(text, matchType));
                        break;
                    default:
                        if (matchType == MatchType.ANYTHING_BUT_IGNORE_CASE) {
                            barf(parser, "Inside anything-but/equals-ignore-case list, number|start|null|boolean is not supported.");
                        } else if (matchType == MatchType.ANYTHING_BUT_WILDCARD) {
                            barf(parser, "wildcard match pattern must be a string");
                        } else {
                            barf(parser, "prefix/suffix match pattern must be a string");
                        }
                }
            }
        } catch (IllegalArgumentException | IOException e) {
            barf(parser, e.getMessage());
        }

        switch (matchType) {
            case ANYTHING_BUT_IGNORE_CASE: return Patterns.anythingButIgnoreCaseMatch(values);
            case ANYTHING_BUT_PREFIX: return Patterns.anythingButPrefix(values);
            case ANYTHING_BUT_SUFFIX: return Patterns.anythingButSuffix(values);
            case ANYTHING_BUT_WILDCARD:
                for (String value : values) {
                    try {
                        getParser().parse(MatchType.ANYTHING_BUT_WILDCARD, value);
                    } catch (ParseException e) {
                        barf(parser, e.getLocalizedMessage());
                    }
                }
                return Patterns.anythingButWildcard(values);
            // Not barfing as this is a code bug rather than bad JSON.
            default: throw new IllegalArgumentException("processAnythingButValuesSetMatchExpression received invalid matchType of " + matchType);
        }
    }