Constructor and Description |
---|
DirectedGraph() |
Modifier and Type | Method and Description |
---|---|
void |
addEdge(T start,
T dest)
Given a start node, and a destination, adds an arc from the start node to the destination.
|
boolean |
addNode(T node)
Adds a new node to the graph.
|
boolean |
edgeExists(T start,
T end)
Given two nodes in the graph, returns whether there is an edge from the first node to the second node.
|
Set<T> |
edgesFrom(T node)
Given a node in the graph, returns an immutable view of the edges leaving that node as a set of endpoints.
|
boolean |
isEmpty()
Returns whether the graph is empty.
|
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.
|
int |
size()
Returns the number of nodes in the graph.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public boolean addNode(T node)
node
- The node to add.public void addEdge(T start, T dest)
start
- The start node.dest
- The destination node.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.NoSuchElementException
- If either node is not in the graph.public boolean edgeExists(T start, T end)
start
- The start node.end
- The destination node.NoSuchElementException
- If either endpoint does not exist.public Set<T> edgesFrom(T node)
node
- The node whose edges should be queried.NoSuchElementException
- If the node does not exist.public Iterator<T> iterator()
public int size()
public boolean isEmpty()
Copyright © 2000–2020 Apache Software Foundation. All rights reserved.