Class AbstractIndexedListIterator<E>

All Implemented Interfaces:
Iterator<E>, ListIterator<E>
Direct Known Subclasses:
Iterators.ArrayItr

abstract class AbstractIndexedListIterator<E> extends UnmodifiableListIterator<E>
This class provides a skeletal implementation of the ListIterator interface across a fixed number of elements that may be retrieved by position. It does not support UnmodifiableIterator.remove(), UnmodifiableListIterator.set(E), or UnmodifiableListIterator.add(E).
  • Field Details

    • size

      private final int size
    • position

      private int position
  • Constructor Details

    • AbstractIndexedListIterator

      protected AbstractIndexedListIterator(int size)
      Constructs an iterator across a sequence of the given size whose initial position is 0. That is, the first call to next() will return the first element (or throw NoSuchElementException if size is zero).
      Throws:
      IllegalArgumentException - if size is negative
    • AbstractIndexedListIterator

      protected AbstractIndexedListIterator(int size, int position)
      Constructs an iterator across a sequence of the given size with the given initial position. That is, the first call to nextIndex() will return position, and the first call to next() will return the element at that index, if available. Calls to previous() can retrieve the preceding position elements.
      Throws:
      IndexOutOfBoundsException - if position is negative or is greater than size
      IllegalArgumentException - if size is negative
  • Method Details

    • get

      protected abstract E get(int index)
      Returns the element with the specified index. This method is called by next().
    • hasNext

      public final boolean hasNext()
    • next

      public final E next()
    • nextIndex

      public final int nextIndex()
    • hasPrevious

      public final boolean hasPrevious()
    • previous

      public final E previous()
    • previousIndex

      public final int previousIndex()