package cn.freemud.amp.service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortTest {



    public static void main(String[] args) {
        List<AuditScoreAccount> list = new ArrayList<AuditScoreAccount>();

        //创建3个学生对象，年龄分别是20、19、21，并将他们依次放入List中



        AuditScoreAccount s1 = new AuditScoreAccount();
        s1.setExpireDate("2020-01-02");
        s1.setAccountId("1");
        AuditScoreAccount s2 = new AuditScoreAccount();
        s2.setExpireDate("2020-04-03");
        s2.setAccountId("2");
        AuditScoreAccount s3 = new AuditScoreAccount();
        s3.setExpireDate("2020-03-01");
        s3.setAccountId("3");

        AuditScoreAccount s5 = new AuditScoreAccount();
        list.add(s5);
        list.add(s1);
        list.add(s2);
        list.add(s3);

        System.out.println("排序前："+list);

        List<String> stringList = new ArrayList<>();
        stringList.add("3");
        stringList.add("2");

        Collections.sort(list, new Comparator<AuditScoreAccount>(){
            /*
             * int compare(Student o1, Student o2) 返回一个基本类型的整型，
             * 返回负数表示：o1 小于o2，
             * 返回0 表示：o1和o2相等，
             * 返回正数表示：o1大于o2。
             */
            public int compare(AuditScoreAccount o1, AuditScoreAccount o2) {
                if(stringList.contains(o2.getAccountId())){
                    return 1;
                }
                if(stringList.contains(o1.getAccountId())){
                    return -1;
                }
                if(o2.getExpireDate() ==null){
                    return -1;
                }
                if(o1.getExpireDate() ==null){
                    return 1;
                }
               return   o1.getExpireDate().compareTo(o2.getExpireDate());
            }
        });
        System.out.println("排序后："+list);
    }
}
