Class ListIteratorWrapper<E>

java.lang.Object
org.apache.commons.collections4.iterators.ListIteratorWrapper<E>
Type Parameters:
E - the type of elements in this iterator.
All Implemented Interfaces:
Iterator<E>, ListIterator<E>, OrderedIterator<E>, ResettableIterator<E>, ResettableListIterator<E>

public class ListIteratorWrapper<E> extends Object implements ResettableListIterator<E>
Converts an Iterator into a ResettableListIterator. For plain Iterators this is accomplished by caching the returned elements. This class can also be used to simply add ResettableIterator functionality to a given ListIterator.

The ListIterator interface has additional useful methods for navigation - previous() and the index methods. This class allows a regular Iterator to behave as a ListIterator. It achieves this by building a list internally of as the underlying iterator is traversed.

The optional operations of ListIterator are not supported for plain Iterators.

This class implements ResettableListIterator from Commons Collections 3.2.

Since:
2.1
  • Field Details

    • UNSUPPORTED_OPERATION_MESSAGE

      private static final String UNSUPPORTED_OPERATION_MESSAGE
      Message used when set or add are called.
      See Also:
    • CANNOT_REMOVE_MESSAGE

      private static final String CANNOT_REMOVE_MESSAGE
      Message used when set or add are called.
      See Also:
    • iterator

      private final Iterator<? extends E> iterator
      The underlying iterator being decorated.
    • list

      private final List<E> list
      The list being used to cache the iterator.
    • currentIndex

      private int currentIndex
      The current index of this iterator.
    • wrappedIteratorIndex

      private int wrappedIteratorIndex
      The current index of the wrapped iterator.
    • removeState

      private boolean removeState
      Recall whether the wrapped iterator's "cursor" is in such a state as to allow remove() to be called
  • Constructor Details

    • ListIteratorWrapper

      public ListIteratorWrapper(Iterator<? extends E> iterator)
      Constructs a new ListIteratorWrapper that will wrap the given iterator.
      Parameters:
      iterator - the iterator to wrap
      Throws:
      NullPointerException - if the iterator is null
  • Method Details