for (Employee employee : employeeList) {
employeeToAssignmentSequenceListMap.put(employee,
new ArrayList<AssignmentSequence>(assignmentSequenceCapacity));
}
for (ShiftAssignment shiftAssignment : shiftAssignmentList) {
Employee employee = shiftAssignment.getEmployee();
List<AssignmentSequence> assignmentSequenceList = employeeToAssignmentSequenceListMap.get(employee);
if (assignmentSequenceList.isEmpty()) {
AssignmentSequence assignmentSequence = new AssignmentSequence(employee, shiftAssignment);
assignmentSequenceList.add(assignmentSequence);
} else {
AssignmentSequence lastAssignmentSequence = assignmentSequenceList // getLast()
.get(assignmentSequenceList.size() - 1);
if (lastAssignmentSequence.belongsHere(shiftAssignment)) {
lastAssignmentSequence.add(shiftAssignment);
} else {
AssignmentSequence assignmentSequence = new AssignmentSequence(employee, shiftAssignment);
assignmentSequenceList.add(assignmentSequence);
}
}
}
// The create the move list
List<Move> moveList = new ArrayList<Move>();
// For every 2 distinct employees
for (ListIterator<Employee> leftEmployeeIt = employeeList.listIterator(); leftEmployeeIt.hasNext();) {
Employee leftEmployee = leftEmployeeIt.next();
List<AssignmentSequence> leftAssignmentSequenceList
= employeeToAssignmentSequenceListMap.get(leftEmployee);
for (ListIterator<Employee> rightEmployeeIt = employeeList.listIterator(leftEmployeeIt.nextIndex());
rightEmployeeIt.hasNext();) {
Employee rightEmployee = rightEmployeeIt.next();
List<AssignmentSequence> rightAssignmentSequenceList = employeeToAssignmentSequenceListMap.get(
rightEmployee);
LowestDayIndexAssignmentSequenceIterator lowestIt = new LowestDayIndexAssignmentSequenceIterator(
leftAssignmentSequenceList, rightAssignmentSequenceList);
// For every pillar part duo
while (lowestIt.hasNext()) {
AssignmentSequence pillarPartAssignmentSequence = lowestIt.next();
// Note: the initialCapacity is probably to high,
// which is bad for memory, but the opposite is bad for performance (which is worse)
List<Move> moveListByPillarPartDuo = new ArrayList<Move>(
leftAssignmentSequenceList.size() + rightAssignmentSequenceList.size());
int lastDayIndex = pillarPartAssignmentSequence.getLastDayIndex();
Employee otherEmployee;
int leftMinimumFirstDayIndex = Integer.MIN_VALUE;
int rightMinimumFirstDayIndex = Integer.MIN_VALUE;
if (lowestIt.isLastNextWasLeft()) {
otherEmployee = rightEmployee;
leftMinimumFirstDayIndex = lastDayIndex;