Interface Queue<T>

  • Type Parameters:
    T - The type of object kept in the queue.
    All Superinterfaces:
    Collection<T>, java.lang.Iterable<T>
    All Known Implementing Classes:
    ArrayQueue, LinkedQueue, SynchronizedQueue

    public interface Queue<T>
    extends Collection<T>
    Interface representing a first-in, first-out (FIFO) queue when unsorted, and a priority queue when sorted.
    • Method Detail

      • enqueue

        void enqueue​(T item)
        Enqueues an item. If the queue is unsorted, the item is added at the tail of the queue (index 0). Otherwise, it is inserted at the appropriate index according to the priority/sort order.

        If there is a maximum queue length defined and the queue is already at the maximum length this new item will not be queued.

        Parameters:
        item - The item to add to the queue.
      • dequeue

        T dequeue()
        Removes the item from the head of the queue and returns it. Calling this method should have the same effect as: remove(getLength() - 1, 1);
        Returns:
        The (removed) object at the head of the queue.
      • peek

        T peek()
        Returns the item at the head of the queue without removing it from the queue. Returns null if the queue contains no items. Will also return null if the head item in the queue is null. isEmpty() can be used to distinguish between these two cases.
        Returns:
        The object at the head of the queue (not removed from the queue).
      • isEmpty

        boolean isEmpty()
        Tests the emptiness of the queue.
        Specified by:
        isEmpty in interface Collection<T>
        Returns:
        true if the queue contains no items; false, otherwise.
      • getLength

        int getLength()
        Returns:
        The length of the queue.
      • getMaxLength

        int getMaxLength()
        Returns:
        The maximum queue length allowed (0 means unlimited).
      • setMaxLength

        void setMaxLength​(int maxLength)
        Set the maximum allowed queue length (0 means unlimited).
        Parameters:
        maxLength - The maximum allowed length.