Class ActionQueue

  • All Implemented Interfaces:
    java.io.Serializable

    public class ActionQueue
    extends java.lang.Object
    implements java.io.Serializable
    See Also:
    Serialized Form
    • Constructor Detail

      • ActionQueue

        public ActionQueue()
      • ActionQueue

        protected ActionQueue​(boolean subQueues)
    • Method Detail

      • addAction

        public <T extends Action> T addAction​(T action)
        Adds an action to the queue.
        Type Parameters:
        T - Action type
        Parameters:
        action - Action to add
        Returns:
        The action that was added
      • saveActions

        public void saveActions​(java.lang.String path)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • loadActions

        public void loadActions​(java.lang.String path)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • addActions

        public void addActions​(Action... actions)
        Adds all the given actions to the queue.
        Parameters:
        actions - Actions to add
      • addActions

        public void addActions​(java.util.Collection<Action<?>> actions)
        Adds all the given actions to the queue.
        Parameters:
        actions - Actions to add
      • removeAction

        public void removeAction​(Action action)
        Removes the supplied action from the queue.
        Parameters:
        action - Action to remove
      • removeActions

        public void removeActions​(Action... actions)
        Removes all the supplied actions from the queue.
        Parameters:
        actions - Actions to remove
      • removeActions

        public void removeActions​(java.util.Collection<Action<?>> actions)
        Removes all the supplied actions from the queue.
        Parameters:
        actions - Actions to remove
      • size

        public int size()
        Returns the number of actions in the queue.
        Returns:
        Number of actions in queue
      • indexOf

        public int indexOf​(Action<?> action)
        Returns the index of a given action in the queue
        Parameters:
        action - Action to find index of
        Returns:
        Index of action
      • swapActions

        public void swapActions​(int indexA,
                                int indexB)
        Swaps the positions of two actions in the queue.
        Parameters:
        indexA - Index of action to swap
        indexB - Index of action to swap
      • swapActions

        public void swapActions​(Action a,
                                Action b)
        Swaps the positions of two actions in the queue.
        Parameters:
        a - Action to swap
        b - Action to swap
      • getActions

        public java.util.List<Action<?>> getActions()
      • clear

        public void clear()
        Removes all actions from the queue.
      • addListener

        public ActionQueue.ListListener<Action<?>> addListener​(ActionQueue.ListListener<Action<?>> listener)
        Adds a listener to be triggered every time the queue is changed (actions added, removed or changed order).
        Parameters:
        listener - Listener to add
        Returns:
        The listener that was added
      • removeListener

        public void removeListener​(ActionQueue.ListListener<Action> listener)
        Removes a listener from the queue.
        Parameters:
        listener - The listener to be removed
      • checkRunning

        protected void checkRunning()
                             throws java.lang.IllegalStateException
        Internal method for checking whether the queue is running before making queue alterations. Throws an IllegalStateException if it is running.
        Throws:
        java.lang.IllegalStateException - If the queue is running
      • isRunning

        public boolean isRunning()
      • isInterrupted

        public boolean isInterrupted()
        Returns whether the last run of the queue was interrupted or not.
        Returns:
        Was it interrupted?
      • getInterruptedAction

        public Action<?> getInterruptedAction()
      • start

        public ActionQueue.Result start()
        Starts the queue from the beginning. Returns the overall result of the queue once completed.
        Returns:
        Result of queue execution (SUCCESS, INTERRUPTED or ERROR)
      • resume

        public ActionQueue.Result resume()
        Starts the queue from the last interrupted action.
        Returns:
        Result of queue execution (SUCCESS, INTERRUPTED or ERROR)
      • getStartActions

        public ActionQueue getStartActions()
      • stop

        public void stop()