public class

ListIteratorWrapper

extends Object
implements ResettableListIterator
java.lang.Object
   ↳ org.apache.commons.collections.iterators.ListIteratorWrapper

Class Overview

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.

Summary

Public Constructors
ListIteratorWrapper(Iterator iterator)
Constructs a new ListIteratorWrapper that will wrap the given iterator.
Public Methods
void add(Object obj)
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()
void reset()
Resets this iterator back to the position at which the iterator was created.
void set(Object obj)
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.util.Iterator
From interface java.util.ListIterator
From interface org.apache.commons.collections.ResettableIterator
From interface org.apache.commons.collections.ResettableListIterator

Public Constructors

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

Public Methods

public void add (Object obj)

Parameters
obj the object to add, ignored

public boolean hasNext ()

Returns true if there are more elements in the iterator.

Returns
  • true if there are more elements

public boolean hasPrevious ()

Returns true if there are previous elements in the iterator.

Returns
  • true if there are previous elements

public Object next ()

Returns the next element from the iterator.

Returns
  • the next element from the iterator
Throws
NoSuchElementException if there are no more elements

public int nextIndex ()

Returns in the index of the next element.

Returns
  • the index of the next element

public Object previous ()

Returns the the previous element.

Returns
  • the previous element
Throws
NoSuchElementException if there are no previous elements

public int previousIndex ()

Returns the index of the previous element.

Returns
  • the index of the previous element

public void remove ()

public void reset ()

Resets this iterator back to the position at which the iterator was created.

public void set (Object obj)

Parameters
obj the object to set, ignored