jdk8使用stream对指定值去重以及其他stream用法

        // 分组统计
        final Map<Integer, Long> gunCountMap = infoDTOS
                .stream()
                .filter(dto -> BooleanStatusEnum.NO.getCode() == x.getSuspend())
                .collect(Collectors.groupingBy(ConnectorEquipmentInfoDTO::getConnectorStatus, Collectors.counting()));
        long hangOnCount = infoDTOS.stream().filter(x -> BooleanStatusEnum.YES.getCode() == x.getSuspend()).count();
        final long allGunCount = gunCountMap.values().stream().collect(Collectors.summarizingLong(Long::longValue)).getSum() + hangOnCount;
        setGunInfo(allGunCount, hangOnCount, gunCountMap, dto);

        // 指定值去重
        final ArrayList<ConnectorEquipmentInfoDTO> distinctList = infoDTOS
                .stream()
                .filter(Objects::nonNull)
                .collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(ConnectorEquipmentInfoDTO::getEquipmentId))), ArrayList::new));
posted @ 2021-11-10 11:06  夜旦  阅读(301)  评论(0编辑  收藏  举报