Class ActionQueue


  • public class ActionQueue
    extends Object
    A priority queue containing ISchedulableAction-s. The actions are ordered according to the return value of their getNextTime() method call.

    This priority queue uses a binary heap algorithm as described in Mark Allen Weis, _Algorithms, Data Structures, and Problem Solving with C++_, chapter 20.

    Author:
    Nick Collier
    See Also:
    ISchedulableAction
    • Constructor Detail

      • ActionQueue

        public ActionQueue()
        Creates an ActionQueue with a default initial size of 13.
      • ActionQueue

        public ActionQueue​(int size)
        Creates an ActionQueue with the specified initial size.
        Parameters:
        size - the intial size of the queue
    • Method Detail

      • voidAction

        public boolean voidAction​(ISchedulableAction action)
        Find the specified Action in the queue and void it. Voiding means replace that action with an empty action that does nothing.
        Returns:
        returns true if the action is found and voided, false if this ActionQueue does not contain the specified AbstractAction.
      • insert

        public void insert​(ISchedulableAction action)
        Insert the specified action into the queue.
      • peekMin

        public ISchedulableAction peekMin()
        Get the minimum element from the queque without removing it from the queue. If heap order is not currently correct, the heap will be fixed before the minimum is returned.
        Returns:
        the minimum element from the queque
      • popMin

        public ISchedulableAction popMin()
        Remove the minimum element from the queque and return it. If heap order is not currently correct, the heap will be fixed before the minimum is returned.
        Returns:
        the minimum element from the queque
      • toss

        public void toss​(ISchedulableAction action)
        Insert the specified action into the queue without maintain heap order.
        Parameters:
        action - the action to insert into the queue
      • clear

        public void clear()
        Removes all elements from the queue.
      • fixHeap

        public void fixHeap()
        Reinstate the heap order. This will fix the tree ordering it correctly.
      • isEmpty

        public boolean isEmpty()
        Returns true if the queue is empty, otherwise false.
        Returns:
        true if the queue is empty, otherwise false.
      • size

        public int size()
        Gets the number of elements in the queue.
        Returns:
        the number of elements in the queue.
      • getModelActionCount

        public int getModelActionCount()
        Retrieves the number of actions whose ISchedulableAction.isNonModelAction() method returns false.
        Returns:
        the number of model actions