-
-
Save pawelpluta/e50eaee07e94d16d23e98c9f3a337694 to your computer and use it in GitHub Desktop.
Article: Law of Demeter - company base
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Company { | |
private List<Department> departments; | |
Map<DepartmentCode, BigDecimal> costPerDepartment() { | |
Map<DepartmentCode, BigDecimal> costPerDepartment = new HashMap<>(); | |
departments.forEach(department -> { | |
DepartmentCode departmentCode = department.getCode(); | |
BigDecimal employeesCost = department.getDivisions().stream() | |
.map(Division::getTeams).flatMap(List::stream) | |
.map(Team::getMembers).flatMap(List::stream) | |
.map(Member::getCost).reduce(BigDecimal.ZERO, BigDecimal::add); | |
costPerDepartment.put(departmentCode, employeesCost); | |
}); | |
return costPerDepartment; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment