package com.sf._01_treeset.demo1;

import java.util.Comparator;
import java.util.TreeSet;

public class Test2 {
    /**
     * Employee
     * id  name age  salary
     * 把Employee 存储到TreeSet 中
     * 按照salary 从大到小排序
     *
     * 默认规则是先按照年龄小到大 如果年龄相同就按照薪资从大到小
     *
     * 用我自己的规则 先按照薪资从大到小 , 如果薪资相同在按照年龄从小到大
     */
    public static void main(String[] args) {
        TreeSet<Employee> treeSet = new TreeSet<>(new Comparator<Employee>() {
            @Override
            public int compare(Employee o1, Employee o2) {
                if(o1.getSalary()> o2.getSalary()){
                    return -1;
                }else if(o1.getSalary()< o2.getSalary()){
                    return 1;
                }else{
                    if(o1.getAge() > o2.getAge()){
                        return 1;
                    }else if(o1.getAge() < o2.getAge()){
                        return -1;
                    }else{
                        return 0;
                    }
                }
            }
        });
        treeSet.add(new Employee(1L,"zhangsan",40,30000));
        treeSet.add(new Employee(2L,"zhangsan1",20,50000));
        treeSet.add(new Employee(3L,"zhangsan2",20,30000));
        treeSet.add(new Employee(4L,"zhangsan3",30,40000));
        // 2 4 3 1
        System.out.println(treeSet);
        for (Employee employee : treeSet) {
            System.out.println(employee);
        }
    }
}
