java 排序多个条件

复制代码
Comparator<RecentReceivingAccountVO> byTime= Comparator.comparing(RecentReceivingAccountVO::getCreateTime);
        Comparator<RecentReceivingAccountVO> byName = Comparator.comparing(p->p.getAccountName().equals(user.getNickName()));
        return voList.stream().sorted(byName.reversed().thenComparing(byTime.reversed())).collect(Collectors.toList());

 

  //按照总价,再按照物流,再按照创建时间
        Comparator<RmpAutoQuotationResourcePriceVO> byTotalPrice = Comparator.comparing(RmpAutoQuotationResourcePriceVO::getTotalPrice);
        Comparator<RmpAutoQuotationResourcePriceVO> byLgisticsPrice = Comparator.comparing(RmpAutoQuotationResourcePriceVO::getLogisticsPrice);
        Comparator<RmpAutoQuotationResourcePriceVO> byCreateTime = Comparator.comparing(RmpAutoQuotationResourcePriceVO::getCreateTime);
        //有物流信息只返回价格最低
        Optional<RmpAutoQuotationResourcePriceVO> hasLogistics = resourcePriceVOList.stream().
                filter(RmpAutoQuotationResourcePriceVO::isHasLogistics).
                sorted(byTotalPrice.thenComparing(byLgisticsPrice).thenComparing(byCreateTime)).findFirst();
        if (hasLogistics.isPresent()) {
            autoPriceQuo.add(copyToAutoPriceQuo(hasLogistics.get(),cityCode));
        }
复制代码

 

posted @   八英里  阅读(359)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示