package rd222dv_assign2.Queues; import java.util.Iterator; /** * An interface representing a simple Queue. This interface defines the required * functionality for all Queue implementations. It provides support * for accessing (enqueue, dequeue, first, last) at the required position in the * list. It also contains basic support for sequential access of the whole * content (i.e., iterators). * Inserts Object element at the last * position of the queue. For removing elements from the queue they can be * dequeued, and the element at the first position will be removed * Illegal accesses (outside current range) should throw an unchecked exception of type * IndexOutOfBoundsException. * * Currently available Queue implementations in the * linked package are: * * * @author Ruth Dirnfeld * @version 1.0 * @since 2017-02-01 */ public interface Queue { /** * Returns the size of the queue * * @return the size of the queue; */ public int size(); // current queue size /** * Returns true if no elements in Queue left * * @return true if this queue is empty; */ public boolean isEmpty(); // true if queue is empty /** * Enqueues an element into the queue. If the Queue is empty, the element * inserted is the first element in the queue. Every inserted element after * it will be at the position after it * * @param element adding element to the queue and returning element at the last position of * the queue * */ public void enqueue(Object element); // add element at end of queue /** * Dequeues an element from the queue. It takes the element at head (first) * position) and removes it. If the Queue is empty, an exception will be * thrown. * * @return return and remove first element. * @throws IndexOutOfBoundsException * if Queue outside current range * [0, size]. */ public Object dequeue(); // return and remove first element. /** * Returns the first element in the Queue List without removing it, if there * are no elements it throws an exception * * @return return (without removing) first element * @throws IndexOutOfBoundsException * if Queue outside current range * [0, size]. */ public Object first(); // return (without removing) first element /** * Returns the last element in the Queue List without removing it, if there * are no elements it throws an exception * * @return return (without removing) last element * @throws IndexOutOfBoundsException * if Queue outside current range * [0, size]. */ public Object last(); // return (without removing) last element /** * Returns a string representation of the current list content separated * with commas. * * * @return string representation of the content. */ public String toString(); // return a string representation of the queue // content /** *Returns an iterator that iterates over the Objects in first in first out order * @return an iterator that iterates over the Objects in first in first out order */ public Iterator iterator(); // element iterator }