Package com.google.common.graph
Class Traverser.GraphTraverser.DepthFirstIterator
- java.lang.Object
-
- com.google.common.collect.UnmodifiableIterator<T>
-
- com.google.common.collect.AbstractIterator<N>
-
- com.google.common.graph.Traverser.GraphTraverser.DepthFirstIterator
-
- All Implemented Interfaces:
java.util.Iterator<N>
- Enclosing class:
- Traverser.GraphTraverser<N>
private final class Traverser.GraphTraverser.DepthFirstIterator extends AbstractIterator<N>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
Traverser.GraphTraverser.DepthFirstIterator.NodeAndSuccessors
A simple tuple of a node and a partially iteratedIterator
of its successors.
-
Field Summary
Fields Modifier and Type Field Description private Traverser.Order
order
private java.util.Deque<Traverser.GraphTraverser.DepthFirstIterator.NodeAndSuccessors>
stack
private java.util.Set<N>
visited
-
Constructor Summary
Constructors Constructor Description DepthFirstIterator(java.lang.Iterable<? extends N> roots, Traverser.Order order)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected N
computeNext()
Returns the next element.(package private) Traverser.GraphTraverser.DepthFirstIterator.NodeAndSuccessors
withSuccessors(N node)
-
Methods inherited from class com.google.common.collect.AbstractIterator
endOfData, hasNext, next, peek
-
Methods inherited from class com.google.common.collect.UnmodifiableIterator
remove
-
-
-
-
Field Detail
-
stack
private final java.util.Deque<Traverser.GraphTraverser.DepthFirstIterator.NodeAndSuccessors> stack
-
visited
private final java.util.Set<N> visited
-
order
private final Traverser.Order order
-
-
Constructor Detail
-
DepthFirstIterator
DepthFirstIterator(java.lang.Iterable<? extends N> roots, Traverser.Order order)
-
-
Method Detail
-
computeNext
protected N computeNext()
Description copied from class:AbstractIterator
Returns the next element. Note: the implementation must callAbstractIterator.endOfData()
when there are no elements left in the iteration. Failure to do so could result in an infinite loop.The initial invocation of
AbstractIterator.hasNext()
orAbstractIterator.next()
calls this method, as does the first invocation ofhasNext
ornext
following each successful call tonext
. Once the implementation either invokesendOfData
or throws an exception,computeNext
is guaranteed to never be called again.If this method throws an exception, it will propagate outward to the
hasNext
ornext
invocation that invoked this method. Any further attempts to use the iterator will result in anIllegalStateException
.The implementation of this method may not invoke the
hasNext
,next
, orAbstractIterator.peek()
methods on this instance; if it does, anIllegalStateException
will result.- Specified by:
computeNext
in classAbstractIterator<N>
- Returns:
- the next element if there was one. If
endOfData
was called during execution, the return value will be ignored.
-
withSuccessors
Traverser.GraphTraverser.DepthFirstIterator.NodeAndSuccessors withSuccessors(N node)
-
-