Comparator排序

/**对trackDeploys DIY 排序*/
List<VendorTrackDeploy> trackDeploys = new ArrayList<>();
trackDeploys.sort(comparator);

Comparator<VendorTrackDeploy> comparator = new Comparator<VendorTrackDeploy>() {
        @Override
        public int compare(VendorTrackDeploy s1, VendorTrackDeploy s2) {
            int flag;
            // 先按货道库存数量倒序
            flag = s2.getCurrentCount()-s1.getCurrentCount();
            if(flag==0){
                // 库存数量相等按警戒值正序
                flag = (StringUtils.isEmpty(s1.getWarningCount())?0:s1.getWarningCount()) - (StringUtils.isEmpty(s2.getWarningCount())?0:s2.getWarningCount());
            }
            return flag;
        }
    };

你可能感兴趣的:(分享)