The decorator supports the removal operation, but an IllegalStateException
will be thrown if remove() is called directly after a call to
peek() or element().
| Modifier and Type | Field and Description |
|---|---|
| private boolean | exhausted
Indicates that the decorated iterator is exhausted. |
| private final Iterator | iterator
The iterator being decorated. |
| private E | slot
The current slot for lookahead. |
| private boolean | slotFilled
Indicates if the lookahead slot is filled. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public E | Returns: the next element from the iteratorReturns the next element in iteration without advancing the underlying iterator. |
| private void | |
| public boolean | |
| public E | |
| public E | Returns: the next element from the iteratorReturns the next element in iteration without advancing the underlying iterator. |
| public static < the element type E> PeekingIterator | Returns: a new peeking iteratorthe iterator to decorate iterator)Decorates the specified iterator to support one-element lookahead. |
| public void | remove()
Overrides default java. |
| exhausted | back to summary |
|---|---|
| private boolean exhausted Indicates that the decorated iterator is exhausted. | |
| iterator | back to summary |
|---|---|
| private final Iterator<? extends E> iterator The iterator being decorated. | |
| slot | back to summary |
|---|---|
| private E slot The current slot for lookahead. | |
| slotFilled | back to summary |
|---|---|
| private boolean slotFilled Indicates if the lookahead slot is filled. | |
| PeekingIterator | back to summary |
|---|---|
| public PeekingIterator(final Iterator<? extends E> iterator) Constructor.
| |
| element | back to summary |
|---|---|
| public E element() Returns the next element in iteration without advancing the underlying iterator. If the iterator is already exhausted, null will be returned.
| |
| fill | back to summary |
|---|---|
| private void fill() | |
| hasNext | back to summary |
|---|---|
| public boolean hasNext() Implements java. Doc from java. Returns
| |
| next | back to summary |
|---|---|
| public E next() Implements java. Doc from java. Returns the next element in the iteration.
| |
| peek | back to summary |
|---|---|
| public E peek() Returns the next element in iteration without advancing the underlying iterator. If the iterator is already exhausted, null will be returned. Note this method does not throw a
The rationale behind this is to follow the
| |
| peekingIterator | back to summary |
|---|---|
| public static <E> PeekingIterator Decorates the specified iterator to support one-element lookahead.
If the iterator is already a
| |
| remove | back to summary |
|---|---|
| public void remove() Overrides default java. Doc from java. Removes from the underlying collection the last element returned
by this iterator (optional operation). This method can be called
only once per call to The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.
The behavior of an iterator is unspecified if this method is called
after a call to the
| |