One thing that I always do when using a PriorityQueue
with my own class is to make that class implement Comparable<Class>
. With this, rather than needing to implement a Comparator, all you need to implement is the int compareTo(Class o)
method in the class which returns "a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object."
In your case, this would return 1 if the Vehicles
has less fuel than the Vehicles
inputed, 0 if the two have the same, and -1 if the Vehicles
has more fuel than the one inputed.
http://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html