The attached screenshot below is the output of the dataset. This is my homework and I have been required to do all the coding according to the functional programming style. I have try to use Java Stream and map to parse the date, but I have no idea to group them by month and weeks, then sum the data.
Below is my code:
This is the function to read the file and store the data into arraylist
public ArrayList<List<String>> csvParser(String CSVFileName) throws IOException {
CSVParser csvParser = CSVParser.parse(Paths.get(CSVFileName), Charset.defaultCharset(), CSVFormat.DEFAULT);
return csvParser
.stream()
.map(i->i.toList())
.collect(Collectors.toCollection(ArrayList::new));
}
This is function to retrieve the column of the dataset and parse the date
public List<String> parseRetrievedDateList(List<String> dateToBeParsedList){
return dateToBeParsedList.stream()
.map(l-> {
return LocalDate.parse(l,DateTimeFormatter.ofPattern("M/d/yy")).format(DateTimeFormatter.ofPattern("yyyy/M/d"));
})
.collect(Collectors.toList());
}