Lets assume I have a list of walls listOfWalls and that each wall object has following hierarchy:
wall -> wallType -> wallEntry(list of wall materials ) -> wallMaterial -> wallMaterialType(enum type),
so in order to get wallMaterialType of some wall in this list, I would go like
wall.getWallType().getWallEntry().getWallMaterial().getWallMaterialType();
Now class Wall has also following params: width
and height
which multiplied together gets an area of the wall by calling my function getWallArea()
from Wall class.
What I would like to achieve is to get area of all wallMaterialTypes from a list of walls calculated, so for instance lets assume we have 2 walls:
- Wall 1 with following wallMaterialTypes: Brick, Plaster, Wood and wallArea() of 35 sq. meters.
- Wall 2 with following wallMaterialTypes: Hay, Plaster and wallArea() of 105 square meters.
Now what output I would like to have is:
BRICK: 35 square meters.
Plaster: 140 square meters.
Wood: 35 square meters.
Hay: 105 square meters.
My code so far is looking something like this where have I pulled for each
Map<WallType, Double> getIt = listOfWalls.stream()
.collect(groupingBy(Wall::getWallType, Collectors.summingDouble(Wall::getWallArea)));
From there I am clueless how to go? Help appreciated.