// © Copyright 1997, Joseph Bergin. All rights reserved.import java.util.Enumeration;/** Implements a double ended queue of Object. Items may be inserted or removed* from either end.  When used in only one direction it will implement FIFO * storage.  When used at only one end, it will implement LIFO storage.  All operations* except clone and toString require constant time.  These latter are linear algorithms in * the number of elements in the Queue.  */public class Queue implements Cloneable{		/**	Create an empty Queue.	*	*/	public Queue(){}	/**	Insert at the rear of the Queue	* @param the element to be inserted	*/	public synchronized void enqueue( Object  e) // Insert at rear	{	_elements.insert(_elements.end(), e);	}	/** Remove the element at the front	* @return the item removed	*/	public synchronized Object dequeue()	// Remove from front.	{	return _elements.remove(_elements.begin());	}	/** Insert at the front of the Queue	* @param the item to be inserted	*/	public synchronized void enqueueFront( Object  e)	{	_elements.insert(_elements.begin(), e);	}	/** Remove the item at the rear of the Queue.	* @return the item removed.	*/	public synchronized Object dequeueRear()	{	return _elements.remove(_elements.end());	}	/** Is the Queue empty?	* @return whether the queue is empty or not.	*/	public synchronized boolean isEmpty()	{	return _elements.isEmpty();	}		/** Obtain a reference to the first item	* @return the front item in the Queue	*/	public synchronized Object atFront()	{	return _elements.begin().get();	}		/** Obtain a reference to the last item.	* @return the last item in the Queue.	*/	public synchronized Object atRear()	{	return _elements.end().get();	}		/** Clear the Queue	*	*/	public synchronized void removeAllElements() 	{	while(! _elements.isEmpty())			_elements.remove(_elements.begin());	}		/** Obtain the length of the queue	* @return the number of elements in the Queue.	*/	public synchronized long size()	{	return _elements.size();	}		/** Create standard Enumeration over the Queue.  The elements	* will be enumerated from first to last. 	* @return the Enumeration	*/	public synchronized Enumeration elements()	{	return _elements.elements();	}		/** Obtain a copy of the Queue	* @return a faithful copy of the Queue.  	*/	public synchronized Object clone()	{	Queue result = new Queue();		result._elements = (LList)_elements.clone();		return result;	}		/** Return a space separated list of elements of the Queue.	* @return a string representation of the Queue	*/	public synchronized String toString()	{	return _elements.toString();	}	private LList _elements = new LList();}