public void add(Object obj) { checkModCount(); parent.add(nextIndex, obj); current = null; currentIndex = -1; nextIndex++; expectedModCount++; } }
/** * Constructs a new empty list that copies the specified list. * * @param coll the collection to copy * @throws NullPointerException if the collection is null */ public TreeList(Collection coll) { super(); addAll(coll); }
/** * Gets a ListIterator over the list. * * @param fromIndex the index to start from * @return the new iterator */ public ListIterator listIterator(int fromIndex) { // override to go 75% faster // cannot use EmptyIterator as iterator.add() must work checkInterval(fromIndex, 0, size()); return new TreeListIterator(this, fromIndex); }
/** * Removes the element at the specified index. * * @param index the index to remove * @return the previous object at that index */ public Object remove(int index) { modCount++; checkInterval(index, 0, size() - 1); Object result = get(index); root = root.remove(index); size--; return result; }
/** * Gets a ListIterator over the list. * * @return the new iterator */ public ListIterator listIterator() { // override to go 75% faster return listIterator(0); }
public boolean hasNext() { return (nextIndex < parent.size()); }
/** * Searches for the presence of an object in the list. * * @return true if the object is found */ public boolean contains(Object object) { return (indexOf(object) >= 0); }
public void remove() { checkModCount(); if (currentIndex == -1) { throw new IllegalStateException(); } parent.remove(currentIndex); if (nextIndex != currentIndex) { // remove() following next() nextIndex--; } // the AVL node referenced by next may have become stale after a remove // reset it now: will be retrieved by next call to next()/previous() via nextIndex next = null; current = null; currentIndex = -1; expectedModCount++; }
public List makeEmptyList() { return new TreeList(); }
/** * Removes the element at the specified index. * * @param index the index to remove * @return the previous object at that index */ public Object remove(int index) { modCount++; checkInterval(index, 0, size() - 1); Object result = get(index); root = root.remove(index); size--; return result; }
/** * Gets an iterator over the list. * * @return an iterator over the list */ public Iterator iterator() { // override to go 75% faster return listIterator(0); }
public boolean hasNext() { return (nextIndex < parent.size()); }
/** * Searches for the presence of an object in the list. * * @return true if the object is found */ public boolean contains(Object object) { return (indexOf(object) >= 0); }
public void remove() { checkModCount(); if (currentIndex == -1) { throw new IllegalStateException(); } parent.remove(currentIndex); if (nextIndex != currentIndex) { // remove() following next() nextIndex--; } // the AVL node referenced by next may have become stale after a remove // reset it now: will be retrieved by next call to next()/previous() via nextIndex next = null; current = null; currentIndex = -1; expectedModCount++; }
public void testBugCollections447() { final List treeList = new TreeList(); treeList.add("A"); treeList.add("B"); treeList.add("C"); treeList.add("D"); final ListIterator li = treeList.listIterator(); assertEquals("A", li.next()); assertEquals("B", li.next()); assertEquals("B", li.previous()); li.remove(); // Deletes "B" // previous() after remove() should move to // the element before the one just removed assertEquals("A", li.previous()); } }
/** * Gets a ListIterator over the list. * * @param fromIndex the index to start from * @return the new iterator */ public ListIterator listIterator(int fromIndex) { // override to go 75% faster // cannot use EmptyIterator as iterator.add() must work checkInterval(fromIndex, 0, size()); return new TreeListIterator(this, fromIndex); }
/** * Removes the element at the specified index. * * @param index the index to remove * @return the previous object at that index */ public Object remove(int index) { modCount++; checkInterval(index, 0, size() - 1); Object result = get(index); root = root.remove(index); size--; return result; }
/** * Gets an iterator over the list. * * @return an iterator over the list */ public Iterator iterator() { // override to go 75% faster return listIterator(0); }
/** * Checks whether the index is valid. * * @param index the index to check * @param startIndex the first allowed index * @param endIndex the last allowed index * @throws IndexOutOfBoundsException if the index is invalid */ private void checkInterval(int index, int startIndex, int endIndex) { if (index < startIndex || index > endIndex) { throw new IndexOutOfBoundsException("Invalid index:" + index + ", size=" + size()); } }
/** * Searches for the presence of an object in the list. * * @return true if the object is found */ public boolean contains(Object object) { return (indexOf(object) >= 0); }