public class CodeFileProcessor
extends java.lang.Object
This class provides helper methods to read a code file and turn it into a map
from int
s to String
s.
Note that the field codeMap
and all methods in this class are
static because we don't need to make several codeFileProcessor
objects and have them maintain their own maps of codes. Instead, we simply
need a collection of useful methods to create a map and return it to the
calling method that will keep track of it.
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.String,java.lang.String> |
codeMap |
Constructor and Description |
---|
CodeFileProcessor() |
Modifier and Type | Method and Description |
---|---|
static java.util.Map<java.lang.String,java.lang.String> |
readCodeFile(java.lang.String fileName)
The method for reading code files.
|
public static java.util.Map<java.lang.String,java.lang.String> readCodeFile(java.lang.String fileName) throws java.io.IOException
Code files are auxiliary data files for Nooz data files. Code files are comma separated values files that associate code numbers with words. Each line of a code file should contain one numeral followed by one set of words.
Note that the field codeMap
and all methods in this class
are static because we don't need to make several
CodeFileProcessor
objects and have them maintain their own
lists of codes. Instead, we simply need a collection of useful methods to
create a code map and return it to the calling method that will keep
track of it. However, this means that when readCodeFile
is called, it needs to clear out its map, since the old map data will
still be in it. Also, the method that calls readCodeFile
will need to make its own copy of the map returned, not simply use a
pointer to the returned map.
Note that this program doesn't attempt to deal with I/O errors. This is allowable at this point to keep this project relatively simple and because we haven't covered this topic yet. However, this is something to be refined in the future.
fileName
- The name of the Nooz style data file to read.java.io.IOException
- If there is an I/O problem reading the data file.