cs2110.assignment1
Class SpeciesReader
java.lang.Object
cs2110.assignment1.SpeciesReader
public abstract class SpeciesReader
- extends java.lang.Object
Reads Species records from the filesystem.
Class to read a CS2110 species data file. Species data files typically end
with the extension ".dat", and contain a list of Attribute="Value" pairs,
like this:
Name="Strats Squirrel"
LatinName="Leapus Longus"
Image="Strats_Squirrel.png"
DNA="ITTAAATTYAYYTYAYIAAITYAIYIYAATTYATTYYTTYTYA"
The DNA string will be longer than the one shown; ours have about 50,000
characters each. The set of data files is in a ZIP file you should download
from the project page, along with the set of animal images (one PNG file per
animal). Your solution should ignore extra white spaces (blanks or tabs), for
example in the line,
Name = "Strats Squirrel"
Note that the equals sign and quotes are not part of the attribute or value.
SpeciesReader should also handle blank lines and lines with
commands other than those shown above (but always in the identical format
Attribute = "Value")
These four attributes {Name, LatinName, Image, DNA} are the only attributes
in our dataset. You would do well to represent them with a static enum; doing
so will improve the type safety of your program. If your program encounters
an attribute not listed above, its behavior is officially undefined. You're
welcome to throw an exception in this case.
The ideal tool for parsing attributes and values from lines of the file is
regular expressions. For this assignment, you don't have to know how to use
them, but in the real world a regex is the fastest and most secure solution.
www.Rubular.com is a great tool for developing regular expressions.
Be sure to close the file when EOF is reached!
- Author:
- CS2110 Course Staff
Method Summary |
abstract Species |
readSpecies(java.io.File file)
Parse a Species from a java.io.File object |
abstract Species |
readSpecies(java.lang.String filename)
Parse a Species from a named file, given as a String |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SpeciesReader
public SpeciesReader()
readSpecies
public abstract Species readSpecies(java.lang.String filename)
throws java.io.IOException
- Parse a Species from a named file, given as a String
- Parameters:
filename
-
- Returns:
-
- Throws:
java.io.IOException
- Thrown if problems are encountered while reading the file
readSpecies
public abstract Species readSpecies(java.io.File file)
throws java.io.IOException
- Parse a Species from a java.io.File object
- Parameters:
file
-
- Returns:
-
- Throws:
java.io.IOException
- Thrown if problems are encountered while reading the file