/* * =============================================================== * EmployeeComparator.java: Class for comparing the names of company * employees. If two employees have the same name, then they are * ranked according to department. * =============================================================== */ import java.util.Comparator; public class EmployeeComparator implements Comparator { public int compare(Object obj1, Object obj2) { Employee emp1 = (Employee) obj1; Employee emp2 = (Employee) obj2; int nameComp = emp1.getName().compareTo( emp2.getName() ); return ((nameComp == 0) ? emp1.getDepartment().compareTo( emp2.getDepartment()) : nameComp); } }