class SpendProfileTableCalculator {

    public Map<String, BigDecimal> createYearlyEligibleCostTotal(ProjectResource project, Map<String, List<BigDecimal>> tableData, List<LocalDateResource> months) {
        Map<String, BigDecimal> yearEligibleCostTotal = new LinkedHashMap<>();
        Integer startYear = new FinancialYearDate(DateUtil.asDate(project.getTargetStartDate())).getFiscalYear();
        Integer endYear = new FinancialYearDate(DateUtil.asDate(project.getTargetStartDate().plusMonths(project.getDurationInMonths()))).getFiscalYear();
        IntStream.range(startYear, endYear + 1).
                forEach(
                        year -> {
                            Set<String> keys = tableData.keySet();
                            BigDecimal totalForYear = BigDecimal.ZERO;

                            for (String key : keys) {
                                List<BigDecimal> values = tableData.get(key);
                                for (int i = 0; i < values.size(); i++) {
                                    LocalDateResource month = months.get(i);
                                    FinancialYearDate financialYearDate = new FinancialYearDate(DateUtil.asDate(month.getLocalDate()));
                                    if (year == financialYearDate.getFiscalYear()) {
                                        totalForYear = totalForYear.add(values.get(i));

                                    }
                                }
                            }
                            yearEligibleCostTotal.put(String.valueOf(year), totalForYear);
                        }
                );
        return yearEligibleCostTotal;
    }

}