/** * Check and add the <code>Content</code> to this list at the given index. * Inserts the specified object at the specified position in this list. * Shifts the object currently at that position (if any) and any subsequent * objects to the right (adds one to their indices). * * @param index * index where to add <code>Element</code> * @param child * <code>Content</code> to add */ @Override public void add(final int index, final Content child) { // Confirm basic sanity of child. checkPreConditions(child, index, false); // Check to see whether this parent believes it can contain this content parent.canContainContent(child, index, false); child.setParent(parent); ensureCapacity(size + 1); if (index == size) { elementData[size++] = child; } else { System.arraycopy(elementData, index, elementData, index + 1, size - index); elementData[index] = child; size++; } // Successful add's increment the AbstractList's modCount incModCount(); }
/** * Set the object at the specified location to the supplied object. * * @param index * The location to set the value to. * @param child * The location to set the value to. * @return The object which was replaced. throws IndexOutOfBoundsException * if index < 0 || index >= size() */ @Override public Content set(final int index, final Content child) { // Confirm basic sanity of child. checkPreConditions(child, index, true); // Ensure the detail checks out OK too. parent.canContainContent(child, index, true); /* * Do a special case of set() where we don't do a remove() then add() * because that affects the modCount. We want to do a true set(). See * issue #15 */ final Content old = elementData[index]; removeParent(old); child.setParent(parent); elementData[index] = child; // for set method we increment dataModCount, but not modCount // set does not change the structure of the List (size()) incDataModOnly(); return old; }