public class PushbackIterator<E> extends Object implements Iterator<E>
The decorator stores the pushed back elements in a LIFO manner: the last element
that has been pushed back, will be returned as the next element in a call to next()
.
The decorator does not support the removal operation. Any call to remove()
will
result in an UnsupportedOperationException
.
Constructor and Description |
---|
PushbackIterator(Iterator<? extends E> iterator)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
hasNext() |
E |
next() |
void |
pushback(E item)
Push back the given element to the iterator.
|
static <E> PushbackIterator<E> |
pushbackIterator(Iterator<? extends E> iterator)
Decorates the specified iterator to support one-element lookahead.
|
void |
remove()
This iterator will always throw an
UnsupportedOperationException . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEachRemaining
public PushbackIterator(Iterator<? extends E> iterator)
iterator
- the iterator to decoratepublic static <E> PushbackIterator<E> pushbackIterator(Iterator<? extends E> iterator)
If the iterator is already a PushbackIterator
it is returned directly.
E
- the element typeiterator
- the iterator to decorateNullPointerException
- if the iterator is nullpublic void pushback(E item)
Calling next()
immediately afterwards will return exactly this element.
item
- the element to push back to the iteratorpublic void remove()
UnsupportedOperationException
.remove
in interface Iterator<E>
UnsupportedOperationException
- alwaysCopyright © 2001–2019 The Apache Software Foundation. All rights reserved.