Class StateGraph
- java.lang.Object
 - 
- StateGraph
 
 
- 
public class StateGraph extends java.lang.ObjectThis class represents the adjacency relationships between US states. (More generally, it could be used to represent any unweighted directed graph.)- Version:
 - V2.0, 04/2021
 - Author:
 - Nathan Sprague
 
 
- 
- 
Constructor Summary
Constructors Constructor Description StateGraph(java.lang.String fileName)Build a StateGraph from a file. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearVisited()Clear the visited flag from all states.StategetState(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. 
 - 
 
- 
- 
Constructor Detail
- 
StateGraph
public StateGraph(java.lang.String fileName) throws java.io.FileNotFoundExceptionBuild 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.
 
 
- 
clearVisited
public void clearVisited()
Clear the visited flag from all states. 
 - 
 
 -