Package de.bcxp.challenge.countries
Class CountryCsvParser
java.lang.Object
de.bcxp.challenge.common.documentParsing.csv.CsvParser
de.bcxp.challenge.countries.CountryCsvParser
- All Implemented Interfaces:
IDocumentParser
A CSV parser specialized for parsing country data entries.
CountryParser
extends CsvParser
to read CSV files containing country information,
including country name, population, and area. Each CSV record is mapped to a CountryEntry
.
The parser expects the CSV file to contain headers matching the field names: "Name", "Population", and "Area (km²)".
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCountryCsvParser
(char delimiter, Locale locale) Constructs aCountryCsvParser
with the specified CSV delimiter and Locale. -
Method Summary
Modifier and TypeMethodDescriptionprotected List<DocumentEntry>
getEntriesFromRecords
(Iterable<org.apache.commons.csv.CSVRecord> records) Converts a collection of CSV records into a list ofDocumentEntry
objects, specificallyCountryEntry
instances.Methods inherited from class de.bcxp.challenge.common.documentParsing.csv.CsvParser
getDelimiter, getLocale, parseDocument
-
Field Details
-
logger
private static final org.apache.logging.log4j.Logger logger -
NAME
- See Also:
-
POPULATION
- See Also:
-
AREA
- See Also:
-
-
Constructor Details
-
CountryCsvParser
Constructs aCountryCsvParser
with the specified CSV delimiter and Locale.- Parameters:
delimiter
- the character used to separate values in the CSV file.locale
- Locale used when parsing number
-
-
Method Details
-
getEntriesFromRecords
protected List<DocumentEntry> getEntriesFromRecords(Iterable<org.apache.commons.csv.CSVRecord> records) throws NumberFormatException, ParseException Converts a collection of CSV records into a list ofDocumentEntry
objects, specificallyCountryEntry
instances. Each record is expected to contain country-related data such as the name, population, and area.- Specified by:
getEntriesFromRecords
in classCsvParser
- Parameters:
records
- anIterable
ofCSVRecord
objects containing country data. Each record must provide values forNAME
,POPULATION
, andAREA
.- Returns:
- a
List
ofDocumentEntry
objects, where each entry corresponds to a parsedCountryEntry
from the CSV records. - Throws:
NumberFormatException
- if numeric values (population or area) cannot be parsed.ParseException
- if a parsing error occurs during number conversion (e.g., due to locale-specific formatting issues).
-