public class PushbackIterator<E>
extends java.lang.Object
implements java.util.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(java.util.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(java.util.Iterator<? extends E> iterator)
Decorates the specified iterator to support one-element lookahead.
|
void |
remove()
This iterator will always throw an
UnsupportedOperationException. |
public PushbackIterator(java.util.Iterator<? extends E> iterator)
iterator - the iterator to decoratepublic static <E> PushbackIterator<E> pushbackIterator(java.util.Iterator<? extends E> iterator)
If the iterator is already a PushbackIterator it is returned directly.
E - the element typeiterator - the iterator to decoratejava.lang.NullPointerException - 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 boolean hasNext()
hasNext in interface java.util.Iterator<E>public void remove()
UnsupportedOperationException.remove in interface java.util.Iterator<E>java.lang.UnsupportedOperationException - alwaysCopyright © 2010 - 2023 Adobe. All Rights Reserved