org.apache.commons.collections.iterators

Class ListIteratorWrapper

Implemented Interfaces:
Iterator, ListIterator, ResettableIterator, ResettableListIterator

public class ListIteratorWrapper
extends java.lang.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.

Version:
$Revision: 405925 $ $Date: 2006-05-12 23:52:43 +0100 (Fri, 12 May 2006) $
Authors:
Morgan Delagrange
Stephen Colebourne
Since:
Commons Collections 2.1

Constructor Summary

ListIteratorWrapper(Iterator iterator)
Constructs a new ListIteratorWrapper that will wrap the given iterator.

Method Summary

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.

Constructor Details

ListIteratorWrapper

public ListIteratorWrapper(Iterator iterator)
Constructs a new ListIteratorWrapper that will wrap the given iterator.
Parameters:
iterator - the iterator to wrap

Method Details

add

public void add(Object obj)
            throws UnsupportedOperationException
Throws UnsupportedOperationException.
Parameters:
obj - the object to add, ignored

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()
            throws NoSuchElementException
Returns the next element from the iterator.
Returns:
the next element from the iterator

nextIndex

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

previous

public Object previous()
            throws NoSuchElementException
Returns the the previous element.
Returns:
the previous element

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.

reset

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

set

public void set(Object obj)
            throws UnsupportedOperationException
Throws UnsupportedOperationException.
Parameters:
obj - the object to set, ignored

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