Class LinkedDirectedGraph<N,​E>

  • Type Parameters:
    N - Value type that the graph node stores.
    E - Value type that the graph edge stores.
    All Implemented Interfaces:
    AdjacencyGraph<N,​E>, GraphvizGraph
    Direct Known Subclasses:
    ControlFlowGraph

    public class LinkedDirectedGraph<N,​E>
    extends DiGraph<N,​E>
    implements GraphvizGraph
    A directed graph using ArrayLists within nodes to store edge information.

    This implementation favors directed graph operations inherited from DirectedGraph. Operations from Graph would tend to be slower.

    • Constructor Detail

      • LinkedDirectedGraph

        protected LinkedDirectedGraph​(boolean useNodeAnnotations,
                                      boolean useEdgeAnnotations)
    • Method Detail

      • createWithoutAnnotations

        public static <N,​E> LinkedDirectedGraph<N,​E> createWithoutAnnotations()
      • connect

        public void connect​(N srcValue,
                            E edgeValue,
                            N destValue)
        Description copied from class: Graph
        Connects two nodes in the graph with an edge.
        Specified by:
        connect in class Graph<N,​E>
        Parameters:
        srcValue - First node.
        edgeValue - The edge.
        destValue - Second node.
      • connect

        public void connect​(DiGraph.DiGraphNode<N,​E> src,
                            E edgeValue,
                            DiGraph.DiGraphNode<N,​E> dest)
        DiGraphNode look ups can be expensive for a large graph operation, prefer this method if you have the DiGraphNode available.
      • connectIfNotConnectedInDirection

        public void connectIfNotConnectedInDirection​(N srcValue,
                                                     E edgeValue,
                                                     N destValue)
        DiGraphNode look ups can be expensive for a large graph operation, prefer this method if you have the DiGraphNode available.
      • disconnect

        public void disconnect​(N n1,
                               N n2)
        Description copied from class: Graph
        Disconnects two nodes in the graph by removing all edges between them.
        Specified by:
        disconnect in class Graph<N,​E>
        Parameters:
        n1 - First node.
        n2 - Second node.
      • disconnectInDirection

        public void disconnectInDirection​(N srcValue,
                                          N destValue)
        Description copied from class: DiGraph
        Disconnects all edges from n1 to n2.
        Specified by:
        disconnectInDirection in class DiGraph<N,​E>
        Parameters:
        srcValue - Source node.
        destValue - Destination node.
      • getNode

        public LinkedDirectedGraph.LinkedDiGraphNode<N,​E> getNode​(N nodeValue)
        Description copied from interface: AdjacencyGraph
        Gets a node from the graph given a value. Values equality are compared using Object.equals.
        Specified by:
        getNode in interface AdjacencyGraph<N,​E>
        Specified by:
        getNode in class DiGraph<N,​E>
        Parameters:
        nodeValue - The node's value.
        Returns:
        The corresponding node in the graph, null if there value has no corresponding node.
      • createNode

        public LinkedDirectedGraph.LinkedDiGraphNode<N,​E> createNode​(N nodeValue)
        Description copied from class: Graph
        Gets a node from the graph given a value. New nodes are created if that value has not been assigned a graph node. Values equality are compared using Object.equals.
        Specified by:
        createNode in class DiGraph<N,​E>
        Parameters:
        nodeValue - The node's value.
        Returns:
        The corresponding node in the graph.
      • getEdges

        public java.util.List<LinkedDirectedGraph.LinkedDiGraphEdge<N,​E>> getEdges​(N n1,
                                                                                         N n2)
        Description copied from class: Graph
        Retrieves an edge from the graph.
        Specified by:
        getEdges in class DiGraph<N,​E>
        Parameters:
        n1 - Node one.
        n2 - Node two.
        Returns:
        The list of edges between those two values in the graph.
      • getFirstEdge

        public Graph.GraphEdge<N,​E> getFirstEdge​(N n1,
                                                       N n2)
        Description copied from class: Graph
        Retrieves any edge from the graph.
        Specified by:
        getFirstEdge in class Graph<N,​E>
        Parameters:
        n1 - Node one.
        n2 - Node two.
        Returns:
        The first edges between those two values in the graph. null if there are none.
      • isConnectedInDirection

        public boolean isConnectedInDirection​(N source,
                                              N dest)
        DiGraphNode look ups can be expensive for a large graph operation, prefer the version below that takes DiGraphNodes, if you have them available.
        Specified by:
        isConnectedInDirection in class DiGraph<N,​E>
        Parameters:
        source - the source node from which we traverse outwards
        dest - Node 2.
        Returns:
        true if the graph contains edge from n1 to n2.
      • isConnectedInDirection

        public boolean isConnectedInDirection​(N source,
                                              E edgeValue,
                                              N dest)
        DiGraphNode look ups can be expensive for a large graph operation, prefer the version below that takes DiGraphNodes, if you have them available.
        Specified by:
        isConnectedInDirection in class DiGraph<N,​E>
        Parameters:
        source - the source node from which we traverse outwards
        edgeValue - only edges equal to the given value will be traversed
        dest - Node 2.
        Returns:
        true if the edge exists.
      • isConnectedInDirection

        public boolean isConnectedInDirection​(LinkedDirectedGraph.LinkedDiGraphNode<N,​E> source,
                                              com.google.common.base.Predicate<E> edgeFilter,
                                              LinkedDirectedGraph.LinkedDiGraphNode<N,​E> dest)
        DiGraphNode look ups can be expensive for a large graph operation, prefer this method if you have the DiGraphNodes available.
        Parameters:
        source - the source node from which we traverse outwards
        edgeFilter - only edges matching this filter will be traversed
        dest - the destination node
      • getName

        public java.lang.String getName()
        Description copied from interface: GraphvizGraph
        Name of the graph.
        Specified by:
        getName in interface GraphvizGraph
        Returns:
        Name of the graph.
      • isDirected

        public boolean isDirected()
        Description copied from interface: GraphvizGraph
        Graph type.
        Specified by:
        isDirected in interface GraphvizGraph
        Returns:
        True if the graph is a directed graph.
      • getNeighborNodes

        public java.util.List<GraphNode<N,​E>> getNeighborNodes​(N value)
        Description copied from class: Graph
        Gets the neighboring nodes.
        Specified by:
        getNeighborNodes in class Graph<N,​E>
        Parameters:
        value - The node's value.
        Returns:
        A list of neighboring nodes.
      • getNodeDegree

        public int getNodeDegree​(N value)
        Description copied from class: Graph
        Gets the degree of a node.
        Specified by:
        getNodeDegree in class Graph<N,​E>
        Parameters:
        value - The node's value.
        Returns:
        The degree of the node.