Class FixedSizeIntegerQueue


  • public final class FixedSizeIntegerQueue
    extends Object
    Primitive but efficient implementation of a fixed size queue for integers. Note: this queue is not implemented as a ring, so at most $N$ enqueue operations are allowed, where $N$ is the maximum capacity of the queue! After that, clear() must be invoked.
    Author:
    Joris Kinable
    • Constructor Detail

      • FixedSizeIntegerQueue

        public FixedSizeIntegerQueue​(int capacity)
        Create a queue of fixed size.
        Parameters:
        capacity - size of the queue
    • Method Detail

      • enqueue

        public void enqueue​(int e)
        Add an element to the queue.
        Parameters:
        e - element
      • poll

        public int poll()
        Poll the first element from the queue.
        Returns:
        the first element.
      • isEmpty

        public boolean isEmpty()
        Check if the queue has any items.
        Returns:
        true if the queue is empty
      • size

        public int size()
        Returns the number of items in the queue.
        Returns:
        number of items in the queue
      • clear

        public void clear()
        Empty the queue.
      • toString

        public String toString()
        Returns a textual representation of the queue.
        Overrides:
        toString in class Object
        Returns:
        a textual representation of the queue.