Interface BoundedQueue<E>

  • All Known Implementing Classes:
    ArrayQueue

    public interface BoundedQueue<E>
    Provides an interface for an bounded queue whose elements are of type E.

    BoundedQueue Invariant: A collection of objects of type E is maintained in first-in first-out order: The object that is visible at the front of the queue is the object that was first inserted onto it, and not yet removed. The number of objects on the queue is never allowed to exceed this queue's (positive integer) capacity.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      int capacity()
      Reports the capacity of this bounded queue.
      void insert​(E x)
      Inserts a new entry onto the queue.
      boolean isEmpty()
      Reports whether the queue is currently empty without changing it.
      E peek()
      Reports the element at the front of the queue without changing it.
      E remove()
      Removes an element from the front of the queue and reports it.
    • Method Detail

      • insert

        void insert​(E x)
             throws QueueFullException
        Inserts a new entry onto the queue.
        Parameters:
        x - the object to be inserted onto the queue
        Throws:
        QueueFullException - if the queue is already full

        Precondition:
        1. The BoundedQueue Invariant is satisfied.
        2. An element x of type E has been given as input.
        Postcondition:
        1. The BoundedQueue Invariant is satisfied.
        2. If the number of objects presently on this bounded queue was less than the bounded queue's capacity, then the input object x has been inserted onto the rear of the queue (which is otherwise unchanged).
        3. If the number of objects presently on the bounded queue was equal to the bounded queue's capacity, then a QueueFullException is thrown and the queue is not changed.
      • peek

        E peek()
        Reports the element at the front of the queue without changing it.
        Returns:
        the element at the front of the queue
        Throws:
        java.util.NoSuchElementException - if the queue is empty

        Precondition:
        1. The BoundedQueue Invariant is satisfied.
        Postcondition:
        1. The BoundedQueue invariant is satisfied.
        2. The bounded queue is not changed.
        3. If the bounded queue was not empty before this operation then the element at the front is returned as output.
        4. If the bounded queue was empty before this operation then a NoSuchElementException is thrown.
      • remove

        E remove()
        Removes an element from the front of the queue and reports it.
        Returns:
        the element removed from the queue
        Throws:
        java.util.NoSuchElementException - if the queue is already empty

        Precondition:
        1. The BoundedQueue Invariant is satisfied.
        Postcondition:
        1. The BoundedQueue Invariant is satisfied.
        2. If the bounded queue was not empty before this operation then the element at the front of the queue (which is otherwise unchanged) is removed and this element is returned as output.
        3. If the bounded queue was empty before this operation then a NoSuchElementException is thrown and the queue is not changed.
      • isEmpty

        boolean isEmpty()
        Reports whether the queue is currently empty without changing it.
        Returns:
        true if the queue is empty, and false otherwise

        Precondition:
        1. The BoundedQueue Invariant is satisfied.
        Postcondition:
        1. The BoundedQueue Invariant is satisfied.
        2. The bounded queue is not changed.
        3. If the bounded queue was empty before this operation then “true” is returned as output.
        4. If the bounded queue was not empty before this operation then “false” is returned as output.
      • capacity

        int capacity()
        Reports the capacity of this bounded queue.
        Returns:
        the capacity of this BoundedQueue

        Precondition:
        1. The BoundedQueue Invariant is satisfied.
        Postcondition:
        1. The BoundedQueue Invariant is satisfied.
        2. The bounded queue is not changed.
        3. The capacity of this bounded queue is returned as output.