public class ListIteratorWrapper extends Object implements ResettableListIterator
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.
Constructor and Description |
---|
ListIteratorWrapper(Iterator iterator)
Constructs a new
ListIteratorWrapper that will wrap
the given iterator. |
Modifier and Type | Method and Description |
---|---|
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 . |
public ListIteratorWrapper(Iterator iterator)
ListIteratorWrapper
that will wrap
the given iterator.iterator
- the iterator to wrapNullPointerException
- if the iterator is nullpublic void add(Object obj) throws UnsupportedOperationException
UnsupportedOperationException
.add
in interface ListIterator
obj
- the object to add, ignoredUnsupportedOperationException
- alwayspublic boolean hasNext()
hasNext
in interface Iterator
hasNext
in interface ListIterator
public boolean hasPrevious()
hasPrevious
in interface ListIterator
public Object next() throws NoSuchElementException
next
in interface Iterator
next
in interface ListIterator
NoSuchElementException
- if there are no more elementspublic int nextIndex()
nextIndex
in interface ListIterator
public Object previous() throws NoSuchElementException
previous
in interface ListIterator
NoSuchElementException
- if there are no previous elementspublic int previousIndex()
previousIndex
in interface ListIterator
public void remove() throws UnsupportedOperationException
UnsupportedOperationException
.remove
in interface Iterator
remove
in interface ListIterator
UnsupportedOperationException
- alwayspublic void set(Object obj) throws UnsupportedOperationException
UnsupportedOperationException
.set
in interface ListIterator
obj
- the object to set, ignoredUnsupportedOperationException
- alwayspublic void reset()
reset
in interface ResettableIterator
reset
in interface ResettableListIterator
Copyright © 2001–2015 The Apache Software Foundation. All rights reserved.