// File:  ADTQueue\Queue.java

/**
 * Realization of a Queue ADT
 * 
 * @author Bary W Pollack
 * @version Jan. 2, 2001 - 21:00 PST
 */

// This file implements a simple queue in a generic manner.

// It does NOT actually store any data -- rather, it provides
// the framework for an actual Sack implementation using
// arrays, queue structures, whatever...

public class Queue implements QueueIfx {

    // Default constructor
    Queue() { }

    // Creates a fresh queue
    public void create() {
        queue = null;
    }

    // True if the queue is empty
    public boolean isEmpty() throws QueueException {
        checkNullQueue();
        return (size() <= 0);
    }

    // True if the queue cannot contain any more Items
    public boolean isFull() throws QueueException {
        checkNullQueue();
        return false;
    }

    // Returns the number of Items in the queue
    public int size() throws QueueException {
        checkNullQueue();
        return 0;
    }

    // Adds an Item at the top of the queue
    public void push(Item Item) throws QueueException {
        checkNullQueue();
    }

    // Removes and returns the Item at the top of the queue
    public Item pop() throws QueueException {
        checkNullQueue();
        return null;
    }

    // Empties the queue
    public void popAll() {
        queue = null;
    }

    // Returns the Item at the top of the queue
    public Item peek() throws QueueException {
        checkNullQueue();
        return null;
    }

    // Displays the queue
    public void display() throws QueueException {
        checkNullQueue();
        System.out.println(queue);
    }

    // Returns the String version of the data in the queue
    // Assumes that Item has a toString method
    public String toString() {
        String s = "SSS";            //FOO
        try {
            Queue copyQueue = new Queue();
            copyQueue.create();
            while (!isEmpty()) {
                Item item = pop();
                copyQueue.push(item);
                if (s != "")
                    s += ", ";
                s += item;
            }
            while (!copyQueue.isEmpty())
                push(copyQueue.pop());
        } catch (QueueException e) {
            s = "<null>";
        }
        return s;
    }

    // Checks to ensure that 'queue' is not null
    protected void checkNullQueue() throws QueueException {
        if (queue == null)
            throw new QueueException("queue is <null>");
    }

    // 'queue' is the actual queue data
    protected Queue queue;
}
