src/main/java/it/uniroma2/dicii/sabd/covidproject/Query1.java
/* Parse a line of the CSV dataset */
Parse a line of the CSV dataset
Parse a line of the CSV dataset
private static ItalianDailyStats parseInputLine(String line) {
        try {
            /* Extract fields of interest from the CSV line */
            CSVReader csvReader = new CSVReader(new StringReader(line));
            String[] csvFields = csvReader.readNext();
            csvReader.close();
            if (csvFields == null) {
                return null;
            }
            String date = csvFields[0];
            Integer cumulativeCured = Integer.parseInt(csvFields[1]);
            Integer cumulativeSwabs = Integer.parseInt(csvFields[2]);
            /* Parsing date field */
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_PATTERN);
            LocalDate formattedDate = LocalDate.parse(date, formatter);
            /* Build ItalianDailyStats object */
            ItalianDailyStats italianDailyStats = new ItalianDailyStats();
            italianDailyStats.setCumulativeCured(cumulativeCured);
            italianDailyStats.setCumulativeSwabs(cumulativeSwabs);
            italianDailyStats.setDayOfWeek(formattedDate.getDayOfWeek().getValue());
            italianDailyStats.setWeekOfYear(formattedDate.get(WeekFields.ISO.weekOfWeekBasedYear()));
            return italianDailyStats;
        } catch (CsvValidationException | IOException e) {
            return null;
        }
    }
private static ItalianDailyStats parseInputLine ( String line ) { try { /* Extract fields of interest from the CSV line */ CSVReader csvReader = new CSVReader ( new StringReader ( line ) ) ; String [ ] csvFields = csvReader . readNext ( ) ; csvReader . close ( ) ; if ( csvFields == null ) { return null ; } String date = csvFields [ 0 ] ; Integer cumulativeCured = Integer . parseInt ( csvFields [ 1 ] ) ; Integer cumulativeSwabs = Integer . parseInt ( csvFields [ 2 ] ) ; /* Parsing date field */ DateTimeFormatter formatter = DateTimeFormatter . ofPattern ( DATE_PATTERN ) ; LocalDate formattedDate = LocalDate . parse ( date , formatter ) ; /* Build ItalianDailyStats object */ ItalianDailyStats italianDailyStats = new ItalianDailyStats ( ) ; italianDailyStats . setCumulativeCured ( cumulativeCured ) ; italianDailyStats . setCumulativeSwabs ( cumulativeSwabs ) ; italianDailyStats . setDayOfWeek ( formattedDate . getDayOfWeek ( ) . getValue ( ) ) ; italianDailyStats . setWeekOfYear ( formattedDate . get ( WeekFields . ISO . weekOfWeekBasedYear ( ) ) ) ; return italianDailyStats ; } catch ( CsvValidationException | IOException e ) { return null ; } }
Parse a line of the CSV dataset
Parse a line of the CSV dataset