/** * 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); }
/** * Adds a negative item. Like addItem but skips the first position * (position 0) if it is not already set. */ public void addNegativeItem(Item negative) { if (getItemCount() == 0) { insertNullFirstItem(); } addItem(negative); }
/** * Sets the positive item (the first item) * * @return the old positive item, or null if there was no items */ public Item setPositiveItem(Item item) { Validator.ensureNotNull("Positive item of " + this, item); if (getItemCount() == 0) { addItem(item); return null; } else { return setItem(0, item); } }
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; }
@NonNull private CompositeItem buildAnd(OperatorNode<ExpressionOperator> ast) { AndItem andItem = new AndItem(); NotItem notItem = new NotItem(); convertVarArgsAnd(ast, 0, andItem, notItem); Preconditions .checkArgument(andItem.getItemCount() > 0, "Vespa does not support AND with no logically positive branches."); if (notItem.getItemCount() == 0) { return andItem; } if (andItem.getItemCount() == 1) { notItem.setPositiveItem(andItem.getItem(0)); } else { notItem.setPositiveItem(andItem); } return notItem; }
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; }
if (not != null && not.getItemCount() == 1) {