Class ControllableQueue<T>

  • Type Parameters:
    T - the type of the value of ControllableQueue.DelayNode

    public class ControllableQueue<T>
    extends java.lang.Object
    A controllable queue is a priority queue with ControllableQueue.DelayNodes. It supports tick the time forward and pop nodes whose delay is smaller than the past time.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ControllableQueue.DelayNode<T>
      A delay node in delta queue which records the value and the total delay (which is the original delay plus the past time).
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(long delay, T value)
      Adds a new node into the queue.
      long getHeadDelay()  
      T getHeadValue()  
      boolean isEmpty()  
      T pop()  
      boolean remove​(T element)
      Removes an element.
      void tick​(long duration)
      Jumps to a future time period.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • isEmpty

        public boolean isEmpty()
        Returns:
        whether this queue is empty
      • getHeadValue

        public T getHeadValue()
        Returns:
        the value of head element
      • getHeadDelay

        public long getHeadDelay()
        Returns:
        the delay of head element
      • add

        public void add​(long delay,
                        T value)
        Adds a new node into the queue.
        Parameters:
        delay - the delay in milliseconds
        value - the value
      • tick

        public void tick​(long duration)
        Jumps to a future time period.
        Parameters:
        duration - the time period to jump
      • pop

        public T pop()
        Returns:
        the head element if it should be executed
      • remove

        public boolean remove​(T element)
        Removes an element.
        Parameters:
        element - an element
        Returns:
        true if the element removed successfully, false otherwise
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object