Package de.bcxp.challenge.weather
Class WeatherCsvParser
java.lang.Object
de.bcxp.challenge.common.documentParsing.csv.CsvParser
de.bcxp.challenge.weather.WeatherCsvParser
- All Implemented Interfaces:
IDocumentParser
A CSV parser specifically for weather data entries.
WeatherCsvParser
extends CsvParser
to parse CSV files containing daily weather information.
Each record is expected to contain fields such as day, maximum temperature, and minimum temperature,
which are mapped to WeatherEntry
objects.
This parser assumes that the CSV file includes a header row.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionWeatherCsvParser
(char delimiter, Locale locale) Constructs aWeatherCsvParser
with the specified CSV delimiter. -
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, specificallyWeatherEntry
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:
-
MAX_TEMP
- See Also:
-
MIN_TEMP
- See Also:
-
-
Constructor Details
-
WeatherCsvParser
Constructs aWeatherCsvParser
with the specified CSV delimiter.- 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, specificallyWeatherEntry
instances. Each record is expected to contain weather-related data such as the name, maximum temperature, and minimum temperature.- Specified by:
getEntriesFromRecords
in classCsvParser
- Parameters:
records
- anIterable
ofCSVRecord
objects containing weather data. Each record must provide values forNAME
,MAX_TEMP
, andMIN_TEMP
.- Returns:
- a
List
ofDocumentEntry
objects, where each entry corresponds to a parsedWeatherEntry
from the CSV records. - Throws:
NumberFormatException
- if temperature values cannot be parsed as doubles.ParseException
- if a parsing error occurs during number conversion (e.g., due to locale-specific formatting issues).
-