public class ListIteratorWrapper<E> extends java.lang.Object implements ResettableListIterator<E>
Iterator
into a ResettableListIterator
.
For plain Iterator
s 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 Iterator
s.
This class implements ResettableListIterator from Commons Collections 3.2.
Constructor and Description |
---|
ListIteratorWrapper(java.util.Iterator<? extends E> iterator)
Constructs a new
ListIteratorWrapper that will wrap
the given iterator. |
Modifier and Type | Method and Description |
---|---|
void |
add(E obj)
Throws
UnsupportedOperationException
unless the underlying Iterator is a ListIterator . |
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)
Throws
UnsupportedOperationException
unless the underlying Iterator is a ListIterator . |
public ListIteratorWrapper(java.util.Iterator<? extends E> iterator)
ListIteratorWrapper
that will wrap
the given iterator.iterator
- the iterator to wrapjava.lang.NullPointerException
- if the iterator is nullpublic void add(E obj) throws java.lang.UnsupportedOperationException
UnsupportedOperationException
unless the underlying Iterator
is a ListIterator
.add
in interface java.util.ListIterator<E>
obj
- the object to addjava.lang.UnsupportedOperationException
- if the underlying iterator is not of
type ListIterator
public boolean hasNext()
public boolean hasPrevious()
hasPrevious
in interface java.util.ListIterator<E>
hasPrevious
in interface OrderedIterator<E>
public E next() throws java.util.NoSuchElementException
public int nextIndex()
nextIndex
in interface java.util.ListIterator<E>
public E previous() throws java.util.NoSuchElementException
previous
in interface java.util.ListIterator<E>
previous
in interface OrderedIterator<E>
java.util.NoSuchElementException
- if there are no previous elementspublic int previousIndex()
previousIndex
in interface java.util.ListIterator<E>
public void remove() throws java.lang.UnsupportedOperationException
UnsupportedOperationException
if previous()
has ever been called.public void set(E obj) throws java.lang.UnsupportedOperationException
UnsupportedOperationException
unless the underlying Iterator
is a ListIterator
.set
in interface java.util.ListIterator<E>
obj
- the object to setjava.lang.UnsupportedOperationException
- if the underlying iterator is not of
type ListIterator
public void reset()
reset
in interface ResettableIterator<E>
Copyright © 2010 - 2023 Adobe. All Rights Reserved