public static final class Grafo.NoDirigido<T>
extends java.lang.Object
implements java.lang.Iterable<T>
Modifier and Type | Field and Description |
---|---|
private java.util.Map<T,java.util.Set<T>> |
mGraph |
Constructor and Description |
---|
NoDirigido() |
Modifier and Type | Method and Description |
---|---|
void |
addEdge(T one,
T two)
Given two nodes, adds an arc of that length between those nodes.
|
boolean |
addNode(T node)
Adds a new node to the graph.
|
boolean |
containsNode(T node)
Returns whether a given node is contained in the graph.
|
boolean |
edgeExists(T one,
T two)
Given two endpoints, returns whether an edge exists between them.
|
java.util.Set<T> |
edgesFrom(T node)
Given a node in the graph, returns an immutable view of the edges
leaving that node.
|
boolean |
isEmpty()
Returns whether the graph is empty.
|
java.util.Iterator<T> |
iterator()
Returns an iterator that can traverse the nodes in the graph.
|
boolean |
nodeExists(T node)
Given a node, returns whether that node exists in the graph.
|
void |
removeEdge(T one,
T two)
Removes the edge between the indicated endpoints from the graph.
|
boolean |
removeNode(T node)
Remove a node from the graph.
|
int |
size()
Returns the number of nodes in the graph.
|
java.lang.String |
toString()
Returns a human-readable representation of the graph.
|
public boolean addNode(T node)
node
- The node to add.public boolean removeNode(T node)
node
- The node to remove.public boolean nodeExists(T node)
node
- The node in question.public void addEdge(T one, T two)
one
- The first node.two
- The second node.java.util.NoSuchElementException
- If either the start or destination nodes
do not exist.public void removeEdge(T one, T two)
one
- The start node.two
- The destination node.java.util.NoSuchElementException
- If either node is not in the graph.public boolean edgeExists(T one, T two)
one
- The first endpoint.two
- The second endpoint.java.util.NoSuchElementException
- If the endpoints are not nodes in the
graph.public java.util.Set<T> edgesFrom(T node)
node
- The node whose edges should be queried.java.util.NoSuchElementException
- If the node does not exist.public boolean containsNode(T node)
node
- The node to test for inclusion.public java.util.Iterator<T> iterator()
iterator
in interface java.lang.Iterable<T>
public int size()
public boolean isEmpty()
public java.lang.String toString()
toString
in class java.lang.Object