public static void collectOr(Expr expr, List<ExprList> list) { if (expr instanceof E_LogicalOr) { E_LogicalOr e = (E_LogicalOr) expr; collectOr(e.getArg1(), list); collectOr(e.getArg2(), list); } else if (expr instanceof E_LogicalAnd) { // List<Expr> ors = new ArrayList<Expr>(); ExprList ors = new ExprList(); collectAnd(expr, ors); list.add(ors); } else { list.add(new ExprList(expr)); } }
/** * This method only words if the input expressions are in DNF, otherwise you will likely get junk * back. * * @param exprs * @return */ public static List<ExprList> dnfToClauses(Iterable<Expr> exprs) { List<ExprList> result = new ArrayList<ExprList>(); for (Expr expr : exprs) { collectOr(expr, result); } return result; }