Class RecordParser<T extends Record>

java.lang.Object
com.github.jamesross03.pop_parser.RecordParser<T>
Type Parameters:
T - subclass of Record to be parsed

public class RecordParser<T extends Record> extends Object
Parser for CSV input files containing records, where type T is a subclass of the Record abstract class representing the type of records (e.g birth).
  • Constructor Details

    • RecordParser

      public RecordParser(Class<T> type, RecordFormat format)
      Initialises a new instance of RecordParser for parsing records of type T from input in a given format.
      Parameters:
      type - class of Record subclass to parse
      format - format of input
  • Method Details

    • parse

      public List<T> parse(String filepath) throws IOException, com.opencsv.exceptions.CsvValidationException
      Parses all lines from an input file into objects of Record subclass T.
      Parameters:
      filepath - filepath of input CSV
      Returns:
      list containing the parsed T objects
      Throws:
      IOException - if errors occur during file-reading
      com.opencsv.exceptions.CsvValidationException - if CSV is invalid or incorrectly formatted
    • parse

      public List<T> parse(Stream<String> csvStream) throws IOException, com.opencsv.exceptions.CsvValidationException
      Parses all lines from an input stream of CSV data (with headers) into objects of Record subclass T.
      Parameters:
      csvStream - input stream of CSV data (incl. headers)
      Returns:
      list containing the parsed T objects
      Throws:
      IOException - if errors occur during file-reading
      com.opencsv.exceptions.CsvValidationException - if CSV is invalid or incorrectly formatted