xChar

基本思路:将stream按照key转成map去重,然后读取map的值,组成集合,集合按照某个属性排序成list

直接上代码:

new ArrayList<>(Optional.ofNullable(psSealList)
    .orElse(Collections.emptyList())
    .stream()
    // 执行过滤条件
    .filter(sp -> validateNoType.or(validateEffective).test(sp))
    // 去重
    .collect(Collectors.toMap(PsSeal::getEsId, Function.identity(), (oldValue, newValue) -> oldValue))
    // 可能导致排序变动
    .values())
    .stream()
    // 根据ID重新排序
    .sorted(Comparator.comparing(PsSeal::getId))
    .collect(Collectors.toList());
Loading comments...