public void add(Item o) { Item newItem = o; owner.adding(newItem); // TODO: Change current here? Check javadoc wrapped.add(o); }
public void addItem(Item item) { adding(item); subitems.add(item); }
/** * Inserts the item at a position and increases the index of existing items * starting on this position by one * * @throws IndexOutOfBoundsException if the index is out of range */ public void addItem(int index, Item item) { if (index > subitems.size() || index < 0) { throw new IndexOutOfBoundsException("Could not add a subitem at position " + index + " to " + this); } adding(item); subitems.add(index, item); }
public void set(Item o) { Item newItem = o; owner.removing(current); owner.adding(newItem); current = newItem; wrapped.set(newItem); }
/** * Replaces the item at the given index * * @param index the (0-base) index of the item to replace * @param item the new item * @return the old item at this position. The parent of the old item is <i>not</i> cleared * @throws IndexOutOfBoundsException if there is no item at this index */ public Item setItem(int index, Item item) { if (index >= subitems.size() || index < 0) throw new IndexOutOfBoundsException("Could not add a subitem at position " + index + " to " + this); adding(item); Item old = subitems.set(index, item); if (old!=item) removing(old); return old; }
/** Returns a deep copy of this item */ public CompositeItem clone() { CompositeItem copy = (CompositeItem) super.clone(); copy.subitems = new java.util.ArrayList<>(); for (Item subItem : subitems) { Item subItemCopy = subItem.clone(); copy.adding(subItemCopy); copy.subitems.add(subItemCopy); } fixConnexity(copy); return copy; }