edu.hawaii.ics.yucheng
Class Graph

java.lang.Object
  extended by edu.hawaii.ics.yucheng.Graph
All Implemented Interfaces:
java.lang.Iterable<Edge>

final class Graph
extends java.lang.Object
implements java.lang.Iterable<Edge>

A weighted, connected, undirected graph. This class is immutable.


Field Summary
private  java.util.ArrayList<Edge> myEdges
           
private  java.net.URL myUrl
           
private  float[] myVertices
           
 
Constructor Summary
Graph(float[] vertices, java.util.Collection<Edge> edges)
          Initializes a new instance of the class.
Graph(java.util.Scanner scanner, java.net.URL url)
          Initializes a new instance of the class.
 
Method Summary
 Edge edgeAt(int index)
          Returns the edge at the specified index.
 int edges()
          Returns the number of edges.
 java.util.Iterator<Edge> iterator()
          Returns an iterator for the edges.
 java.lang.String toString()
          Returns the string representation of the class.
 java.net.URL url()
          Returns the URL, if one was assigned.
private static void verifyConnectedGraph(Graph graph)
          This method verifies a graph is connected.
private static void verifyNoDuplicateEdges(java.util.Collection<Edge> edges)
          Verifies the graph has no duplicate edges.
 float vertexAt(int index)
          Returns the vertex weight at the specified index.
 int vertices()
          Returns the number of vertices.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

myEdges

private final java.util.ArrayList<Edge> myEdges

myUrl

private final java.net.URL myUrl

myVertices

private final float[] myVertices
Constructor Detail

Graph

public Graph(float[] vertices,
             java.util.Collection<Edge> edges)
Initializes a new instance of the class.

Parameters:
vertices - The vertices.
edges - The edges.

Graph

public Graph(java.util.Scanner scanner,
             java.net.URL url)
      throws GraphException
Initializes a new instance of the class.

Parameters:
scanner - The scanner.
url - The url.
Throws:
GraphException - Thrown if there are any errors reading from the scanner.
Method Detail

verifyConnectedGraph

private static void verifyConnectedGraph(Graph graph)
This method verifies a graph is connected.

Parameters:
graph - The graph.
Throws:
GraphException - if the graph is invalid.

verifyNoDuplicateEdges

private static void verifyNoDuplicateEdges(java.util.Collection<Edge> edges)
Verifies the graph has no duplicate edges.

Parameters:
edges - The collection of edges.
Throws:
GraphException - if the graph is invalid.

edgeAt

public Edge edgeAt(int index)
Returns the edge at the specified index.

Parameters:
index - The index.
Returns:
The edge.

edges

public int edges()
Returns the number of edges.

Returns:
The number of edges.

iterator

public java.util.Iterator<Edge> iterator()
Returns an iterator for the edges.

Specified by:
iterator in interface java.lang.Iterable<Edge>
Returns:
An Edge iterator.

toString

public java.lang.String toString()
Returns the string representation of the class.

Overrides:
toString in class java.lang.Object
Returns:
The string representation of the class.

url

public java.net.URL url()
Returns the URL, if one was assigned.

Returns:
The URL.

vertexAt

public float vertexAt(int index)
Returns the vertex weight at the specified index.

Parameters:
index - The index.
Returns:
The weight.

vertices

public int vertices()
Returns the number of vertices.

Returns:
The number of vertices.