/** * Returns the positive item (the first subitem), * or null if no positive items has been added */ public Item getPositiveItem() { if (getItemCount() == 0) { return null; } return getItem(0); }
private static Recall optimizeNotItemByRestrict(NotItem item, String restrictParam) { // first item is the positive one if (optimizeByRestrict(item.getItem(0), restrictParam) == Recall.RECALLS_NOTHING) { return Recall.RECALLS_NOTHING; } // all the remaining items are negative ones for (int i = item.getItemCount(); --i >= 1; ) { Item child = item.getItem(i); switch (optimizeByRestrict(child, restrictParam)) { case RECALLS_EVERYTHING: return Recall.RECALLS_NOTHING; case RECALLS_NOTHING: item.removeItem(i); break; } } return Recall.UNKNOWN_RECALL; }
private static CompositeItem extractAndNot(AndItem parent) { NotItem theOnlyNot = null; for (int i = 0; i < parent.getItemCount(); i++) { Item child = parent.getItem(i); if (child instanceof NotItem) { NotItem thisNot = (NotItem) child; parent.setItem(i, thisNot.getPositiveItem()); if (theOnlyNot == null) { theOnlyNot = thisNot; theOnlyNot.setPositiveItem(parent); } else { for (int j=1; j < thisNot.getItemCount(); j++) { theOnlyNot.addNegativeItem(thisNot.getItem(j)); } } } } return (theOnlyNot != null) ? theOnlyNot : parent; }