Class ListIteratorWrapper
java.lang.Object
org.apache.commons.collections.iterators.ListIteratorWrapper
- All Implemented Interfaces:
Iterator,ListIterator,ResettableIterator,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) $
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intThe current index of this iterator.private final IteratorThe underlying iterator being decorated.private final ListThe list being used to cache the iterator.private static final StringMessage used when remove, set or add are called.private intThe current index of the wrapped iterator. -
Constructor Summary
ConstructorsConstructorDescriptionListIteratorWrapper(Iterator iterator) Constructs a newListIteratorWrapperthat will wrap the given iterator. -
Method Summary
Modifier and TypeMethodDescriptionvoidThrowsUnsupportedOperationException.booleanhasNext()Returns true if there are more elements in the iterator.booleanReturns true if there are previous elements in the iterator.next()Returns the next element from the iterator.intReturns in the index of the next element.previous()Returns the the previous element.intReturns the index of the previous element.voidremove()ThrowsUnsupportedOperationException.voidreset()Resets this iterator back to the position at which the iterator was created.voidThrowsUnsupportedOperationException.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining
-
Field Details
-
UNSUPPORTED_OPERATION_MESSAGE
Message used when remove, set or add are called.- See Also:
-
iterator
The underlying iterator being decorated. -
list
The list being used to cache the iterator. -
currentIndex
private int currentIndexThe current index of this iterator. -
wrappedIteratorIndex
private int wrappedIteratorIndexThe current index of the wrapped iterator.
-
-
Constructor Details
-
ListIteratorWrapper
Constructs a newListIteratorWrapperthat will wrap the given iterator.- Parameters:
iterator- the iterator to wrap- Throws:
NullPointerException- if the iterator is null
-
-
Method Details
-
add
ThrowsUnsupportedOperationException.- Specified by:
addin interfaceListIterator- 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:
hasNextin interfaceIterator- Specified by:
hasNextin interfaceListIterator- Returns:
- true if there are more elements
-
hasPrevious
public boolean hasPrevious()Returns true if there are previous elements in the iterator.- Specified by:
hasPreviousin interfaceListIterator- Returns:
- true if there are previous elements
-
next
Returns the next element from the iterator.- Specified by:
nextin interfaceIterator- Specified by:
nextin interfaceListIterator- 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:
nextIndexin interfaceListIterator- Returns:
- the index of the next element
-
previous
Returns the the previous element.- Specified by:
previousin interfaceListIterator- 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:
previousIndexin interfaceListIterator- Returns:
- the index of the previous element
-
remove
ThrowsUnsupportedOperationException.- Specified by:
removein interfaceIterator- Specified by:
removein interfaceListIterator- Throws:
UnsupportedOperationException- always
-
set
ThrowsUnsupportedOperationException.- Specified by:
setin interfaceListIterator- 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:
resetin interfaceResettableIterator- Specified by:
resetin interfaceResettableListIterator- Since:
- Commons Collections 3.2
-