Interface SuccessorsFunction<N>

 Type Parameters:
N
 Node parameter type
 All Known Subinterfaces:
com.google.common.graph.BaseGraph<N>
,Graph<N>
,MutableGraph<N>
,MutableNetwork<N,E>
,MutableValueGraph<N,V>
,Network<N,E>
,ValueGraph<N,V>
 All Known Implementing Classes:
AbstractGraph
,AbstractNetwork
,AbstractValueGraph
,ImmutableGraph
,ImmutableNetwork
,ImmutableValueGraph
@Beta @DoNotMock("Implement with a lambda, or use GraphBuilder to build a Graph with the desired edges") public interface SuccessorsFunction<N>
A functional interface for graphstructured data.This interface is meant to be used as the type of a parameter to graph algorithms (such as breadth first traversal) that only need a way of accessing the successors of a node in a graph.
Usage
Given an algorithm, for example:
you will invoke it depending on the graph representation you're using.public <N> someGraphAlgorithm(N startNode, SuccessorsFunction<N> successorsFunction);
If you have an instance of one of the primary
common.graph
types (Graph
,ValueGraph
, andNetwork
):
This works because those types each implementsomeGraphAlgorithm(startNode, graph);
SuccessorsFunction
. It will also work with any other implementation of this interface.If you have your own graph implementation based around a custom node type
MyNode
, which has a methodgetChildren()
that retrieves its successors in a graph:someGraphAlgorithm(startNode, MyNode::getChildren);
If you have some other mechanism for returning the successors of a node, or one that doesn't return an
Iterable<? extends N>
, then you can use a lambda to perform a more general transformation:someGraphAlgorithm(startNode, node > ImmutableList.of(node.leftChild(), node.rightChild()));
Graph algorithms that need additional capabilities (accessing both predecessors and successors, iterating over the edges, etc.) should declare their input to be of a type that provides those capabilities, such as
Graph
,ValueGraph
, orNetwork
.Additional documentation
See the Guava User Guide for the
common.graph
package ("Graphs Explained") for additional documentation, including notes for implementors Since:
 23.0
 Author:
 Joshua O'Madadhain, Jens Nyman


Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.Iterable<? extends N>
successors(N node)
Returns all nodes in this graph adjacent tonode
which can be reached by traversingnode
's outgoing edges in the direction (if any) of the edge.



Method Detail

successors
java.lang.Iterable<? extends N> successors(N node)
Returns all nodes in this graph adjacent tonode
which can be reached by traversingnode
's outgoing edges in the direction (if any) of the edge.This is not the same as "all nodes reachable from
node
by following outgoing edges". For that functionality, seeGraphs.reachableNodes(Graph, Object)
.Some algorithms that operate on a
SuccessorsFunction
may produce undesired results if the returnedIterable
contains duplicate elements. Implementations of such algorithms should document their behavior in the presence of duplicates.The elements of the returned
Iterable
must each be: Nonnull
 Usable as
Map
keys (see the Guava User Guide's section on graph elements for details)
 Throws:
java.lang.IllegalArgumentException
 ifnode
is not an element of this graph

