List中根据某个字段相同的值相加

List中根据某个字段相同的值相加

	List<AlarmStateSum> nodeAlarmStateStatistics = baseMapper.getNodeAlarmStateStatistics(alarmRealtimeVO);
			alarmRealtimeVO.setTableName(startTableName);
			List<AlarmStateSum> nodeHistoryAlarmStateStatistics = baseMapper.getHistoryNodeAlarmStateStatistics(alarmRealtimeVO);
			alarmRealtimeVO.setTableName(endTableName);
			List<AlarmStateSum> nodeHistoryAlarmStateStatistics1 = baseMapper.getHistoryNodeAlarmStateStatistics(alarmRealtimeVO);
			list.addAll(nodeAlarmStateStatistics);
			list.addAll(nodeHistoryAlarmStateStatistics);
			list.addAll(nodeHistoryAlarmStateStatistics1);
			collect =list.stream().collect(Collectors.toMap(AlarmStateSum::getCode,a->a,(o1,o2)->{
				o1.setCount(o1.getCount()+o2.getCount());
				return o1;
			})).values().stream().collect(Collectors.toList());

你可能感兴趣的:(java)