org.samcrow.io
Class BasicIO

java.lang.Object
  extended by org.samcrow.io.IOBase
      extended by org.samcrow.io.BasicIO

public class BasicIO
extends IOBase

Handles IO for a basic file with a non-standard format

The format is as follows:
Node <hash> <x> <y> "<name>";
if name is nonexistent; the node is considered a waypoint instead of a destination
Link <start_node_hash> <end_node_hash> <speed>
#comment

Any Link must appear in the file after both of the Nodes that it links.

Author:
Sam Crow

Field Summary
private static java.lang.String LINK
          The word at the start of a line that indicates that the line contains link information
private static java.lang.String NODE
          The word at the start of a line that indicates that the line contains node information
 
Fields inherited from class org.samcrow.io.IOBase
file
 
Constructor Summary
BasicIO(java.io.File inFile)
          Constructor with a given File object
BasicIO(java.lang.String inFilename)
          Construct this with a given filename
 
Method Summary
 IOResponse read()
          Read the file; get the nodes and links defined in it.
This method is designed to be relatively robust.
 void write(java.util.Collection<Node> nodes, java.util.Collection<Link> links)
          Writes to the file that this instance uses
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NODE

private static final java.lang.String NODE
The word at the start of a line that indicates that the line contains node information

See Also:
Constant Field Values

LINK

private static final java.lang.String LINK
The word at the start of a line that indicates that the line contains link information

See Also:
Constant Field Values
Constructor Detail

BasicIO

public BasicIO(java.lang.String inFilename)
Construct this with a given filename

Parameters:
inFilename -

BasicIO

public BasicIO(java.io.File inFile)
Constructor with a given File object

Parameters:
inFile - the File object
Method Detail

write

public void write(java.util.Collection<Node> nodes,
                  java.util.Collection<Link> links)
Description copied from class: IOBase
Writes to the file that this instance uses

Specified by:
write in class IOBase
Parameters:
nodes - the nodes to write
links - the links to write

read

public IOResponse read()
                throws java.text.ParseException
Description copied from class: IOBase
Read the file; get the nodes and links defined in it.
This method is designed to be relatively robust. It will attempt to load data for every data entry that is encountered. It will ignore lines with malformed data. It will throw an exception only if an IOException is encountered. When attempting to read an empty file, it will simply return an IOResponse with empty Collections.

Specified by:
read in class IOBase
Returns:
IOResponse with the information in the file
Throws:
java.text.ParseException - if the file is invalid