通过对象某一属性(去重),并指定其他属性相加,最后返回不重复的list
public List<Schedule> merge(List<Schedule> list) {
// 表示doctorId为key, 接着如果有重复的,那么从Schedule对象o1与o2中筛选出一个,这里选择o1,
// 并把doctorId重复,需要将limitsNum与o1进行合并的o2, 赋值给o1,最后返回o1
List<Schedule> result = list.stream()
.collect(Collectors.toMap(Schedule::getDoctorId, a -> a, (o1, o2) -> {
o1.setLimitsNum(o1.getLimitsNum() + o2.getLimitsNum());
o1.setRemainNum(o1.getRemainNum() + o2.getRemainNum());
o1.setSessionName(o1.getSessionName() + "," + o2.getSessionName());
return o1;
})).values().stream().collect(Collectors.toList());
return result;
}
通过list对象的某个字段的不同状态。统计list对象的各个状态的个数
public Map<String, Long> getMap(List<RegRecord> regRecordList) {
//统计各个状态的数量
Map<String, Long> statusMap = regRecordList.stream().collect(
Collectors.groupingBy(RegRecord::getStatus, Collectors.counting()));
statusMap.putIfAbsent(AppointmentC.APPOINTMENT_STATUS.UNLOCK, 0L);
statusMap.putIfAbsent(AppointmentC.APPOINTMENT_STATUS.LOCK, 0L);
statusMap.putIfAbsent(AppointmentC.APPOINTMENT_STATUS.TO_BE_SIGNED, 0L);
statusMap.putIfAbsent(AppointmentC.APPOINTMENT_STATUS.SIGNED, 0L);
statusMap.putIfAbsent(AppointmentC.APPOINTMENT_STATUS.CALLING, 0L);
statusMap.putIfAbsent(AppointmentC.APPOINTMENT_STATUS.VISITING, 0L);
statusMap.putIfAbsent(AppointmentC.APPOINTMENT_STATUS.PASS_NUMBER, 0L);
statusMap.putIfAbsent(AppointmentC.APPOINTMENT_STATUS.REFUND, 0L);
statusMap.putIfAbsent(AppointmentC.APPOINTMENT_STATUS.SUPPLEMENT, 0L);
statusMap.putIfAbsent(AppointmentC.APPOINTMENT_STATUS.STOP_REFUND, 0L);
return statusMap;
}