import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class AssignTest {
static List<Integer> listCus = new ArrayList<Integer>();
static List<Persons> personsList = new ArrayList<Persons>();
static List<Persons> compareList = new ArrayList<Persons>();
static List<Persons> result = new ArrayList<Persons>();
public static void main(String[] args) {
for (int i = 0; i < 20; i++) {
listCus.add(i);
}
for (Integer j = 0; j < 5; j++) {
Persons p = new Persons();
p.setAssignedNum(0);
p.setLimit(5);
p.setPersonname("Person" + j);
p.setAssignedCases(new ArrayList<Integer>());
personsList.add(p);
}
int cursor = 0;
for (int i = 0; i < listCus.size(); i++) {
int personSize = personsList.size();
if (personSize <= cursor) {
cursor = 0;
}
if (personSize > 0) {
Persons p = personsList.get(cursor % personSize);
cursor = getOrg(cursor, i, p);
}
}
for (Persons p : compareList) {
System.out.println(p);
}
for (Persons p : personsList) {
System.out.println(p);
}
}
private static int getOrg(int cursor, int i, Persons p) {
int personSize;
if (p.getLimit() <= p.assignedNum) {
compareList.add(p);
personsList.remove(p);
personSize = personsList.size();
if (personSize > 0) {
if (personSize <= cursor) {
cursor = 0;
}
p = personsList.get(cursor % personSize);
getOrg(cursor, i, p);
}
} else {
p.setAssignedNum(p.getAssignedNum() + 1);
List list;
list = p.getAssignedCases();
list.add(i);
p.setAssignedCases(list);
cursor++;
}
return cursor;
}
public void getOrg(){
}
public static class Persons {
List<Integer> assignedCases;
Integer limit;
Integer assignedNum;
private String personname;
public Persons() {
this.limit = 0;
this.assignedNum = 0;
}
public List<Integer> getAssignedCases() {
return assignedCases;
}
public void setAssignedCases(List<Integer> assignedCases) {
this.assignedCases = assignedCases;
}
public Integer getAssignedNum() {
return assignedNum;
}
public void setAssignedNum(Integer assignedNum) {
this.assignedNum = assignedNum;
}
public String getPersonname() {
return personname;
}
public void setPersonname(String personname) {
this.personname = personname;
}
public Integer getLimit() {
return limit;
}
public void setLimit(Integer limit) {
this.limit = limit;
}
@Override
public String toString() {
return "Persons{" +
"assignedCases=" + assignedCases +
", limit=" + limit +
", assignedNum=" + assignedNum +
", personname='" + personname + '\'' +
'}';
}
}
}
|