Class XGraphUtils
- java.lang.Object
-
- de.xima.fc.utils.XGraphUtils
-
- Direct Known Subclasses:
GraphAlgos
public class XGraphUtils extends Object
Helper methods forGraphandValueGraphdata structures.- Since:
- 8.0.0
- Author:
- XIMA MEDIA GmbH
-
-
Constructor Summary
Constructors Constructor Description XGraphUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <N> Set<N>arrivingNodes(com.google.common.graph.Graph<N> graph, Iterable<? extends N> startNodes)Returns the set of nodes from which thenodecan be reached.static <N> Set<N>arrivingNodes(com.google.common.graph.Graph<N> graph, N startNode)Returns the set of nodes from which thenodecan be reached.static <N,V>
Set<N>arrivingNodes(com.google.common.graph.ValueGraph<N,? extends V> graph, Iterable<? extends N> startNodes, IValueGraphEdgePredicate<? super N,? super V> edgeFilter)Returns the set of nodes from which thenodecan be reached.static <N,I,R>
com.google.common.graph.ImmutableGraph<R>immutableFromTreeAccessor(N startNode, ITreeAccessor<N,I> treeAccessor, com.google.common.graph.GraphBuilder<Object> builder, BiFunction<N,I,R> mapper)Creates a directed graph from a given start node and its children, recursively.static <N> Set<N>reachableNodes(com.google.common.graph.Graph<N> graph, Iterable<? extends N> startNodes)Taken fromGraphs.reachableNodes(Graph, Object), but fixed so that a node is only reachable from itself when there exists has a 0+ loop cycle with the loop.static <N> Set<N>reachableNodes(com.google.common.graph.Graph<N> graph, N startNode)Taken fromGraphs.reachableNodes(Graph, Object), but fixed so that a node is only reachable from itself when there exists has a 0+ loop cycle with the loop.static <N,V>
Set<N>reachableNodes(com.google.common.graph.ValueGraph<N,? extends V> graph, Iterable<? extends N> startNodes, IValueGraphEdgePredicate<? super N,? super V> edgeFilter)Taken fromGraphs.reachableNodes(Graph, Object), but for value graphs and fixed so that a node is only reachable from itself when there exists has a 0+ loop cycle with the loop.static <N> com.google.common.graph.Graph<N>transitiveClosure(com.google.common.graph.Graph<N> graph)Taken fromGraphs.transitiveClosure(Graph), but fixed so it does not add self-loops.
-
-
-
Method Detail
-
arrivingNodes
public static <N> Set<N> arrivingNodes(com.google.common.graph.Graph<N> graph, Iterable<? extends N> startNodes)
Returns the set of nodes from which thenodecan be reached. Node B is defined as reachable from node A if there exists a path (a sequence of adjacent outgoing edges) starting at node A and ending at node B. Note that a node is only reachable from itself when there exists a 0+ cycle with node in the graph.This is a "snapshot" based on the current topology of
graph, rather than a live view of the set of nodes reachable fromnode. In other words, the returnedSetwill not be updated after modifications tograph.- Type Parameters:
N- Type of the nodes in the graph.- Parameters:
graph- Graph to traverse.startNodes- Nodes where to start traversal.- Returns:
- A mutable set with all nodes that are from which the given start node can be reached by traversing the edges of the graph. This will not include the node itself, unless a 0+ cycle with the node exists in the graph.
- Since:
- 8.0.0
-
arrivingNodes
public static <N> Set<N> arrivingNodes(com.google.common.graph.Graph<N> graph, N startNode)
Returns the set of nodes from which thenodecan be reached. Node B is defined as reachable from node A if there exists a path (a sequence of adjacent outgoing edges) starting at node A and ending at node B. Note that a node is only reachable from itself when there exists a 0+ cycle with node in the graph.This is a "snapshot" based on the current topology of
graph, rather than a live view of the set of nodes reachable fromnode. In other words, the returnedSetwill not be updated after modifications tograph.- Type Parameters:
N- Type of the nodes in the graph.- Parameters:
graph- Graph to traverse.startNode- Node where to start traversal.- Returns:
- A mutable set with all nodes that are from which the given start node can be reached by traversing the edges of the graph. This will not include the node itself, unless a 0+ cycle with the node exists in the graph.
-
arrivingNodes
public static <N,V> Set<N> arrivingNodes(com.google.common.graph.ValueGraph<N,? extends V> graph, Iterable<? extends N> startNodes, IValueGraphEdgePredicate<? super N,? super V> edgeFilter)
Returns the set of nodes from which thenodecan be reached. Node B is defined as reachable from node A if there exists a path (a sequence of adjacent outgoing edges) starting at node A and ending at node B. Note that a node is only reachable from itself when there exists a 0+ cycle with node in the graph.This is a "snapshot" based on the current topology of
graph, rather than a live view of the set of nodes reachable fromnode. In other words, the returnedSetwill not be updated after modifications tograph.- Type Parameters:
N- Type of the nodes in the graph.V- Type of the values associated with the edges in he graph.- Parameters:
graph- Graph to traverse.startNodes- Nodes where to start traversal.edgeFilter- Filter for the edges to respect when computing the arriving nodes. Each edge for which this filter returnfalseis excluded. In other words, this method behaves as if it would first construct a new graph with the same nodes of the original graph and those edge for which the filter returnstrue; and then compute the arriving nodes on that new graph.- Returns:
- A mutable set with all nodes that are from which the given start node can be reached by traversing the edges of the graph. This will not include the nodes themselves, unless a 0+ cycle with the node exists in the graph.
- Since:
- 8.0.0
-
immutableFromTreeAccessor
public static <N,I,R> com.google.common.graph.ImmutableGraph<R> immutableFromTreeAccessor(N startNode, ITreeAccessor<N,I> treeAccessor, com.google.common.graph.GraphBuilder<Object> builder, BiFunction<N,I,R> mapper)Creates a directed graph from a given start node and its children, recursively.- Type Parameters:
N- Type of the input nodes.I- Type of the ID of each node.R- Type of the output nodes.- Parameters:
startNode- Start or root nodetreeAccessor- How to access the children of an input node.builder- Graph builder to use for creating a new graph.mapper- How to map an input node o an output node.- Returns:
- A graph with one edge for each (parent, child)from the input.
-
reachableNodes
public static <N> Set<N> reachableNodes(com.google.common.graph.Graph<N> graph, Iterable<? extends N> startNodes)
Taken fromGraphs.reachableNodes(Graph, Object), but fixed so that a node is only reachable from itself when there exists has a 0+ loop cycle with the loop. Also does not throw an illegal argument exception when the node is not contained in the graph.Returns the set of nodes that are reachable from
node. Node B is defined as reachable from node A if there exists a path (a sequence of adjacent outgoing edges) starting at node A and ending at node B. Note that a node is only reachable from itself when there exists a 0+ cycle with node in the graph.This is a "snapshot" based on the current topology of
graph, rather than a live view of the set of nodes reachable fromnode. In other words, the returnedSetwill not be updated after modifications tograph.- Type Parameters:
N- Type of the nodes in the graph.- Parameters:
graph- Graph to traverse.startNodes- Nodes where to start traversal.- Returns:
- A mutable set with all nodes that are reachable from the given start node by traversing the edges of the graph. This will not include the node itself, unless a 0+ cycle with the node exists in the graph.
- Since:
- 8.0.0
-
reachableNodes
public static <N> Set<N> reachableNodes(com.google.common.graph.Graph<N> graph, N startNode)
Taken fromGraphs.reachableNodes(Graph, Object), but fixed so that a node is only reachable from itself when there exists has a 0+ loop cycle with the loop. Also does not throw an illegal argument exception when the node is not contained in the graph.Returns the set of nodes that are reachable from
node. Node B is defined as reachable from node A if there exists a path (a sequence of adjacent outgoing edges) starting at node A and ending at node B. Note that a node is only reachable from itself when there exists a 0+ cycle with node in the graph.This is a "snapshot" based on the current topology of
graph, rather than a live view of the set of nodes reachable fromnode. In other words, the returnedSetwill not be updated after modifications tograph.- Type Parameters:
N- Type of the nodes in the graph.- Parameters:
graph- Graph to traverse.startNode- Node where to start traversal.- Returns:
- A mutable set with all nodes that are reachable from the given start node by traversing the edges of the graph. This will not include the node itself, unless a 0+ cycle with the node exists in the graph.
-
reachableNodes
public static <N,V> Set<N> reachableNodes(com.google.common.graph.ValueGraph<N,? extends V> graph, Iterable<? extends N> startNodes, IValueGraphEdgePredicate<? super N,? super V> edgeFilter)
Taken fromGraphs.reachableNodes(Graph, Object), but for value graphs and fixed so that a node is only reachable from itself when there exists has a 0+ loop cycle with the loop. Also does not throw an illegal argument exception when the node is not contained in the graph.Returns the set of nodes that are reachable from
node. Node B is defined as reachable from node A if there exists a path (a sequence of adjacent outgoing edges) starting at node A and ending at node B. Note that a node is only reachable from itself when there exists a 0+ cycle with node in the graph.This is a "snapshot" based on the current topology of
graph, rather than a live view of the set of nodes reachable fromnode. In other words, the returnedSetwill not be updated after modifications tograph.- Type Parameters:
N- Type of the nodes in the graph.V- Type of the values associated with the edges in he graph.- Parameters:
graph- Graph to traverse.startNodes- Nodes where to start traversal.edgeFilter- Filter for the edges to respect when computing the reachable nodes. Each edge for which this filter returnfalseis excluded. In other words, this method behaves as if it would first construct a new graph with the same nodes of the original graph and those edge for which the filter returnstrue; and then compute the reachable nodes on that new graph.- Returns:
- A mutable set with all nodes that are reachable from the given start node by traversing the edges of the graph. This will not include the nodes themselves, unless a 0+ cycle with the node exists in the graph.
- Since:
- 8.0.0
-
transitiveClosure
public static <N> com.google.common.graph.Graph<N> transitiveClosure(com.google.common.graph.Graph<N> graph)
Taken fromGraphs.transitiveClosure(Graph), but fixed so it does not add self-loops. Can be replaced withGraphs.transitiveClosure(Graph)when https://github.com/google/guava/issues/2778 is resolved.Returns the transitive closure of
graph. The transitive closure of a graph is another graph with an edge connecting node A to node B if node B isreachablefrom node A.This is a "snapshot" based on the current topology of
graph, rather than a live view of the transitive closure ofgraph. In other words, the returnedGraphwill not be updated after modifications tograph.- Type Parameters:
N- Type of the nodes in the graph.- Parameters:
graph- Graph to traverse.- Returns:
- The transitive closure of the given graph.
-
-