public static int indexOf(ExprNodeDesc origin, List<ExprNodeDesc> sources) { for (int i = 0; i < sources.size(); i++) { if (origin.isSame(sources.get(i))) { return i; } } return -1; }
/** return true if predicate is already included in source */ public static boolean containsPredicate(ExprNodeDesc source, ExprNodeDesc predicate) { if (source.isSame(predicate)) { return true; } if (FunctionRegistry.isOpAnd(source)) { if (containsPredicate(source.getChildren().get(0), predicate) || containsPredicate(source.getChildren().get(1), predicate)) { return true; } } return false; }
// backtrack key exprs of child to parent and compare it with parent's protected Integer sameKeys( List<ExprNodeDesc> cexprs, List<ExprNodeDesc> pexprs, Operator<?> child, Operator<?> parent) throws SemanticException { int common = Math.min(cexprs.size(), pexprs.size()); int limit = Math.max(cexprs.size(), pexprs.size()); int i = 0; for (; i < common; i++) { ExprNodeDesc pexpr = pexprs.get(i); ExprNodeDesc cexpr = ExprNodeDescUtils.backtrack(cexprs.get(i), child, parent); if (cexpr == null || !pexpr.isSame(cexpr)) { return null; } } for (; i < limit; i++) { if (cexprs.size() > pexprs.size()) { if (ExprNodeDescUtils.backtrack(cexprs.get(i), child, parent) == null) { // cKey is not present in parent return null; } } } return Integer.valueOf(cexprs.size()).compareTo(pexprs.size()); }