package com.lovecoding.day18.ex02;

import org.junit.Test;

import java.util.Arrays;
import java.util.Comparator;

public class TestEmployee {

    @Test
    public void test01(){

        Employee[] arr = {
                new Employee("zs1",1200,10),
                new Employee("zs2",1200,22),
                new Employee("zs3",1400,22),
                new Employee("zs4",1100,24),
        };

        Arrays.sort(arr);

        System.out.println(Arrays.toString(arr));

        //数组
        Arrays.sort(arr,new EmployeeAgeComparator());

        Arrays.sort(arr, new Comparator<Employee>() {
            @Override
            public int compare(Employee o1, Employee o2) {
                //按照员工年龄比较大小，年龄相同的按照姓名字典顺序
                int result = o1.getAge() - o2.getAge();
                return result == 0 ? o1.getName().compareTo(o2.getName()) : result;
            }
        });

        System.out.println(Arrays.toString(arr));
    }
}
