public class ListIteratorWrapper<E> extends Object implements ResettableListIterator<E>
Iterator into a ResettableListIterator.
For plain Iterators this is accomplished by caching the returned
elements. This class can also be used to simply add
ResettableIterator
functionality to a given ListIterator.
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 for plain Iterators.
This class implements ResettableListIterator from Commons Collections 3.2.
| Constructor and Description |
|---|
ListIteratorWrapper(Iterator<? extends E> iterator)
Constructs a new
ListIteratorWrapper that will wrap
the given iterator. |
| Modifier and Type | Method and Description |
|---|---|
void |
add(E 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.
|
E |
next()
Returns the next element from the iterator.
|
int |
nextIndex()
Returns the index of the next element.
|
E |
previous()
Returns the previous element.
|
int |
previousIndex()
Returns the index of the previous element.
|
void |
remove()
Throws
UnsupportedOperationException if previous() has ever been called. |
void |
reset()
Resets this iterator back to the position at which the iterator
was created.
|
void |
set(E obj)
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEachRemainingpublic ListIteratorWrapper(Iterator<? extends E> iterator)
ListIteratorWrapper that will wrap
the given iterator.iterator - the iterator to wrapNullPointerException - if the iterator is nullpublic void add(E obj) throws UnsupportedOperationException
add in interface ListIterator<E>obj - the object to addUnsupportedOperationException - if the underlying iterator is not of
type ListIteratorpublic boolean hasNext()
public boolean hasPrevious()
hasPrevious in interface ListIterator<E>hasPrevious in interface OrderedIterator<E>public E next() throws NoSuchElementException
next in interface Iterator<E>next in interface ListIterator<E>NoSuchElementException - if there are no more elementspublic int nextIndex()
nextIndex in interface ListIterator<E>public E previous() throws NoSuchElementException
previous in interface ListIterator<E>previous in interface OrderedIterator<E>NoSuchElementException - if there are no previous elementspublic int previousIndex()
previousIndex in interface ListIterator<E>public void remove()
throws UnsupportedOperationException
UnsupportedOperationException if previous() has ever been called.remove in interface Iterator<E>remove in interface ListIterator<E>UnsupportedOperationException - alwayspublic void set(E obj) throws UnsupportedOperationException
set in interface ListIterator<E>obj - the object to setUnsupportedOperationException - if the underlying iterator is not of
type ListIteratorpublic void reset()
reset in interface ResettableIterator<E>Copyright © 2006–2022 Apache Software Foundation. All rights reserved.