I have a list of taxes:
TaxLine = title:\"New York Tax\", rate:0.20, price:20.00
TaxLine = title:\"New York Tax\", rate:0.20, price:20.00
TaxLine = title:\"Count
Unable to sum up the grouped field can be achieved by Defining a new class called TitleRate inside Taxline class as below.
class Taxline{
public static class TitleRate {
public TitleRate(String title, int taxline) {
...
}
}
public TitleRate getTitleRate() {
return new TitleRate(title, taxline);
}
}
To sum the price by grouping title and taxrate, below can be used.
Map> groupedData = people.collect(Collectors.groupingBy(Taxline::getTitleRate));
List groupedTaxLines = new ArrayList();
BigDecimal groupedRate = BigDecimal.ZERO;
for (Map> entry : groupedData.entrySet())
{
for(Taxline taxline : entry.getValue()){
groupedRate = groupedRate.add(taxline.getPrice());
}
groupedTaxLines.add(new Taxline(entry.getKey().getTitle, entry.getKey().getRate(), groupedRate));
groupedRate = BigDecimal.ZERO;
}