Class RecordParser<T extends Record>
java.lang.Object
com.github.jamesross03.pop_parser.RecordParser<T>
- Type Parameters:
T
- subclass ofRecord
to be parsed
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 Summary
ConstructorsConstructorDescriptionRecordParser
(Class<T> type, RecordFormat format) Initialises a new instance ofRecordParser
for parsing records of typeT
from input in a given format. -
Method Summary
-
Constructor Details
-
RecordParser
Initialises a new instance ofRecordParser
for parsing records of typeT
from input in a given format.- Parameters:
type
- class ofRecord
subclass to parseformat
- 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 ofRecord
subclassT
.- Parameters:
filepath
- filepath of input CSV- Returns:
- list containing the parsed
T
objects - Throws:
IOException
- if errors occur during file-readingcom.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 ofRecord
subclassT
.- Parameters:
csvStream
- input stream of CSV data (incl. headers)- Returns:
- list containing the parsed
T
objects - Throws:
IOException
- if errors occur during file-readingcom.opencsv.exceptions.CsvValidationException
- if CSV is invalid or incorrectly formatted
-