Top Description Inners Fields Constructors Methods
com.google.common.graph

pack-priv abstract Class EndpointPairIterator<N>

extends AbstractIterator<EndpointPair<N>>
Class Inheritance
Known Direct Subclasses
com.google.common.graph.EndpointPairIterator.Directed, com.google.common.graph.EndpointPairIterator.Undirected
Annotations
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkState, java.util.Objects.requireNonNull

A class to facilitate the set returned by Graph#edges().
Author
James Sexton

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
EndpointPairIterator.Directed<N>

If the graph is directed, each ordered [source, target] pair will be visited once if there is an edge connecting them.

private static class
EndpointPairIterator.Undirected<N>

If the graph is undirected, each unordered [node, otherNode] pair (except self-loops) will be visited twice if there is an edge connecting them.

Field Summary

Modifier and TypeField and Description
private final BaseGraph<N>
pack-priv N
private final Iterator<N>
pack-priv Iterator<N>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv final boolean
advance()

Called after successorIterator is exhausted.

pack-priv static <N> EndpointPairIterator<N>
of(BaseGraph<N> graph)

Inherited from com.google.common.collect.AbstractIterator:
computeNextendOfDatahasNextnextpeek

Field Detail

graphback to summary
private final BaseGraph<N> graph
nodeback to summary
pack-priv N node
Annotations
@CheckForNull
nodeIteratorback to summary
private final Iterator<N> nodeIterator
successorIteratorback to summary
pack-priv Iterator<N> successorIterator

Constructor Detail

EndpointPairIteratorback to summary
private EndpointPairIterator(BaseGraph<N> graph)

Method Detail

advanceback to summary
pack-priv final boolean advance()

Called after successorIterator is exhausted. Advances node to the next node and updates successorIterator to iterate through the successors of node.

ofback to summary
pack-priv static <N> EndpointPairIterator<N> of(BaseGraph<N> graph)
com.google.common.graph back to summary

private final Class EndpointPairIterator.Directed<N>

extends EndpointPairIterator<N>
Class Inheritance

If the graph is directed, each ordered [source, target] pair will be visited once if there is an edge connecting them.

Field Summary

Inherited from com.google.common.graph.EndpointPairIterator:
nodesuccessorIterator

Constructor Summary

AccessConstructor and Description
private
Directed(BaseGraph<N> graph)

Method Summary

Modifier and TypeMethod and Description
protected EndpointPair<N>
computeNext()

Implements abstract com.google.common.collect.AbstractIterator.computeNext.

Returns the next element

Note

the implementation must call endOfData() when there are no elements left in the iteration.

Inherited from com.google.common.graph.EndpointPairIterator:
advanceof

Constructor Detail

Directedback to summary
private Directed(BaseGraph<N> graph)

Method Detail

computeNextback to summary
protected EndpointPair<N> computeNext()

Implements abstract com.google.common.collect.AbstractIterator.computeNext.

Doc from com.google.common.collect.AbstractIterator.computeNext.

Returns the next element

Note

the implementation must call endOfData() when there are no elements left in the iteration. Failure to do so could result in an infinite loop.

The initial invocation of hasNext() or next() calls this method, as does the first invocation of hasNext or next following each successful call to next. Once the implementation either invokes endOfData 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 or next invocation that invoked this method. Any further attempts to use the iterator will result in an IllegalStateException.

The implementation of this method may not invoke the hasNext, next, or peek() methods on this instance; if it does, an IllegalStateException will result.

Returns:EndpointPair<N>

the next element if there was one. If endOfData was called during execution, the return value will be ignored.

Annotations
@Override
@CheckForNull
com.google.common.graph back to summary

private final Class EndpointPairIterator.Undirected<N>

extends EndpointPairIterator<N>
Class Inheritance

If the graph is undirected, each unordered [node, otherNode] pair (except self-loops) will be visited twice if there is an edge connecting them. To avoid returning duplicate EndpointPairs, we keep track of the nodes that we have visited. When processing endpoint pairs, we skip if the "other node" is in the visited set, as shown below:
Nodes = {N1, N2, N3, N4}
   N2           __
  /  \         |  |
N1----N3      N4__|

Visited Nodes = {}
EndpointPair [N1, N2] - return
EndpointPair [N1, N3] - return
Visited Nodes = {N1}
EndpointPair [N2, N1] - skip
EndpointPair [N2, N3] - return
Visited Nodes = {N1, N2}
EndpointPair [N3, N1] - skip
EndpointPair [N3, N2] - skip
Visited Nodes = {N1, N2, N3}
EndpointPair [N4, N4] - return
Visited Nodes = {N1, N2, N3, N4}

Field Summary

Modifier and TypeField and Description
private Set<@Nullable N>
Inherited from com.google.common.graph.EndpointPairIterator:
nodesuccessorIterator

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected EndpointPair<N>
computeNext()

Implements abstract com.google.common.collect.AbstractIterator.computeNext.

Returns the next element

Note

the implementation must call endOfData() when there are no elements left in the iteration.

Inherited from com.google.common.graph.EndpointPairIterator:
advanceof

Field Detail

visitedNodesback to summary
private Set<@Nullable N> visitedNodes
Annotations
@CheckForNull

Constructor Detail

Undirectedback to summary
private Undirected(BaseGraph<N> graph)

Method Detail

computeNextback to summary
protected EndpointPair<N> computeNext()

Implements abstract com.google.common.collect.AbstractIterator.computeNext.

Doc from com.google.common.collect.AbstractIterator.computeNext.

Returns the next element

Note

the implementation must call endOfData() when there are no elements left in the iteration. Failure to do so could result in an infinite loop.

The initial invocation of hasNext() or next() calls this method, as does the first invocation of hasNext or next following each successful call to next. Once the implementation either invokes endOfData 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 or next invocation that invoked this method. Any further attempts to use the iterator will result in an IllegalStateException.

The implementation of this method may not invoke the hasNext, next, or peek() methods on this instance; if it does, an IllegalStateException will result.

Returns:EndpointPair<N>

the next element if there was one. If endOfData was called during execution, the return value will be ignored.

Annotations
@Override
@CheckForNull