Class LinkedUndirectedGraph<N,E>
- java.lang.Object
-
- com.google.javascript.jscomp.graph.Graph<N,E>
-
- com.google.javascript.jscomp.graph.UndiGraph<N,E>
-
- com.google.javascript.jscomp.graph.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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.javascript.jscomp.graph.UndiGraph
UndiGraph.UndiGraphEdge<N,E>, UndiGraph.UndiGraphNode<N,E>
-
Nested classes/interfaces inherited from class com.google.javascript.jscomp.graph.Graph
Graph.GraphEdge<N,E>
-
Nested classes/interfaces inherited from interface com.google.javascript.jscomp.graph.GraphvizGraph
GraphvizGraph.GraphvizEdge, GraphvizGraph.GraphvizNode
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedLinkedUndirectedGraph(boolean useNodeAnnotations, boolean useEdgeAnnotations)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconnect(N srcValue, E edgeValue, N destValue)Connects two nodes in the graph with an edge.static <N,E>
LinkedUndirectedGraph<N,E>create()GraphNode<N,E>createNode(N value)Gets a node from the graph given a value.UndiGraph.UndiGraphNode<N,E>createUndirectedGraphNode(N nodeValue)voiddisconnect(N srcValue, N destValue)Disconnects two nodes in the graph by removing all edges between them.java.util.List<Graph.GraphEdge<N,E>>getEdges()Gets an immutable list of all edges.java.util.List<Graph.GraphEdge<N,E>>getEdges(N n1, N n2)Retrieves an edge from the graph.Graph.GraphEdge<N,E>getFirstEdge(N n1, N n2)Retrieves any edge from the graph.java.util.List<GraphvizGraph.GraphvizEdge>getGraphvizEdges()Retrieve a list of edges in the graph.java.util.List<GraphvizGraph.GraphvizNode>getGraphvizNodes()Retrieve a list of nodes in the graph.java.lang.StringgetName()Name of the graph.java.util.List<GraphNode<N,E>>getNeighborNodes(N value)Gets the neighboring nodes.GraphNode<N,E>getNode(N value)Gets a node from the graph given a value.intgetNodeCount()intgetNodeDegree(N value)Gets the degree of a node.java.util.Collection<GraphNode<N,E>>getNodes()Gets an immutable list of all nodes.java.util.List<UndiGraph.UndiGraphEdge<N,E>>getUndirectedGraphEdges(N n1, N n2)UndiGraph.UndiGraphNode<N,E>getUndirectedGraphNode(N nodeValue)java.util.Collection<UndiGraph.UndiGraphNode<N,E>>getUndirectedGraphNodes()booleanisConnected(N n1, E e, N n2)Checks whether two nodes in the graph are connected by the given edge type.booleanisConnected(N n1, N n2)Checks whether two nodes in the graph are connected.booleanisDirected()Graph type.SubGraph<N,E>newSubGraph()Returns an empty SubGraph for this Graph.-
Methods inherited from class com.google.javascript.jscomp.graph.Graph
clearEdgeAnnotations, clearNodeAnnotations, connectIfNotFound, getWeight, hasNode, popEdgeAnnotations, popNodeAnnotations, pushEdgeAnnotations, pushNodeAnnotations
-
-
-
-
Method Detail
-
newSubGraph
public SubGraph<N,E> newSubGraph()
Description copied from interface:AdjacencyGraphReturns an empty SubGraph for this Graph.- Specified by:
newSubGraphin interfaceAdjacencyGraph<N,E>
-
create
public static <N,E> LinkedUndirectedGraph<N,E> create()
-
connect
public void connect(N srcValue, E edgeValue, N destValue)
Description copied from class:GraphConnects two nodes in the graph with an edge.
-
disconnect
public void disconnect(N srcValue, N destValue)
Description copied from class:GraphDisconnects two nodes in the graph by removing all edges between them.- Specified by:
disconnectin classGraph<N,E>- Parameters:
srcValue- First node.destValue- Second node.
-
createUndirectedGraphNode
public UndiGraph.UndiGraphNode<N,E> createUndirectedGraphNode(N nodeValue)
-
getNeighborNodes
public java.util.List<GraphNode<N,E>> getNeighborNodes(N value)
Description copied from class:GraphGets the neighboring nodes.- Specified by:
getNeighborNodesin classGraph<N,E>- Parameters:
value- The node's value.- Returns:
- A list of neighboring nodes.
-
getUndirectedGraphEdges
public java.util.List<UndiGraph.UndiGraphEdge<N,E>> getUndirectedGraphEdges(N n1, N n2)
-
getUndirectedGraphNode
public UndiGraph.UndiGraphNode<N,E> getUndirectedGraphNode(N nodeValue)
- Specified by:
getUndirectedGraphNodein classUndiGraph<N,E>
-
getUndirectedGraphNodes
public java.util.Collection<UndiGraph.UndiGraphNode<N,E>> getUndirectedGraphNodes()
-
createNode
public GraphNode<N,E> createNode(N value)
Description copied from class:GraphGets 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 usingObject.equals.- Specified by:
createNodein classGraph<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:GraphRetrieves an edge from the graph.
-
getEdges
public java.util.List<Graph.GraphEdge<N,E>> getEdges()
Description copied from class:GraphGets an immutable list of all edges.
-
getFirstEdge
public Graph.GraphEdge<N,E> getFirstEdge(N n1, N n2)
Description copied from class:GraphRetrieves any edge from the graph.- Specified by:
getFirstEdgein classGraph<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:AdjacencyGraphGets a node from the graph given a value. Values equality are compared usingObject.equals.- Specified by:
getNodein interfaceAdjacencyGraph<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:GraphChecks whether two nodes in the graph are connected.- Specified by:
isConnectedin classGraph<N,E>- Parameters:
n1- Node 1.n2- Node 2.- Returns:
trueif the two nodes are connected.
-
isConnected
public boolean isConnected(N n1, E e, N n2)
Description copied from class:GraphChecks whether two nodes in the graph are connected by the given edge type.- Specified by:
isConnectedin classGraph<N,E>- Parameters:
n1- Node 1.e- The edge type.n2- Node 2.
-
getGraphvizEdges
public java.util.List<GraphvizGraph.GraphvizEdge> getGraphvizEdges()
Description copied from interface:GraphvizGraphRetrieve a list of edges in the graph.- Specified by:
getGraphvizEdgesin interfaceGraphvizGraph- Returns:
- A list of edges in the graph.
-
getName
public java.lang.String getName()
Description copied from interface:GraphvizGraphName of the graph.- Specified by:
getNamein interfaceGraphvizGraph- Returns:
- Name of the graph.
-
getGraphvizNodes
public java.util.List<GraphvizGraph.GraphvizNode> getGraphvizNodes()
Description copied from interface:GraphvizGraphRetrieve a list of nodes in the graph.- Specified by:
getGraphvizNodesin interfaceGraphvizGraph- Returns:
- A list of nodes in the graph.
-
isDirected
public boolean isDirected()
Description copied from interface:GraphvizGraphGraph type.- Specified by:
isDirectedin interfaceGraphvizGraph- Returns:
- True if the graph is a directed graph.
-
getNodes
public java.util.Collection<GraphNode<N,E>> getNodes()
Description copied from class:GraphGets an immutable list of all nodes.
-
getNodeCount
public int getNodeCount()
- Specified by:
getNodeCountin interfaceAdjacencyGraph<N,E>- Specified by:
getNodeCountin classGraph<N,E>
-
-