public final class DirectedGraph<T>
extends java.lang.Object
implements java.lang.Iterable<T>, java.lang.Cloneable
Constructor and Description |
---|
DirectedGraph() |
Modifier and Type | Method and Description |
---|---|
void |
addEdge(T start,
T dest,
double length)
Given a start node, destination, and length, adds an arc from the
start node to the destination of the length.
|
boolean |
addNode(T node)
Adds a new node to the graph.
|
DirectedGraph<T> |
clone() |
java.util.Map<T,java.lang.Double> |
edgesFrom(T node)
Given a node in the graph, returns an immutable view of the edges
leaving that node, as a map from endpoints to costs.
|
java.util.Iterator<T> |
iterator()
Returns an iterator that can traverse the nodes in the graph.
|
void |
removeEdge(T start,
T dest)
Removes the edge from start to dest from the graph.
|
public DirectedGraph<T> clone()
clone
in class java.lang.Object
public boolean addNode(T node)
node
- The node to add.public void addEdge(T start, T dest, double length)
start
- The start node.dest
- The destination node.length
- The length of the edge.java.util.NoSuchElementException
- If either the start or destination nodes
do not exist.public void removeEdge(T start, T dest)
start
- The start node.dest
- The destination node.java.util.NoSuchElementException
- If either node is not in the graph.public java.util.Map<T,java.lang.Double> edgesFrom(T node)
node
- The node whose edges should be queried.java.util.NoSuchElementException
- If the node does not exist.