I initialize the priority queue, for example:
strategy = new FuelPriority();
incoming = new PriorityQueue<Vehicle>(1, strategy);
Code of my Comparator class:
public class FuelPriority implements Comparator<Object> {
public int compare(Object o1, Object o2) {
Vehicle a1 = (Vehicle) o1;
Vehicle a2 = (Vheicle) o2;
return Integer.compare(a1.getFuelLevel(), a2.getFuelLevel());
}
}
After starting the simulation, the elements are not ordered at all - they are random; I set a breakpoint in the comparison method of my class FuelPriority, but it was not called at all. Did I miss something?
source
share