クエリの結果として、db からの Bean のリストがあります。
ビーンは次のとおりです。
public class Employee implements Comparator<Employee> {
protected String empId; //alphanumeric e.g.abc123
protected String empFullName;
protected String empAddress;
protected String dept;
protected String project;
public String getEmpId() {
return empId;
}
public void setEmpId(String empId) {
this.empId = empId;
}
public String getEmpFullName() {
return empFullName;
}
public void setEmpFullName(String empFullName) {
this.empFullName = empFullName;
}
public String getEmpAddress() {
return empAddress;
}
public void setEmpAddress(String empAddress) {
this.empAddress = empAddress;
}
public String getDept() {
return dept;
}
public void setDept(String dept) {
this.dept = dept;
}
public String getProject() {
return project;
}
public void setProject(String project) {
this.project = project;
}
@Override
public int compare(Employee e1, Employee e2) {
if (e1 == null && e2 == null) return 0;
if (e1 != null && e2 == null) return -1;
if (e1 == null && e2 != null) return 1;
return e1.empId.compareTo (e2.empId);
}
}
英数字の empId でソートするコンパレータがあります。
empId、dept、project で並べ替える最善の方法を知りたいです。
コードでは、次のようにすると、empId で並べ替えられます。
List<Employee> empList = someDao.getEmpList();
Collections.sort(empList, new Employee());
助言がありますか。