List<Double> memUseRateList = serverLogList.parallelStream().filter(sl -> sl.getMemUseRate() != null).map(MonitorServerLog::getMemUseRate).collect(Collectors.toList());
Double memUseRate = 0D;
//Double取平均值
if (CollectionUtils.isNotEmpty(memUseRateList)) {
memUseRate = memUseRateList.stream().collect(Collectors.averagingDouble(mem -> mem));;
}
serverLogVO.setMemUseRate(memUseRate);
List<Double> cpuUseRateList = serverLogList.parallelStream().filter(sl -> sl.getCpuUseRate() != null).map(MonitorServerLog::getCpuUseRate).collect(Collectors.toList());
Double cpuUseRate = 0D;
//Double取最大值
if (CollectionUtils.isNotEmpty(cpuUseRateList)) {
cpuUseRate = cpuUseRateList.stream().max(Double::compareTo).orElse(0D);
}
serverLogVO.setCpuUseRte(cpuUseRate);
List<Double> diskUseRateList = serverLogList.parallelStream().filter(sl -> sl.getDiskUseRate() != null).map(MonitorServerLog::getDiskUseRate).collect(Collectors.toList());
Double diskUseRate = 0D;
//Double取最小值
if (CollectionUtils.isNotEmpty(diskUseRateList)) {
diskUseRate = diskUseRateList.stream().min(Double::compareTo).orElse(0D);
}
serverLogVO.setDiskUseRate(diskUseRate);
List<Long> netTxList = serverLogList.parallelStream().filter(sl -> sl.getNetTx() != null).map(MonitorServerLog::getNetTx).collect(Collectors.toList());
Double netTx = 0D;
//Long取平均值
if (CollectionUtils.isNotEmpty(netTxList)) {
netTx = netTxList.stream().collect(Collectors.averagingLong(x -> x));
}
List用stream取各项值
最新推荐文章于 2024-01-02 17:16:45 发布