|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.collections4.iterators.PeekingIterator<E>
public class PeekingIterator<E>
Decorates an iterator to support one-element lookahead while iterating.
The decorator supports the removal operation, but an IllegalStateException
will be thrown if remove()
is called directly after a call to
peek()
or element()
.
Constructor Summary | |
---|---|
PeekingIterator(Iterator<? extends E> iterator)
Constructor. |
Method Summary | ||
---|---|---|
E |
element()
Returns the next element in iteration without advancing the underlying iterator. |
|
boolean |
hasNext()
|
|
E |
next()
|
|
E |
peek()
Returns the next element in iteration without advancing the underlying iterator. |
|
static
|
peekingIterator(Iterator<? extends E> iterator)
Decorates the specified iterator to support one-element lookahead. |
|
void |
remove()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PeekingIterator(Iterator<? extends E> iterator)
iterator
- the iterator to decorateMethod Detail |
---|
public static <E> PeekingIterator<E> peekingIterator(Iterator<? extends E> iterator)
If the iterator is already a PeekingIterator
it is returned directly.
E
- the element typeiterator
- the iterator to decorate
IllegalArgumentException
- if the iterator is nullpublic boolean hasNext()
hasNext
in interface Iterator<E>
public E peek()
Note: this method does not throw a NoSuchElementException
if the iterator
is already exhausted. If you want such a behavior, use element()
instead.
The rationale behind this is to follow the Queue
interface
which uses the same terminology.
public E element()
NoSuchElementException
- if the iterator is already exhausted according to hasNext()
public E next()
next
in interface Iterator<E>
public void remove()
remove
in interface Iterator<E>
IllegalStateException
- if peek()
or element()
has been called
prior to the call to remove()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |