Skip to content

Instantly share code, notes, and snippets.

@pawelpluta
Created December 20, 2020 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawelpluta/0d3786ebe9aae5f62731e294a1b3255a to your computer and use it in GitHub Desktop.
Save pawelpluta/0d3786ebe9aae5f62731e294a1b3255a to your computer and use it in GitHub Desktop.
Article: Law of Demeter - company without division
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.getTeams().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