CqlUtil { public static boolean eval(CQLNode vn1, CQLTermNode tn, Comparator<CQLTermNode> cmp) { if (vn1 instanceof CQLBooleanNode) { CQLBooleanNode n1 = (CQLBooleanNode) vn1; switch (n1.getOperator()) { case AND: case PROX: return eval(n1.getLeftOperand(), tn, cmp) && eval(n1.getRightOperand(), tn, cmp); case OR: return eval(n1.getLeftOperand(), tn, cmp) || eval(n1.getRightOperand(), tn, cmp); case NOT: return eval(n1.getLeftOperand(), tn, cmp); default: throw new IllegalArgumentException("unknown operator for CQLBooleanNode: " + n1.getOperator()); } } else if (vn1 instanceof CQLTermNode) { CQLTermNode n1 = (CQLTermNode) vn1; return cmp.compare(n1, tn) == 0; } else if (vn1 instanceof CQLSortNode) { CQLSortNode n1 = (CQLSortNode) vn1; return eval(n1.getSubtree(), tn, cmp); } else if (vn1 instanceof CQLPrefixNode) { CQLPrefixNode n1 = (CQLPrefixNode) vn1; return eval(n1.getSubtree(), tn, cmp); } else { throw new IllegalArgumentException("unknown type for CQLNode: " + vn1.toString()); } } private  CqlUtil(); static boolean eval(CQLNode vn1, CQLTermNode tn, Comparator<CQLTermNode> cmp); static CQLNode reducer(CQLNode vn1, CQLTermNode tn, Comparator<CQLTermNode> cmp);  }
@Test public void testEval() { assertTrue(eval("a")); assertTrue(eval("a sortby title")); assertTrue(eval(">dc = \"xx\" a sortby title")); assertTrue(eval(">dc = \"xx\" a sortby title")); assertFalse(eval("source=x and x")); assertTrue(eval("source=x or x")); assertTrue(eval("source=kb and x")); assertTrue(eval("(source=kb or source=other) and x")); assertFalse(eval("(source=foo or source=bar) and x")); assertFalse(eval("a and source=x sortby title")); assertTrue(eval("(a and source=x) or (b and source=kb) sortby title")); assertTrue(eval("a not b")); assertTrue(eval("source=kb and a not b")); assertFalse(eval("source=x and a not b")); }