java.util.Iterator<E>
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 | Description |
---|---|
PushbackIterator(java.util.Iterator<? extends E> iterator) |
Constructor.
|
Modifier and Type | Method | 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 © 2001-2019 - Apache Software Foundation