QueryExprConverter { public QueryExpr convert(QueryExpr qe) { if (qe == null) { return null; } else if (qe instanceof QueryExprCompare) { return convertCompExpr((QueryExprCompare) qe); } else if (qe instanceof QueryExprAnd) { return convertAndExpr((QueryExprAnd) qe); } else if (qe instanceof QueryExprOr) { return convertOrExpr((QueryExprOr) qe); } else if (qe instanceof QueryExprNot) { return convertNotExpr((QueryExprNot) qe); } else if (qe instanceof QueryExprInMemCondition) { return convertInMemExpr((QueryExprInMemCondition<?>) qe); } else { return convertUnknownExpr(qe); } }  QueryExpr convert(QueryExpr qe);  }
@Test public void convertExprCombination() { QueryExpr is1 = new QueryExprCompare(A, CompOpEquals.class, 1); QueryExpr is3 = new QueryExprCompare(A, CompOpEquals.class, 3); QueryExpr is1or3 = QueryExprOr.join(is1, is3); QueryExpr isNotNegative = new QueryExprNot(new QueryExprCompare(A, CompOpLt.class, 0)); QueryExpr isOdd = new QueryExprInMemCondition<Integer>() { @Override public boolean eval(Integer item) { return item != null && item % 2 != 0; } @Override public String toString() { return "IS_ODD"; } }; QueryExpr is1or3AndNotNegativeAndOdd = QueryExprAnd.join(is1or3, isNotNegative, isOdd); assertEquals("AND(OR(a = 1, a = 3), NOT(a < 0), IS_ODD)", is1or3AndNotNegativeAndOdd.toString()); QueryExpr converted = new QueryExprConverter().convert(is1or3AndNotNegativeAndOdd); assertEquals("AND(OR(a = 1, a = 3), NOT(a < 0), IS_ODD)", converted.toString()); }
@Test public void convertNull() { assertEquals(null, new QueryExprConverter().convert(null)); }