I'm using a Comparator
implementation to sort a large collection of objects. Depending on the type of objects in this collection the sort takes a few milliseconds to half a minute. Is there any way to determine the progress of the Comparator
while sorting? I'd like to visualize this for the user.
Collections.sort(sorted, new Comparator<Object[]>() {
public int compare(Object[] o1, Object[] o2) {
/* do it... */
return order;
}
}
The collection may hold simple short String objects, Date objects or (worst case) CLOB objects which need to fetch data while sorting.
You could do that by writing an comparator that counts up an "global" variable.
But to visualize the progress for analytical purpose, you have to copy your list, and sort it twice. The first time you determine the number of comparator calls. The next time you know how far you already are, by comparing the current counter with the value from the first sort.
You would need a second thread to read out the counter while the other thread is sorting.
Another possibility is to estimate the number of comparator calls: on average this could be related to n * ld (n).
Then again count up, and read from another thread. This way you have to sort only once.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With