Class StateGraph

java.lang.Object
  extended by StateGraph

public class StateGraph
extends java.lang.Object

This class represents the adjacency relationships between US states. (More generally, it could be used to represent any unweighted directed graph.)

Version:
V1.0, 03/2012
Author:
Nathan Sprague

Constructor Summary
StateGraph(java.lang.String fileName)
          Build a StateGraph from a file.
 
Method Summary
 State getState(java.lang.String name)
          Return the vertex with the indicated name.
 java.util.ArrayList<State> getStates()
          Return a list of all vertices in the graph.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StateGraph

public StateGraph(java.lang.String fileName)
           throws java.io.FileNotFoundException
Build a StateGraph from a file. The file format is one state per line followed by a comma separated list of neighboring states. For example, the first two lines might look like the following:
 Alaska
 Alabama,Mississippi,Tennessee,Georgia,Florida
 
No state may be listed as a neighbor if it does not begin some line in the file.

Parameters:
fileName - The name of the file containing the graph specification.
Throws:
java.io.FileNotFoundException - If the file cannot be opened for reading.
Method Detail

getStates

public java.util.ArrayList<State> getStates()
Return a list of all vertices in the graph.

Returns:
The list of vertices.

getState

public State getState(java.lang.String name)
Return the vertex with the indicated name.

Parameters:
name - The name of the desired State.
Returns:
The requested State, or null if it does not exist.