Package edu.wisc.game.util
Class CsvData
java.lang.Object
edu.wisc.game.util.CsvData
Represents the entire content of a CSV file. The file may consist
of an optional header line and any number of data lines and
(possibly) also comment lines. Comment lines may or may not be
stored. Child classes add specific semantics for a particula type of
CSV files.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
Stores a comment line from the CSV file.static interface
-
Field Summary
FieldsModifier and TypeFieldDescriptionAll data lines (except for, possibly, the first line), and possibly also comment lines, from the fileUnless noHeader=true, this is where we put the first line of the file. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected CsvData.LineEntry
Child classes would override this, typically with a wrapper around the constructor for an object that represents the content of a single linemkNewHeader
(String extras) Creates a new header line by appending some extra columns to the stored header line of this file.toMap()
Creates a hash map that includes all entries from the CSV file that have keys (i.e., normally, all data lines).
-
Field Details
-
entries
All data lines (except for, possibly, the first line), and possibly also comment lines, from the file -
header
Unless noHeader=true, this is where we put the first line of the file. The leading '#', if present, is removed.
-
-
Constructor Details
-
CsvData
- Throws:
IOException
IllegalInputException
-
CsvData
public CsvData(File csvFile, boolean noHeader, boolean keepComments, int[] legalLengths) throws IOException, IllegalInputException Creates a CsvData object from the content of a CSV file.- Parameters:
csvFile
- File to readnoHeader
- If true, we don't expect the input file to contain a header; the file only should have data lines and optional comment lines. (In reality, of course, the first line may still have header semantics, but it's up to the user of this class to separate and process it). If false, we look at the first line of the file to figure if it's a header line or data line or comment line, and process it appropriately.keepComments
- If true, comment lines from the input file are stored in the object being created; otherwise, they are discarded.legalLengths
- If this is not null, it specifies how many columns the file's lines may contain. For example, {4,6} means that the lines must contain 4 or 6 columns.- Throws:
IOException
IllegalInputException
-
CsvData
public CsvData(File csvFile, Reader r, boolean noHeader, boolean keepComments, int[] legalLengths) throws IOException, IllegalInputException - Parameters:
csvFile
- only passed so that the name of it can be used in error messages. May be null if the data come not from the file.r
- The data to read- Throws:
IOException
IllegalInputException
-
-
Method Details
-
mkNewHeader
Creates a new header line by appending some extra columns to the stored header line of this file.- Parameters:
extras
- ",f1,f2,..."- Throws:
IllegalInputException
-
mkEntry
Child classes would override this, typically with a wrapper around the constructor for an object that represents the content of a single line- Throws:
IllegalInputException
-
toMap
Creates a hash map that includes all entries from the CSV file that have keys (i.e., normally, all data lines).
-