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