Class LinkedUndirectedGraph<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 final class LinkedUndirectedGraph<N,​E>
    extends UndiGraph<N,​E>
    implements GraphvizGraph
    An undirected graph using linked list within nodes to store edge information.
    • Field Detail

      • nodes

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

      • LinkedUndirectedGraph

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

      • 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 srcValue,
                               N destValue)
        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:
        srcValue - First node.
        destValue - Second node.
      • 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.
      • 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.
      • 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.
      • 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>
      • 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.
      • getNode

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

        public boolean isConnected​(N n1,
                                   N n2)
        Description copied from class: Graph
        Checks whether two nodes in the graph are connected.
        Specified by:
        isConnected in class Graph<N,​E>
        Parameters:
        n1 - Node 1.
        n2 - Node 2.
        Returns:
        true if the two nodes are connected.
      • isConnected

        public boolean isConnected​(N n1,
                                   E e,
                                   N n2)
        Description copied from class: Graph
        Checks whether two nodes in the graph are connected by the given edge type.
        Specified by:
        isConnected in class Graph<N,​E>
        Parameters:
        n1 - Node 1.
        e - The edge type.
        n2 - Node 2.
      • 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.
      • 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.