Class GraphHelper


  • public class GraphHelper
    extends java.lang.Object
    Utility class for graph related operations.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <V> java.util.List<V> constructPath​(V source, V target, java.util.Set<V> nodesInGraph, IGraphDataSource<V> graphDataSource)
      Constructs a path between source and target in the given graph.
      static <V> int getEdgeCount​(V node, IGraphDataSource<V> graphDataSource)
      Returns the number of self-loop edges for the given node.
      static <V> int getEdgeCount​(V source, V target, IGraphDataSource<V> graphDataSource)
      Returns the number of edges between the given source and target nodes.
      static <V> Graph<V> getSubGraph​(java.util.Collection<V> nodesInSubGraph, IBiDirectionalGraphDataSource<V> graphDataSource)
      Returns the subgraph from the given IBiDirectionalGraphDataSource which contains the given set of nodes.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getSubGraph

        public static <V> Graph<V> getSubGraph​(java.util.Collection<V> nodesInSubGraph,
                                               IBiDirectionalGraphDataSource<V> graphDataSource)
        Returns the subgraph from the given IBiDirectionalGraphDataSource which contains the given set of nodes.
        Parameters:
        nodesInSubGraph - the nodes that are present in the subgraph
        graphDataSource - the graph data source for the original graph
        Returns:
        the subgraph associated to the given nodes
      • constructPath

        public static <V> java.util.List<V> constructPath​(V source,
                                                          V target,
                                                          java.util.Set<V> nodesInGraph,
                                                          IGraphDataSource<V> graphDataSource)
        Constructs a path between source and target in the given graph. Both the IGraphDataSource and the set of nodes are used, this way it is possible to construct a path in a given subgraph. The returned List contains the nodes along the path (this means that there is an edge in the graph between two consecutive nodes). A self loop (one edge) is indicated with the source node being present two times in the returned List.
        Parameters:
        source - the source node
        target - the target node
        nodesInGraph - the nodes that are present in the subgraph
        graphDataSource - the graph data source
        Returns:
        the path between the two nodes
      • getEdgeCount

        public static <V> int getEdgeCount​(V node,
                                           IGraphDataSource<V> graphDataSource)
        Returns the number of self-loop edges for the given node.
        Parameters:
        node - the node
        graphDataSource - the graph data source
        Returns:
        the number of self-loop edges
      • getEdgeCount

        public static <V> int getEdgeCount​(V source,
                                           V target,
                                           IGraphDataSource<V> graphDataSource)
        Returns the number of edges between the given source and target nodes.
        Parameters:
        source - the source node
        target - the target node
        graphDataSource - the graph data source
        Returns:
        the number of parallel edges between the two nodes