}
LowestFirstNightBedDesignationIterator lowestIt = new LowestFirstNightBedDesignationIterator(
leftBedDesignationList, rightBedDesignationList);
// For every pillar part duo
while (lowestIt.hasNext()) {
BedDesignation pillarPartBedDesignation = 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>(
leftBedDesignationList.size() + rightBedDesignationList.size());
int lastNightIndex = pillarPartBedDesignation.getAdmissionPart().getLastNight().getIndex();
Bed otherBed;
int leftMinimumFirstNightIndex = Integer.MIN_VALUE;
int rightMinimumFirstNightIndex = Integer.MIN_VALUE;
if (lowestIt.isLastNextWasLeft()) {
otherBed = rightBed;
leftMinimumFirstNightIndex = lastNightIndex;
} else {
otherBed = leftBed;
rightMinimumFirstNightIndex = lastNightIndex;
}
moveListByPillarPartDuo.add(new BedChangeMove(pillarPartBedDesignation, otherBed));
// For every BedDesignation in that pillar part duo
while (lowestIt.hasNextWithMaximumFirstNightIndexes(
leftMinimumFirstNightIndex, rightMinimumFirstNightIndex)) {
pillarPartBedDesignation = lowestIt.next();
lastNightIndex = pillarPartBedDesignation.getAdmissionPart().getLastNight().getIndex();
if (lowestIt.isLastNextWasLeft()) {
otherBed = rightBed;
leftMinimumFirstNightIndex = Math.max(leftMinimumFirstNightIndex, lastNightIndex);
} else {
otherBed = leftBed;