I have a Map collection in java
Map<AreaDate, Map<AreaCategory, List<Location>> dateWiseAreas
using java 8 I want to build a map of
Map<Area, Map<AreaCategory, List<Location>> areas
I used the below logic and I get a duplicate key error saying Area key is duplicate
Map<Area, Map<AreaCategory, List<Location>> areas = dateWiseAreas.entrySet().stream()
.collect(toMap(k -> k.getKey().area(),
v -> v.getValue()
.entrySet()
.stream()
.collect(Collectors.toMap(Map.Entry::getKey(), Map::Entry::getValue,
(oldValue,newValue) -> oldValue, LinkedHashMap::new))));
Java classes
Area {
EUROPE,
AUSTRALIA,
ASIA;
}
AreaDate {
Area area;
LocalDate date;
int priority;
}
AreaCategory {
NORTH,
SOUTH,
WEST,
EAST;
}
Location {
int xaxis;
int yaxis;
}