package com.sf._01_treeset.demo1;

public class Employee implements Comparable<Employee> {
    private Long id;
    private String name;
    private int age;
    private double salary;


    public Employee() {
    }

    public Employee(Long id, String name, int age, double salary) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    /**
     * 获取
     * @return id
     */
    public Long getId() {
        return id;
    }

    /**
     * 设置
     * @param id
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 获取
     * @return salary
     */
    public double getSalary() {
        return salary;
    }

    /**
     * 设置
     * @param salary
     */
    public void setSalary(double salary) {
        this.salary = salary;
    }

    public String toString() {
        return "Employee{id = " + id + ", name = " + name + ", age = " + age + ", salary = " + salary + "}";
    }

    /**
     * 先按照年龄进行从小到大排序, 如果年龄相同按照薪资从大到小进行降序排序
     */
    @Override
    public int compareTo(Employee e) {
        if(this.age > e.getAge()){
            return 1;
        }else if(this.age < e.getAge()){
            return -1;
        }{
            // 如果相同在按照薪资排序
            if(this.salary > e.getSalary()){
                return -1;
            }else if(this.salary < e.getSalary()){
                return 1;
            }else{
                return 0;
            }
        }
    }
}
