예제 #1
0
 private void combineParts(
     MultiMap<Part, ColumnKey> needed,
     MultiMap<ColumnKey, Part> classified,
     List<ExpressionNode> andexprs,
     List<Part> andparts) {
   Part p = needed.keySet().iterator().next();
   Collection<ColumnKey> missing = needed.get(p);
   if (missing == null || missing.isEmpty()) {
     andexprs.add((ExpressionNode) p.getParent());
     needed.remove(p);
     andparts.add(p);
     return;
   }
   ListSet<Part> containingMissing = new ListSet<Part>();
   boolean first = true;
   for (ColumnKey ck : missing) {
     Collection<Part> matching = classified.get(ck);
     if (matching == null || matching.isEmpty()) continue;
     if (first) containingMissing.addAll(matching);
     else {
       containingMissing.retainAll(matching);
     }
   }
   if (containingMissing.isEmpty()) {
     andexprs.add((ExpressionNode) p.getParent());
     andparts.add(p);
     needed.remove(p);
   } else {
     ListSet<Part> toCombine = new ListSet<Part>();
     toCombine.add(p);
     toCombine.addAll(containingMissing);
     ListSet<Part> toRemove = new ListSet<Part>();
     toRemove.addAll(toCombine);
     Part clhs = choosePartForAndCombo(toCombine);
     toCombine.remove(clhs);
     while (!toCombine.isEmpty()) {
       Part crhs = choosePartForAndCombo(toCombine);
       toCombine.remove(crhs);
       clhs = combineParts(clhs, crhs);
     }
     for (Part rp : toRemove) {
       needed.remove(rp);
       ArrayList<ColumnKey> classKeys = new ArrayList<ColumnKey>(classified.keySet());
       for (ColumnKey ck : classKeys) {
         Collection<Part> sub = classified.get(ck);
         if (sub == null || sub.isEmpty()) continue;
         if (sub.contains(rp)) classified.remove(ck, rp);
       }
     }
     andexprs.add((ExpressionNode) clhs.getParent());
     andparts.add(clhs);
   }
 }
예제 #2
0
 protected ListSet<Part> getCompletedParts() {
   if (stopped) return null;
   ListSet<Part> cols = new ListSet<Part>();
   for (Part p : completedParts) {
     if (p instanceof OredParts) cols.add(p);
   }
   completedParts.removeAll(cols);
   for (Part p : cols) {
     for (Part sp : p.getParts()) {
       completedParts.remove(sp);
     }
   }
   completedParts.addAll(cols);
   return completedParts;
 }