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 (except for, possibly, the first line), and possibly also comment lines, from the file
    `CsvData.BasicLineEntry` | `header` | Unless noHeader=true, this is where we put the first line of the file.

  - ### Constructor Summary

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

  - ### 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

    - #### entries

          public CsvData.LineEntry[] entries

      All data lines (except for, possibly, the first line), and possibly also comment lines, from the file

    - #### header

          public CsvData.BasicLineEntry header

      Unless noHeader=true, this is where we put the first line of the file. The leading '#', if present, is removed.

  - ### Constructor Detail

    - #### CsvData

          public CsvData​(File csvFile)
                  throws IOException,
                         IllegalInputException

      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 read
        `noHeader` - 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 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).