假设我有一个 bean 集合,它在为其编写的自定义比较器的帮助下按 empld、dept、project 排序,并使用 apache 集合 ComparatorChain 对该 bean 的列表进行排序。豆子如下。
public class Employee {
protected String empId; //alphanumeric e.g.abc123
protected String empFullName;
protected String empAddress;
protected String dept;
protected String project;
protected String customer;
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;
}
public String getCustomer() {
return customer;
}
public void setCustomer(String customer) {
this.customer = customer;
}
}
客户价值可以是,比如说:公司、政府、大学
现在假设集合中有数千条记录(bean),现在我想要的是相同的 empId(可以出现两次),如果客户是公司,则将其移动到具有客户名称 University 的相同 empId 之下。客户的记录可能不按顺序排列,所以任何一个都可以先出现,等等。
所以基本上我想移动两个或多个具有相同empId的记录并且其中一个有customer =Company将其移动到具有相同empId的订单下方,例如
我怎样才能以一种有效且可能的线程安全的方式实现这种记录的交换/重新排列。