package ch.usi.inf.ajp22.flyable;

import java.util.Comparator;

/**
 * 3 Points
 * Create a Comparator, named PeopleComparator, for People and its subtypes.
 * Comparison should be done first by age and then by name length.
 */
public final class PeopleComparator<T extends People> implements Comparator<T> {
    private static final Comparator<People> AGE_AND_NAME_CMP = Comparator.comparingInt(People::getAge)
            .thenComparingInt(p -> p.getName().length());

    @Override
    public int compare(final T o1, final T o2) {
        return AGE_AND_NAME_CMP.compare(o1, o2);
    }
}