Structure:
Accounting
+ Map<Employee, EmployeeCard> getEmployeeCards()
EmployeeCard
+ Map<LocalDate, Report> getReports()
Report
+ double getSalary()
I need to calculate salary sum of all reports of all employee cards.
My variant using two cycles:
public double getCostsOfEmployeesSalaries() {
double sumOfSalary = 0;
for (EmployeeCard card : accounting.getEmployeeCards().values()) {
Collection<Report> reports = card.getReports().values();
for (Report report : reports) {
sumOfSalary += report.getSalary();
}
}
return sumOfSalary;
}
Is there any solution to calculate sum using java stream API?