stream流式编程
类分组求和
Map<Integer, BigDecimal> bigDecimalMap = dayPlans.stream().collect(Collectors.groupingBy(
o -> o.getDay(), Collectors.reducing(
new BigDecimal("0"), GradeMaterialDayPlan::getPlanQty, BigDecimal::add)));
List集合类分组取第一条
Map<Integer, GradeMaterialDayPlan> materialDayPlanMap = dayPlans.stream().collect(Collectors.groupingBy(
o -> o.getDay(), Collectors.collectingAndThen(Collectors.reducing(
(e1, e2) -> e1.getDay() == e2.getDay() ? e1 : e2), Optional::get)));
List集合按两个字段分组
Map<String, GradeDayPlan> materialDayPlanMap = gradeDayPlanList.stream().collect(
Collectors.groupingBy(o -> o.getGrade() + "_" + o.getDate().getDay(), Collectors.collectingAndThen(
Collectors.reducing((e1, e2) -> e1.getGrade() == e2.getGrade() ? e1 : e2), Optional::get)));