In Java, I currently have my PriorityQueue set up to add the objects where they are needed in the list, ideally, I'd want to call a method on all of the moved items, for example:
List = {0,10,20,30,40,50,60,70,80,90,100}.
Add 55
List = {0,10,20,30,40,50,55,60,70,80,90,100}
Objects that would have moved down: {0,10,20,30,40,50} (indexes: 7,8,9,10,11,12)
I only need to worry about the highest 8 items in this list, so, ideally it would only call the method on:
{40,50} (indexes: 7,8)
if anything below that index is changed, I don't need to bother checking it. I've tried doing it by creating a LinkedList, using Collections.sort and cloning the top 8 elements before the next sort. but I continually run into null pointer or and Index out of bounds exception.
Could anyone provide a more generic approach to this problem? My current iteration method:
Hit[] sorted = hitList.toArray(new Hit[hitList.size()]);
for (int i = sorted.length - 1; i > 0; i--) {
if (sorted[i] != clone[i]) { // Nullpointer, arrays are not of equal length
System.out.print("CHANGE AT " + i);
}
System.out.println("");
}
My point is, surely there's a method that avoids this entire conundrum, such as extending a Priority List and overriding add... Which isn't an option because all the useful methods are private.
SortedSetor manually sorted collection.