SimpleConstraintParser { public SimpleConstraintParser.SimpleConstraintElements parse(String constraint) { SimpleConstraintParser.SimpleConstraintElements result; Matcher m = re.matcher(constraint); try { if (m.matches()) { Operator op = Operator.valueOf(m.group(2)); String right = getRightOperandGroup(m); result = new SimpleConstraintParser.SimpleConstraintElements( m.group(1), op, right); return result; } } catch (Exception e) { } throw new IllegalArgumentException("[" + constraint + "] is not a valid constraint"); }  SimpleConstraintParser.SimpleConstraintElements parse(String constraint);  }
@Test public void testParseWithExtendedNamesShouldPass() { SimpleConstraintParser parser = new SimpleConstraintParser(); check(parser.parse("analytics_time LT 1"), "analytics_time", Operator.LT, "1"); check(parser.parse("nuro.analytics LT 1"), "nuro.analytics", Operator.LT, "1"); check(parser.parse("nuro.analytics_time LT 1"), "nuro.analytics_time", Operator.LT, "1"); check(parser.parse("a.b.c LT 1"), "a.b.c", Operator.LT, "1"); }
@Test public void testParse() { SimpleConstraintParser parser = new SimpleConstraintParser(); check(parser.parse("m1 GT 1"), "m1", Operator.GT, "1"); check(parser.parse("m1 GT (1)"), "m1", Operator.GT, "1"); check(parser.parse("m2 GE 2"), "m2", Operator.GE, "2"); check(parser.parse("m2 GE (2)"), "m2", Operator.GE, "2"); check(parser.parse("m3 EQ 3"), "m3", Operator.EQ, "3"); check(parser.parse("m3 EQ (3)"), "m3", Operator.EQ, "3"); check(parser.parse("m4 LT 4"), "m4", Operator.LT, "4"); check(parser.parse("m4 LT (4)"), "m4", Operator.LT, "4"); check(parser.parse("m5 LE 5"), "m5", Operator.LE, "5"); check(parser.parse("m5 LE (5)"), "m5", Operator.LE, "5"); check(parser.parse("m6 NE 6"), "m6", Operator.NE, "6"); check(parser.parse("m6 NE (6)"), "m6", Operator.NE, "6"); check(parser.parse("latency LT 0.5"), "latency", Operator.LT, "0.5"); check(parser.parse("latency LT (0.5)"), "latency", Operator.LT, "0.5"); check(parser.parse("val IN 1"), "val", Operator.IN, "1"); check(parser.parse("val IN (1)"), "val", Operator.IN, "1"); check(parser.parse("val IN (1,2)"), "val", Operator.IN, "1,2"); check(parser.parse("val IN (1,2,3)"), "val", Operator.IN, "1,2,3"); check(parser.parse("val BETWEEN (1,2)"), "val", Operator.BETWEEN, "1,2"); check(parser.parse("val EXISTS"), "val", Operator.EXISTS, ""); check(parser.parse("val NOT_EXISTS"), "val", Operator.NOT_EXISTS, ""); check(parser.parse("val BETWEEN 1,2"), "val", Operator.BETWEEN, "1,2"); check(parser.parse("val BETWEEN 1,2 "), "val", Operator.BETWEEN, "1,2"); check(parser.parse("val BETWEEN 1 ,2"), "val", Operator.BETWEEN, "1,2"); check(parser.parse("val BETWEEN 1, 2"), "val", Operator.BETWEEN, "1,2"); check(parser.parse("val IN 1 , 2 , 3 "), "val", Operator.IN, "1,2,3"); check(parser.parse("val EXISTS "), "val", Operator.EXISTS, ""); check(parser.parse("val NOT_EXISTS "), "val", Operator.NOT_EXISTS, ""); }