import java.util.NoSuchElementException; /** * The definition of the Queue interface * * @param * @author gtowell Modified Feb 14 2020 */ public interface QueueIntf { /** * The number of items in the queue * * @return the number of items in the queie */ int size(); /** * Return true iff the queue is empty * * @return true iff the queue is empty */ boolean isEmpty(); /** * Inserts the specified element into this queue if it is possible to do so * immediately without violating capacity restrictions, returning true upon * success and throwing an IllegalStateException if no space is currently * available. * * @param q the element to be added * @return true * @throws IllegalStateException if the element cannot be added at this time due * to capacity restrictions */ boolean add(Q q) throws IllegalStateException; /** * Retrieves and removes the head of this queue. This method differs from poll * only in that it throws an exception if this queue is empty. * * @return the removed element, if such an element exists * @throws NoSuchElementException if this queue is empty */ Q remove() throws NoSuchElementException; /** * Retrieves, but does not remove, the head of this queue. This method differs * from peek only in that it throws an exception if this queue is empty. * * @return the element at the head of the queue * @throws NoSuchElementException if this queue is empty */ Q element() throws NoSuchElementException; /** * Inserts the specified element into this queue if it is possible to do so * immediately without violating capacity restrictions, returning true upon * success and false on failure * * @param q the element to be added * @return true on success, false on failure */ boolean offer(Q q); /** * Retrieves and removes the head of this queue. This method differs from poll * only in that it throws an exception if this queue is empty. * * @return the removed element, or null if the queue is empty */ Q poll(); /** * Retrieves, but does not remove, the head of this queue. This method differs * from peek only in that it throws an exception if this queue is empty. * * @return the element at the head of the queue or null if the queue is empty */ Q peek(); }