private static Patterns processNumericMatchExpression()

in src/main/software/amazon/event/ruler/JsonRuleCompiler.java [719:786]


    private static Patterns processNumericMatchExpression(final JsonParser parser) throws IOException {
        JsonToken token = parser.nextToken();
        if (token != JsonToken.VALUE_STRING) {
            barf(parser, "Invalid member in numeric match: " + parser.getText());
        }
        String operator = parser.getText();
        token = parser.nextToken();
        try {
            if (Constants.EQ.equals(operator)) {
                if (!token.isNumeric()) {
                    barf(parser, "Value of equals must be numeric");
                }
                final String val = parser.getText();
                if (parser.nextToken() != JsonToken.END_ARRAY) {
                    tooManyElements(parser);
                }
                return Patterns.numericEquals(val);
            } else if (Constants.GE.equals(operator)) {
                if (!token.isNumeric()) {
                    barf(parser, "Value of >= must be numeric");
                }
                final String val = parser.getText();
                token = parser.nextToken();
                if (token == JsonToken.END_ARRAY) {
                    return Range.greaterThanOrEqualTo(val);
                }
                return completeNumericRange(parser, token, val, false);

            } else if (Constants.GT.equals(operator)) {
                if (!token.isNumeric()) {
                    barf(parser, "Value of > must be numeric");
                }
                final String val = parser.getText();
                token = parser.nextToken();
                if (token == JsonToken.END_ARRAY) {
                    return Range.greaterThan(val);
                }
                return completeNumericRange(parser, token, val, true);

            } else if (Constants.LE.equals(operator)) {
                if (!token.isNumeric()) {
                    barf(parser, "Value of <= must be numeric");
                }
                final String top = parser.getText();
                if (parser.nextToken() != JsonToken.END_ARRAY) {
                    tooManyElements(parser);
                }
                return Range.lessThanOrEqualTo(top);

            } else if (Constants.LT.equals(operator)) {
                if (!token.isNumeric()) {
                    barf(parser, "Value of < must be numeric");
                }
                final String top = parser.getText();
                if (parser.nextToken() != JsonToken.END_ARRAY) {
                    tooManyElements(parser);
                }
                return Range.lessThan(top);
            } else {
                barf(parser, "Unrecognized numeric range operator: " + operator);
            }
        } catch (IllegalArgumentException e) {
            barf(parser, e.getMessage());
        }

        barf(parser, "Reached a line which is supposed completely unreachable.");
        return null;  // completely unreachable
    }