Package edu.wisc.game.util

## Class CsvData

- java.lang.Object
- - edu.wisc.game.util.CsvData

-     public class CsvData
      extends Object

  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 Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `CsvData.BasicLineEntry` |
    `static class` | `CsvData.CommentEntry` | Stores a comment line from the CSV file.
    `static interface` | `CsvData.LineEntry` |

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `CsvData.LineEntry[]` | `entries` | All data lines, and possibly also comment lines, from the file
    `String` | `header` | The header line of the CSV file.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `CsvData​(File csvFile)` |
    `CsvData​(File csvFile, boolean neverHeader, boolean keepComments, int[] legalLengths)` | Creates a CsvData object from the content of a CSV file.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `protected CsvData.LineEntry` | `mkEntry​(String[] csv, int colCnt)` | Child classes would override this, typically with a wrapper around the constructor for an object that represents the content of a single line
    `String` | `mkNewHeader​(String extras)` | Creates a new header line by appending some extra columns to the stored header line of this file.
    `HashMap<String,​CsvData.LineEntry>` | `toMap()` | Creates a hash map that includes all entries from the CSV file that have keys (i.e., normally, all data lines).

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### header

          public String header

      The header line of the CSV file. It is not analyzed, but stored, and can be printed later. A file may or may not have a header line; to decide if there is one, we use a cludge: if the first letter of the first line is a digit, it's not a header, otehrwise it is

    - #### entries

          public CsvData.LineEntry[] entries

      All data lines, and possibly also comment lines, from the file

  - ### Constructor Detail

    - #### CsvData

          public CsvData​(File csvFile)
                  throws IOException,
                         IllegalInputException

      Throws:
        `IOException`
        `IllegalInputException`

    - #### CsvData

          public CsvData​(File csvFile,
                         boolean neverHeader,
                         boolean keepComments,
                         int[] legalLengths)
                  throws IOException,
                         IllegalInputException

      Creates a CsvData object from the content of a CSV file.
      Parameters:
        `csvFile` - File to read
        `neverHeader` - If true, we don't expect the input file to connect a header; the file only should have data lines and optional comment lines. 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`

  - ### Method Detail

    - #### mkNewHeader

          public String mkNewHeader​(String extras)
                             throws IllegalInputException

      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

          protected CsvData.LineEntry mkEntry​(String[] csv,
                                              int colCnt)
                                       throws IllegalInputException

      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

          public HashMap<String,​CsvData.LineEntry> toMap()

      Creates a hash map that includes all entries from the CSV file that have keys (i.e., normally, all data lines).