Package com.google.common.collect
Class Iterators.PeekingImpl<E>
- java.lang.Object
-
- com.google.common.collect.Iterators.PeekingImpl<E>
-
- All Implemented Interfaces:
PeekingIterator<E>
,java.util.Iterator<E>
- Enclosing class:
- Iterators
private static class Iterators.PeekingImpl<E> extends java.lang.Object implements PeekingIterator<E>
Implementation of PeekingIterator that avoids peeking unless necessary.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
hasPeeked
private java.util.Iterator<? extends E>
iterator
private E
peekedElement
-
Constructor Summary
Constructors Constructor Description PeekingImpl(java.util.Iterator<? extends E> iterator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
hasNext()
E
next()
E
peek()
Returns the next element in the iteration, without advancing the iteration.void
remove()
-
-
-
Constructor Detail
-
PeekingImpl
public PeekingImpl(java.util.Iterator<? extends E> iterator)
-
-
Method Detail
-
hasNext
public boolean hasNext()
- Specified by:
hasNext
in interfacejava.util.Iterator<E>
-
next
public E next()
Description copied from interface:PeekingIterator
The objects returned by consecutive calls to
PeekingIterator.peek()
thenPeekingIterator.next()
are guaranteed to be equal to each other.- Specified by:
next
in interfacejava.util.Iterator<E>
- Specified by:
next
in interfacePeekingIterator<E>
-
remove
public void remove()
Description copied from interface:PeekingIterator
Implementations may or may not support removal when a call to
PeekingIterator.peek()
has occurred since the most recent call toPeekingIterator.next()
.- Specified by:
remove
in interfacejava.util.Iterator<E>
- Specified by:
remove
in interfacePeekingIterator<E>
-
peek
public E peek()
Description copied from interface:PeekingIterator
Returns the next element in the iteration, without advancing the iteration.Calls to
peek()
should not change the state of the iteration, except that it may prevent removal of the most recent element viaPeekingIterator.remove()
.- Specified by:
peek
in interfacePeekingIterator<E>
-
-