int[] previousIndices = listChanges.getReorderMap();
int[] reorderMap = new int[collapsedElements.colourSize(Barcode.BLACK)];
// walk through the unfiltered elements, adjusting the indices
// for each group of unfiltered (black) elements
BarcodeIterator i = collapsedElements.iterator();
int groupStartSourceIndex = 0;
while(true) {
// we already know where this group starts, now we calculate
// where it ends, and how many indices it's offset by in the view
boolean newGroupFound;
int groupEndSourceIndex;
int leadingCollapsedElements;
if(i.hasNextWhite()) {
i.nextWhite();
groupEndSourceIndex = i.getIndex();
newGroupFound = true;
leadingCollapsedElements = i.getWhiteIndex();
} else {
newGroupFound = false;
groupEndSourceIndex = collapsedElements.size();
leadingCollapsedElements = collapsedElements.whiteSize();
}
// update the reorder map for each element in this group
for(int j = groupStartSourceIndex; j < groupEndSourceIndex; j++) {
reorderMap[j - leadingCollapsedElements] = previousIndices[j] - leadingCollapsedElements;
}
// prepare the next iteration: find the start of the next group
if(newGroupFound && i.hasNextBlack()) {
i.nextBlack();
groupStartSourceIndex = i.getIndex();
} else {
break;
}
}
updates.reorder(reorderMap);