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

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

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

    • Field Detail

      • nodes

        protected final java.util.Map<N,​com.google.javascript.jscomp.graph.LinkedDirectedGraph.LinkedDirectedGraphNode<N,​E>> nodes
    • Constructor Detail

      • LinkedDirectedGraph

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

      • createWithoutAnnotations

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

        public static <N,​E> LinkedDirectedGraph<N,​E> createWithNodeAnnotations()
      • createWithEdgeAnnotations

        public static <N,​E> LinkedDirectedGraph<N,​E> createWithEdgeAnnotations()
      • 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.
      • 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 GraphNode<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>
        Parameters:
        nodeValue - The node's value.
        Returns:
        The corresponding node in the graph, null if there value has no corresponding node.
      • getEdges

        public java.util.List<Graph.GraphEdge<N,​E>> getEdges​(N n1,
                                                                   N n2)
        Description copied from class: Graph
        Retrieves an edge from the graph.
        Specified by:
        getEdges in class Graph<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.
      • createNode

        public GraphNode<N,​E> createNode​(N value)
        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 Graph<N,​E>
        Parameters:
        value - The node's value.
        Returns:
        The corresponding node in the graph.
      • isConnectedInDirection

        public boolean isConnectedInDirection​(N n1,
                                              N n2)
        Description copied from class: DiGraph
        Checks whether two nodes in the graph are connected via a directed edge.
        Specified by:
        isConnectedInDirection in class DiGraph<N,​E>
        Parameters:
        n1 - Node 1.
        n2 - Node 2.
        Returns:
        true if the graph contains edge from n1 to n2.
      • isConnectedInDirection

        public boolean isConnectedInDirection​(N n1,
                                              E edgeValue,
                                              N n2)
        Description copied from class: DiGraph
        Checks whether two nodes in the graph are connected via a directed edge with the given value.
        Specified by:
        isConnectedInDirection in class DiGraph<N,​E>
        Parameters:
        n1 - Node 1.
        edgeValue - edge value tag
        n2 - Node 2.
        Returns:
        true if the edge exists.
      • 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.
      • getEdges

        public java.util.List<Graph.GraphEdge<N,​E>> getEdges()
        Description copied from class: Graph
        Gets an immutable list of all edges.
        Specified by:
        getEdges in class Graph<N,​E>
      • 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.