Class SimpleQueueComparator

java.lang.Object
cz.mendelu.xotradov.SimpleQueueComparator
All Implemented Interfaces:
Comparator<Queue.Item>

public class SimpleQueueComparator extends Object implements 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 Details

    • SimpleQueueComparator

      public SimpleQueueComparator()
  • Method Details

    • getInstance

      public static SimpleQueueComparator getInstance()
    • hasDesiresFor

      public boolean hasDesiresFor(long key)
    • compare

      public int compare(Queue.Item item1, Queue.Item item2)
      Specified by:
      compare in interface Comparator<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 item
      longB - Id of less important Queue.Item
    • removeDesireOfKey

      public void removeDesireOfKey(long id)
    • resetDesires

      public void resetDesires()
    • sortNotWaitingItems

      public void sortNotWaitingItems(List<Queue.Item> items)
      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