org.apache.commons.collections.iterators

## Class ListIteratorWrapper

- java.lang.Object
- - org.apache.commons.collections.iterators.ListIteratorWrapper

- All Implemented Interfaces:
    Iterator, ListIterator, ResettableIterator, ResettableListIterator

      public class ListIteratorWrapper
      extends Object
      implements ResettableListIterator

  Converts an iterator into a list iterator by caching the returned entries.

  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.

  This class implements ResettableListIterator from Commons Collections 3.2.

  Since:
    Commons Collections 2.1
  Version:
    $Revision: 646777 $ $Date: 2008-04-10 14:33:15 +0200 (Thu, 10 Apr 2008) $
  Author:
    Morgan Delagrange, Stephen Colebourne

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ListIteratorWrapper(Iterator iterator)` Constructs a new `ListIteratorWrapper` that will wrap the given iterator.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(Object obj)` Throws `UnsupportedOperationException`.
    `boolean` | `hasNext()` Returns true if there are more elements in the iterator.
    `boolean` | `hasPrevious()` Returns true if there are previous elements in the iterator.
    `Object` | `next()` Returns the next element from the iterator.
    `int` | `nextIndex()` Returns in the index of the next element.
    `Object` | `previous()` Returns the the previous element.
    `int` | `previousIndex()` Returns the index of the previous element.
    `void` | `remove()` Throws `UnsupportedOperationException`.
    `void` | `reset()` Resets this iterator back to the position at which the iterator was created.
    `void` | `set(Object obj)` Throws `UnsupportedOperationException`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ListIteratorWrapper

          public ListIteratorWrapper(Iterator 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 Detail

    - #### add

          public void add(Object obj)
                   throws UnsupportedOperationException

      Throws `UnsupportedOperationException`.
      Specified by:
        `add` in interface `ListIterator`
      Parameters:
        `obj` - the object to add, ignored
      Throws:
        `UnsupportedOperationException` - always

    - #### hasNext

          public boolean hasNext()

      Returns true if there are more elements in the iterator.
      Specified by:
        `hasNext` in interface `Iterator`
      Specified by:
        `hasNext` in interface `ListIterator`
      Returns:
        true if there are more elements

    - #### hasPrevious

          public boolean hasPrevious()

      Returns true if there are previous elements in the iterator.
      Specified by:
        `hasPrevious` in interface `ListIterator`
      Returns:
        true if there are previous elements

    - #### next

          public Object next()
                      throws NoSuchElementException

      Returns the next element from the iterator.
      Specified by:
        `next` in interface `Iterator`
      Specified by:
        `next` in interface `ListIterator`
      Returns:
        the next element from the iterator
      Throws:
        `NoSuchElementException` - if there are no more elements

    - #### nextIndex

          public int nextIndex()

      Returns in the index of the next element.
      Specified by:
        `nextIndex` in interface `ListIterator`
      Returns:
        the index of the next element

    - #### previous

          public Object previous()
                          throws NoSuchElementException

      Returns the the previous element.
      Specified by:
        `previous` in interface `ListIterator`
      Returns:
        the previous element
      Throws:
        `NoSuchElementException` - if there are no previous elements

    - #### previousIndex

          public int previousIndex()

      Returns the index of the previous element.
      Specified by:
        `previousIndex` in interface `ListIterator`
      Returns:
        the index of the previous element

    - #### remove

          public void remove()
                      throws UnsupportedOperationException

      Throws `UnsupportedOperationException`.
      Specified by:
        `remove` in interface `Iterator`
      Specified by:
        `remove` in interface `ListIterator`
      Throws:
        `UnsupportedOperationException` - always

    - #### set

          public void set(Object obj)
                   throws UnsupportedOperationException

      Throws `UnsupportedOperationException`.
      Specified by:
        `set` in interface `ListIterator`
      Parameters:
        `obj` - the object to set, ignored
      Throws:
        `UnsupportedOperationException` - always

    - #### reset

          public void reset()

      Resets this iterator back to the position at which the iterator was created.
      Specified by:
        `reset` in interface `ResettableIterator`
      Specified by:
        `reset` in interface `ResettableListIterator`
      Since:
        Commons Collections 3.2

Copyright © 2001–2015 The Apache Software Foundation. All rights reserved.