mon.beginTask(SORTING, 100);
// Create a LazySortedCollection
Comparator order = sortOrder;
IFilter f = filter;
LazySortedCollection collection = new LazySortedCollection(order);
// Fill it in with all existing known objects
Object[] knownObjects = updator.getKnownObjects();
for (int i = 0; i < knownObjects.length; i++) {
Object object = knownObjects[i];
if (object != null) {
collection.add(object);
}
}
boolean dirty = false;
int prevSize = knownObjects.length;
updator.setTotalItems(prevSize);
// Start processing changes
while(true) {
// If the sort order has changed, build a new LazySortedCollection with
// the new comparator
if (order != sortOrder) {
dirty = true;
order = sortOrder;
// Copy all elements from the old collection to the new one
LazySortedCollection newCollection = new LazySortedCollection(order);
Object[] items = collection.getItems(false);
for (int j = 0; j < items.length && order == sortOrder; j++) {
Object item = items[j];
newCollection.add(item);
}
// If the sort order changed again, re-loop
if (order != sortOrder) {
continue;
}
collection = newCollection;
continue;
}
// If the filter has changed
if (f != filter) {
dirty = true;
f = filter;
Object[] items = collection.getItems(false);
// Remove any items that don't pass the new filter
for (int j = 0; j < items.length && f == filter; j++) {
Object toTest = items[j];
if (!f.select(toTest)) {
collection.remove(toTest);
}
}
continue;
}