在bug中写bug

导航

 

使用方法:

   List<BuLtReasonCodeDTO> categoryList = searchvo
                .stream()
                .filter(distinctByKey(BuLtReasonCodeDTO::getReasonCategory))
                .collect(Collectors.toList());

 

过滤方法:  

    /**
     * 根据属性过滤相同数据方法,用于Stream
     *
     * @param keyExtractor
     * @param <T>
     * @return
     */
    private static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
        Set<Object> seen = ConcurrentHashMap.newKeySet();
        return t -> seen.add(keyExtractor.apply(t));
    }

  

 

posted on 2023-05-19 11:36  在bug中写bug  阅读(122)  评论(0)    收藏  举报