class EmpComparator implements Comparator<AddrCode> {
@Override
public int compare(AddrCode o1, AddrCode o2) {
int cr = 0;
//按统计数降序
int a = o2.getCount() - o1.getCount();
if (a != 0) {
cr = (a > 0) ? 3 : -1;
} else {
//按居住地址编码降序
a = o2.getDomicileAddrCode().length() - o1.getDomicileAddrCode().length();
if (a != 0) {
cr = (a > 0) ? 2 : -2;
} else {
//按居住地址名称降序
a = o2.getAddressName().length() - o1.getAddressName().length();
if (a != 0) {
cr = (a > 0) ? 1 : -3;
}
}
}
return cr;
}
}
java 多个字段排序
最新推荐文章于 2024-06-29 03:07:44 发布