Class PuzzleLoader

java.lang.Object
  extended by PuzzleLoader

public class PuzzleLoader
extends java.lang.Object

PuzzleLoader reads and processes a puzzle definition file. The resulting puzzle object and error messages are available through accessors. For a description of the file format, please see the assignment description.

Version:
2005-10-30, JDK 1.5.0.5, Eclipse 3.1.0, Windows XP, CS 340, Fall 2005, Instructor: Pat Troy, TA: Nitin Jindal
Author:
Michael Leonhard (mleonhar)

Field Summary
private  java.util.ArrayList errors
           
private  java.lang.String fileName
           
private  Puzzle puzzle
           
 
Constructor Summary
PuzzleLoader(java.lang.String fileName)
          Constructor: reads a puzzle definition from the file with the specified file name and creates a puzzle object from it, warnings and error are stored in the object.
 
Method Summary
 java.util.List getErrors()
          Accessor for the list of errors that were generated when reading the file.
 java.lang.String getFileName()
          Accessor for file name string
 Puzzle getPuzzle()
          Accessor for loaded puzzle
private static Piece readPiece(java.io.BufferedReader reader)
          Reads a line, processes it, and returns a new Piece object
private  void readPuzzle(java.io.BufferedReader reader)
          Reads puzzle definition and creates a puzzle state object with pieces
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

puzzle

private Puzzle puzzle

errors

private java.util.ArrayList errors

fileName

private java.lang.String fileName
Constructor Detail

PuzzleLoader

public PuzzleLoader(java.lang.String fileName)
Constructor: reads a puzzle definition from the file with the specified file name and creates a puzzle object from it, warnings and error are stored in the object.

Parameters:
fileName - name of a file from which to read a puzzle definition
Method Detail

readPuzzle

private void readPuzzle(java.io.BufferedReader reader)
                 throws PuzzleException,
                        java.io.IOException
Reads puzzle definition and creates a puzzle state object with pieces

Parameters:
reader - the source of the line
Throws:
PuzzleException - if the file doesn't define a valid puzzle
java.io.IOException - if the file cannot be read

readPiece

private static Piece readPiece(java.io.BufferedReader reader)
                        throws java.io.IOException,
                               java.io.EOFException,
                               PuzzleException
Reads a line, processes it, and returns a new Piece object

Parameters:
reader - the source of the line
Returns:
the piece represented by the data in the line
Throws:
java.io.IOException - if the line cannot be read
java.io.EOFException - when the end of the file is reached
PuzzleException - if the line contains an invalid piece definition

getFileName

public java.lang.String getFileName()
Accessor for file name string

Returns:
the fileName.

getPuzzle

public Puzzle getPuzzle()
Accessor for loaded puzzle

Returns:
the puzzle, or null the puzzle could not be loaded

getErrors

public java.util.List getErrors()
Accessor for the list of errors that were generated when reading the file. If the puzzle could not be loaded (getPuzzle() returns null), the cause of error will be the last item in the errors list.

Returns:
the list of errors Strings