java Collections 排序--多条件排序

java Collections 排序–多条件排序

// 告警排序
Collections.sort(domesticAirport, comparator);

// 告警排序
Comparator<AirportRtWeatherWarningBeanForTable> comparator = new Comparator<AirportRtWeatherWarningBeanForTable>() {
@Override
public int compare(AirportRtWeatherWarningBeanForTable a1, AirportRtWeatherWarningBeanForTable a2) {
            // 首先根据是否过期排序
            if(a1.isMetarExpired() && !a2.isMetarExpired()){
                return 1;
            }else if (!a1.isMetarExpired() && a2.isMetarExpired()) {
                return -1;
            } else if ((a1.isMetarExpired() && a2.isMetarExpired()) || (!a1.isMetarExpired() && !a2.isMetarExpired())) {
                //同时过期,或者都不过期,则按告警类型排序
                if (a1.getWarningColor() != a2.getWarningColor()) {
                    return compareColor(a1.getWarningColor(), a2.getWarningColor());
                }
            }
            //告警类型相同,按字母排序
            return a1.getCode4().compareTo(a2.getCode4());
        }
    };

    // 告警类型比较排序
    public int compareColor(Color color1, Color color2) {
        int i = 0;
        int j = 0;

        if (color1.equals(MeteoWeatherWarningPanel.RED)) {
            i = 3;
        } else if (color1.equals(MeteoWeatherWarningPanel.YELLOW)) {
            i = 2;
        } else if (color1.equals(MeteoWeatherWarningPanel.GREEN)) {
            i = 1;
        }

        if (color2.equals(MeteoWeatherWarningPanel.RED)) {
            j = 3;
        } else if (color2.equals(MeteoWeatherWarningPanel.YELLOW)) {
            j = 2;
        } else if (color2.equals(MeteoWeatherWarningPanel.GREEN)) {
            j = 1;
        }
        int k = i - j;
        if (k > 0) {
            return -1;
        } else if (k < 0) {
            return 1;
        } else
            return 0;
    }
  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值