package UE03_170924_Map_Birthdays;

public class Birthday implements Comparable {
    private int day;
    private int month;
    private int year;

    public Birthday(String date) {
        if (date.length() != 10) return;
        for (int i = 0; i < 10; i++) {
            if ((i == 2 || i == 5) && date.charAt(i) == '.') continue;
            if (Character.isDigit(date.charAt(i))) continue;
            return;
        }
        this.day = Integer.parseInt(date.substring(0, 2));
        this.month = Integer.parseInt(date.substring(3, 5));
        this.year = Integer.parseInt(date.substring(6, 10));
    }

    public int getYear() {
        return year;
    }

    public int getMonth() {
        return month;
    }

    public int getDay() {
        return day;
    }

    @Override
    public String toString() {
        return "Birthday{" + "day=" + day + ", month=" + month + ", year=" + year + '}';
    }

    @Override
    public int compareTo(Object object) {
        Birthday o = (Birthday) object;
        if (this.day != o.getDay()) return Integer.compare(this.day, o.getDay());
        if (this.month != o.getMonth()) return Integer.compare(this.month, o.getMonth());
        return Integer.compare(this.year, o.getYear());
    }
}
