in iep-admin/src/main/java/com/netflix/iep/admin/endpoints/SpectatorEndpoint.java [301:398]
static Query parse(String expr) {
Query q, q1, q2;
String k, v;
List<String> vs = null;
String[] parts = expr.split(",");
Deque<Object> stack = new ArrayDeque<>(parts.length);
for (String p : parts) {
String token = p.trim();
if (vs != null && !")".equals(token)) {
vs.add(token);
continue;
}
switch (token) {
case "(":
vs = new ArrayList<>();
break;
case ")":
stack.push(vs);
vs = null;
break;
case ":true":
stack.push(TRUE);
break;
case ":false":
stack.push(FALSE);
break;
case ":and":
q2 = (Query) stack.pop();
q1 = (Query) stack.pop();
stack.push(new AndQuery(q1, q2));
break;
case ":or":
q2 = (Query) stack.pop();
q1 = (Query) stack.pop();
stack.push(new OrQuery(q1, q2));
break;
case ":not":
q = (Query) stack.pop();
stack.push(new NotQuery(q));
break;
case ":has":
k = (String) stack.pop();
stack.push(new HasQuery(k));
break;
case ":eq":
v = (String) stack.pop();
k = (String) stack.pop();
stack.push(new EqualQuery(k, v));
break;
case ":in":
vs = (List<String>) stack.pop();
k = (String) stack.pop();
stack.push(new InQuery(k, new TreeSet<>(vs)));
break;
case ":lt":
v = (String) stack.pop();
k = (String) stack.pop();
stack.push(new LessThanQuery(k, v));
break;
case ":le":
v = (String) stack.pop();
k = (String) stack.pop();
stack.push(new LessThanEqualQuery(k, v));
break;
case ":gt":
v = (String) stack.pop();
k = (String) stack.pop();
stack.push(new GreaterThanQuery(k, v));
break;
case ":ge":
v = (String) stack.pop();
k = (String) stack.pop();
stack.push(new GreaterThanEqualQuery(k, v));
break;
case ":re":
v = (String) stack.pop();
k = (String) stack.pop();
stack.push(new RegexQuery(k, v));
break;
case ":reic":
v = (String) stack.pop();
k = (String) stack.pop();
stack.push(new RegexQuery(k, v, Pattern.CASE_INSENSITIVE, ":reic"));
break;
default:
if (token.startsWith(":")) {
throw new IllegalArgumentException("unknown word '" + token + "'");
}
stack.push(token);
break;
}
}
q = (Query) stack.pop();
if (!stack.isEmpty()) {
throw new IllegalArgumentException("too many items remaining on stack: " + stack);
}
return q;
}