@Override public E previous() { checkModCount(); if (!hasPrevious()) { throw new NoSuchElementException("Already at start of list."); } next = next.previous; final E value = next.getValue(); current = next; nextIndex--; return value; }
@Override public E next() { checkModCount(); if (!hasNext()) { throw new NoSuchElementException("No element at index " + nextIndex + "."); } final E value = next.getValue(); current = next; next = next.next; nextIndex++; return value; }
@Override public void remove() { checkModCount(); if (current == next) { // remove() following previous() next = next.next; parent.removeNode(getLastNodeReturned()); } else { // remove() following next() parent.removeNode(getLastNodeReturned()); nextIndex--; } current = null; expectedModCount++; }
@Override public int nextIndex() { return super.nextIndex() - sub.offset; }
@Override public ListIterator<E> listIterator(final int fromIndex) { return new LinkedListIterator<>(this, fromIndex); }
@Override public ListIterator<E> listIterator() { return new LinkedListIterator<>(this, 0); }
/** * Adds an object to the list. * The object added here will be the new 'previous' in the iterator. * * @param obj the object to add */ @Override public void add(final E obj) { // overridden, as the nodeInserted() method updates the iterator state super.add(obj); // matches the (next.previous == node) clause in nodeInserted() // thus next gets changed - reset it again here next = next.next; }
@Override public int previousIndex() { // not normally overridden, as relative to nextIndex() return nextIndex() - 1; }
@Override public void remove() { super.remove(); sub.expectedModCount = parent.modCount; sub.size--; } }
@Override public void add(final E obj) { checkModCount(); parent.addNodeBefore(next, obj); current = null; nextIndex++; expectedModCount++; }
@Override public void set(final E obj) { checkModCount(); getLastNodeReturned().setValue(obj); }
@Override public void add(final E obj) { super.add(obj); sub.expectedModCount = parent.modCount; sub.size++; }