Package toxi.util.datatypes
Class UndirectedGraph<N>
java.lang.Object
toxi.util.datatypes.UndirectedGraph<N>
Straightforward undirected graph implementation. Nodes are generic type N.
- Author:
- Paul Chew Created November, December 2007. For use in Delaunay/Voronoi code., toxi Updated July 2010, minor API changes to be better suited for toxiclibs
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a node.voidAdd a link.voiddisconnect(N nodeA, N nodeB) Remove the specified link.getConnectedNodesFor(N node) Report all the neighbors of node.getNodes()Returns an unmodifiable Set view of the nodes contained in this graph.voidRemove node and any links that use node.
-
Constructor Details
-
UndirectedGraph
public UndirectedGraph()
-
-
Method Details
-
add
Add a node. If node is already in graph then no change.- Parameters:
node- the node to add
-
connect
Add a link. If the link is already in graph then no change.- Parameters:
nodeA- one end of the linknodeB- the other end of the link- Throws:
NullPointerException- if either endpoint is not in graph
-
disconnect
Remove the specified link. If link not in graph, nothing happens.- Parameters:
nodeA- one end of the linknodeB- the other end of the link- Throws:
NullPointerException- if either endpoint is not in graph
-
getConnectedNodesFor
Report all the neighbors of node.- Parameters:
node- the node- Returns:
- the neighbors of node
- Throws:
NullPointerException- if node does not appear in graph
-
getNodes
Returns an unmodifiable Set view of the nodes contained in this graph. The set is backed by the graph, so changes to the graph are reflected in the set.- Returns:
- a Set view of the graph's node set
-
remove
Remove node and any links that use node. If node not in graph, nothing happens.- Parameters:
node- the node to remove.
-