Package cz.mendelu.xotradov
Class SimpleQueueComparator
java.lang.Object
cz.mendelu.xotradov.SimpleQueueComparator
- All Implemented Interfaces:
Comparator<Queue.Item>
The comparator backs up the SimpleQueueSorter.
It stores all current desires - acts of will concerning order of build items.
- Author:
- Jaroslav Otradovec
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDesire(long longA, long longB) Add desire of order relationship between two items.intcompare(Queue.Item item1, Queue.Item item2) static SimpleQueueComparatorbooleanhasDesiresFor(long key) voidremoveDesireOfKey(long id) voidvoidsortNotWaitingItems(List<Queue.Item> items) Sorts the NotWaitingItem entries (BlockedItem and BuildableItem) within the given list in place, using the comparator's desires.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
SimpleQueueComparator
public SimpleQueueComparator()
-
-
Method Details
-
getInstance
-
hasDesiresFor
public boolean hasDesiresFor(long key) -
compare
- Specified by:
comparein interfaceComparator<Queue.Item>- Returns:
- -1 when first is more important, 1 when second is more important, default 0
-
addDesire
public void addDesire(long longA, long longB) Add desire of order relationship between two items. If is present vice versa relation, it is deleted.- Parameters:
longA- Id of desired more important itemlongB- Id of less important Queue.Item
-
removeDesireOfKey
public void removeDesireOfKey(long id) -
resetDesires
public void resetDesires() -
sortNotWaitingItems
Sorts the NotWaitingItem entries (BlockedItem and BuildableItem) within the given list in place, using the comparator's desires. Items that are not NotWaitingItem (e.g. WaitingItem) are left in their original position, with the sorted NotWaitingItems placed between the before/after groups.The sort order matches the widget display: lower priority at the top (start of list), higher priority at the bottom (end of list). The comparator returns -1 for higher priority, so we reverse the arguments to achieve the display order.
- Parameters:
items- the mutable list of queue items to sort in place
-