/** Modifies this query to become the current query AND the given item */ // TODO: Make sure this is complete, unit test and make it public private void and(Item item) { if (isEmpty()) { setRoot(item); } else if (getRoot() instanceof NotItem && item instanceof NotItem) { throw new IllegalArgumentException("Can't AND two NOTs"); // TODO: Complete } else if (getRoot() instanceof NotItem){ NotItem notItem = (NotItem)getRoot(); notItem.addPositiveItem(item); } else if (item instanceof NotItem){ NotItem notItem = (NotItem)item; notItem.addPositiveItem(getRoot()); setRoot(notItem); } else { AndItem andItem = new AndItem(); andItem.addItem(getRoot()); andItem.addItem(item); setRoot(andItem); } }
NotItem not = new NotItem(); not.addPositiveItem(rootAsRank.removeItem(0)); not.addNegativeItem(item); if (rootAsRank.getItemCount() == 0) { not.addPositiveItem(root); not.addNegativeItem(item); return not;
private Item addAndFilter(Item root, Item item) { if (item == null) { return root; } if (root instanceof AndItem) { ((AndItem) root).addItem(item); return root; } if (root instanceof RankItem) { Item firstChild = ((RankItem) root).getItem(0); if (firstChild instanceof AndItem) { ((AndItem) firstChild).addItem(item); return root; } else if (firstChild instanceof NotItem) { ((NotItem) firstChild).addPositiveItem(item); return root; } } AndItem and = new AndItem(); and.addItem(root); and.addItem(item); return and; }
if (not == null) { not = new NotItem(); not.addPositiveItem(item); topLevelItem = combineItems(topLevelItem, not); } else { not.addPositiveItem(item); not.addPositiveItem(getItemAsPositiveItem(topLevelItem, not)); return not; } else { // Only negatives - ignore them
NotItem not = new NotItem(); not.addPositiveItem(topLevelItem); return not;