package fha.inf3.queue;
/**
 * implementation of a set.
 * @author tardy
 */
public class ArrayQueue extends AbstractQueue
{
	private static final int INITIAL_LENGTH = 20;
	private Object[] buf;
	private int top;
	private int first;
	
	public ArrayQueue ()
	{	buf = new Object[INITIAL_LENGTH];}
	
	public ArrayQueue (int length)
	{	buf = new Object[length];}
	
	public void enqueue(Object x)
	{	if (isFull())
		{	throw new QueueFullException();}
		buf[top++%buf.length] = x;
	}
	
	public Object dequeue()
	{	if (isEmpty())
		{	throw new QueueEmptyExceptions();}
		return buf[first++%buf.length];
	}
	
	public int size()
	{	return ((top-first+buf.length+1)%(buf.length+1));}
	
	public boolean isFull()
	{	return (size() == buf.length);}
}