cl.cromer.estructuras

## Class Grafo.NoDirigido<T>

- java.lang.Object
- - cl.cromer.estructuras.Grafo.NoDirigido<T>

All Implemented Interfaces:
  java.lang.Iterable<T>

Enclosing class:
  Grafo

    public static final class Grafo.NoDirigido<T>
    extends java.lang.Object
    implements java.lang.Iterable<T>

Author: Keith Schwarz (htiek@cs.stanford.edu)

### Field Summary

Fields
`private java.util.Map<T,java.util.Set<T>>` `mGraph`

### Constructor Summary

Constructors
Constructor and Description
`NoDirigido()`

### Method Summary

All Methods Instance Methods Concrete Methods
`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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface java.lang.Iterable

`forEach, spliterator`

### Field Detail

#### mGraph

    private final java.util.Map<T,java.util.Set<T>> mGraph

### Constructor Detail

#### NoDirigido

    public NoDirigido()

### Method Detail

#### addNode

    public boolean addNode(T node)

Adds a new node to the graph. If the node already exists, this function is a no-op.

Parameters:
  `node` - The node to add.
Returns:
  Whether or not the node was added.

#### removeNode

    public boolean removeNode(T node)

Remove a node from the graph.

Parameters:
  `node` - The node to remove.
Returns:
  Whether or not the node was removed.

#### nodeExists

    public boolean nodeExists(T node)

Given a node, returns whether that node exists in the graph.

Parameters:
  `node` - The node in question.
Returns:
  Whether that node eixsts in the graph.

#### addEdge

    public void addEdge(T one,
                        T two)

Given two nodes, adds an arc of that length between those nodes. If either endpoint does not exist in the graph, throws a NoSuchElementException.

Parameters:
  `one` - The first node.
  `two` - The second node.
Throws:
  `java.util.NoSuchElementException` - If either the start or destination nodes do not exist.

#### removeEdge

    public void removeEdge(T one,
                           T two)

Removes the edge between the indicated endpoints from the graph. If the edge does not exist, this operation is a no-op. If either endpoint does not exist, this throws a NoSuchElementException.

Parameters:
  `one` - The start node.
  `two` - The destination node.
Throws:
  `java.util.NoSuchElementException` - If either node is not in the graph.

#### edgeExists

    public boolean edgeExists(T one,
                              T two)

Given two endpoints, returns whether an edge exists between them. If either endpoint does not exist in the graph, throws a NoSuchElementException.

Parameters:
  `one` - The first endpoint.
  `two` - The second endpoint.
Returns:
  Whether an edge exists between the endpoints.
Throws:
  `java.util.NoSuchElementException` - If the endpoints are not nodes in the graph.

#### edgesFrom

    public java.util.Set<T> edgesFrom(T node)

Given a node in the graph, returns an immutable view of the edges leaving that node.

Parameters:
  `node` - The node whose edges should be queried.
Returns:
  An immutable view of the edges leaving that node.
Throws:
  `java.util.NoSuchElementException` - If the node does not exist.

#### containsNode

    public boolean containsNode(T node)

Returns whether a given node is contained in the graph.

Parameters:
  `node` - The node to test for inclusion.
Returns:
  Whether that node is contained in the graph.

#### iterator

    public java.util.Iterator<T> iterator()

Returns an iterator that can traverse the nodes in the graph.

Specified by:
  `iterator` in interface `java.lang.Iterable<T>`
Returns:
  An iterator that traverses the nodes in the graph.

#### size

    public int size()

Returns the number of nodes in the graph.

Returns:
  The number of nodes in the graph.

#### isEmpty

    public boolean isEmpty()

Returns whether the graph is empty.

Returns:
  Whether the graph is empty.

#### toString

    public java.lang.String toString()

Returns a human-readable representation of the graph.

Overrides:
  `toString` in class `java.lang.Object`
Returns:
  A human-readable representation of the graph.