/** Removes this item */ public void removeItem(Item item) { item.getParent().removeItem(item); }
/** Always call on every remove */ private void removing(Item item) { if (item == null) { return; } if (item.getParent() == this) { // Otherwise, this belongs to somebody else now (somebody are doing addField, removeField) item.setParent(null); } }
private int findIndexByIdentity(Item item) { int position=0; for (Iterator<Item> i=item.getParent().getItemIterator(); i.hasNext(); ) { Item child=i.next(); if (item==child) { return position; } position++; } return -1; }
/** Removes an item, prefers the one at/close to the given position if there are multiple ones */ public void removeItem(int position,Item item) { Item removeCandidate=item.getParent().getItem(position); if (removeCandidate.equals(item)) // Remove based on position item.getParent().removeItem(position); else item.getParent().removeItem(item); // Otherwise, just removeField any such item }
private void replaceItemByGrams(Item item, Item grams, int indexInParent) { if (!(grams instanceof CompositeItem) || !(item.getParent() instanceof PhraseItem)) { // usually, simply replace item.getParent().setItem(indexInParent, grams); } else { // but if the parent is a phrase, we cannot add the AND to it, so add each gram to the phrase PhraseItem phraseParent = (PhraseItem)item.getParent(); phraseParent.removeItem(indexInParent); int addedTerms = 0; for (Iterator<Item> i = ((CompositeItem)grams).getItemIterator(); i.hasNext(); ) { phraseParent.addItem(indexInParent+(addedTerms++),i.next()); } } }
/** * Removes this item by identity to ensure we remove the right one if there are multiple * equal items */ public void removeItemByIdentity(Item item) { int position=findIndexByIdentity(item); if (position>=0) item.getParent().removeItem(position); else item.getParent().removeItem(item); // Fallback to removeField by equal() }
((Item) current).getParent(), indexName); } else {