org.apache.commons.collections.iterators

Class ListIteratorWrapper

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: 405925 $ $Date: 2006-05-12 23:52:43 +0100 (Fri, 12 May 2006) $

Author: Morgan Delagrange Stephen Colebourne

Constructor Summary
ListIteratorWrapper(Iterator iterator)
Constructs a new ListIteratorWrapper that will wrap the given iterator.
Method Summary
voidadd(Object obj)
Throws UnsupportedOperationException.
booleanhasNext()
Returns true if there are more elements in the iterator.
booleanhasPrevious()
Returns true if there are previous elements in the iterator.
Objectnext()
Returns the next element from the iterator.
intnextIndex()
Returns in the index of the next element.
Objectprevious()
Returns the the previous element.
intpreviousIndex()
Returns the index of the previous element.
voidremove()
Throws UnsupportedOperationException.
voidreset()
Resets this iterator back to the position at which the iterator was created.
voidset(Object obj)
Throws UnsupportedOperationException.

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.

Parameters: obj the object to add, ignored

Throws: UnsupportedOperationException always

hasNext

public boolean hasNext()
Returns true if there are more elements in the iterator.

Returns: true if there are more elements

hasPrevious

public boolean hasPrevious()
Returns true if there are previous elements in the iterator.

Returns: true if there are previous elements

next

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

nextIndex

public int nextIndex()
Returns in the index of the next element.

Returns: the index of the next element

previous

public Object previous()
Returns the the previous element.

Returns: the previous element

Throws: NoSuchElementException if there are no previous elements

previousIndex

public int previousIndex()
Returns the index of the previous element.

Returns: the index of the previous element

remove

public void remove()
Throws UnsupportedOperationException.

Throws: UnsupportedOperationException always

reset

public void reset()
Resets this iterator back to the position at which the iterator was created.

Since: Commons Collections 3.2

set

public void set(Object obj)
Throws UnsupportedOperationException.

Parameters: obj the object to set, ignored

Throws: UnsupportedOperationException always

Copyright © 2001-2008 Apache Software Foundation. All Rights Reserved.