I have a map of maps: Map<String,<LocalDate,List<Integer>>
. In each iteration of loops, I need to insert the daily cases of each country from the List<List<String>
into each day.Each day will only limit to one record. But my current attempt is fail because it will append all the list in the first date in the table.
List<List<String>
[Province/State, Country/Region, Lat, Long, 1/22/20, 1/23/20, 1/24/20, 1/25/20, 1/26/20, 1/27/20]
[, Afghanistan, 33.93911, 67.709953, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]
[, Angola, -11.2027, 17.8739, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0]
[, Angeria, -12.3047, 17.8739, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0]
[, Andora, -13.2087, 17.8739, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0]
Desired Output
Afghanistan --> {2020-01-22=[0], 2020-01-23=[0], 2020-01-24=[3], 2020-01-25=[0], 2020-01-26=[0]}
Angola --> {2020-01-22=[0], 2020-01-23=[0], 2020-01-24=[0], 2020-01-25=[0], 2020-01-26=[0]}
Angeria --> {2020-01-22=[0], 2020-01-23=[0], 2020-01-24=[0], 2020-01-25=[0], 2020-01-26=[0]}
Andora --> {2020-01-22=[0], 2020-01-23=[0], 2020-01-24=[0], 2020-01-25=[0], 2020-01-26=[0]}
My attempt
Map<String, Map<LocalDate, List<Integer>>> dataMap = new LinkedHashMap<>();
Map<LocalDate,List<Integer>> innerMap = new LinkedHashMap<>();
IntStream //functional for loop to add the date as keys into the map
.range(0,covidListWithoutCountryDetails.get(0).size())
.forEach(i->
innerMap
.put(keys.get(i),new ArrayList<>()
)
);
IntStream //functional for loop to add the country keys into map
.range(0,mapKeys.size())
.forEach(i->dataMap
.put(mapKeys.get(i), innerMap));