
/* decorator pattern good choice for 
 * pre & post conditions:  
 * "design-by-contract"
 * 
 * each method will have a pre-condition and
 * a post-condition
 * 
 * you can use this decorator class, which
 * provides pre-condition wrappers, for 
 * debugging purposes
 * 
 * the post-condition wrappers can also
 * be written as well
 */

public class StackCheckDecorator 
implements Stack {

	private Stack m_inner;
	
	public StackCheckDecorator (Stack inner) {
		m_inner = inner;
	}
	
	// pre_condition for push: o is not null
	// post: puts it on the stack
	public void push(Object o) {
		if(o == null) {
			System.out.println("You are a bad person: push() does not like nullness.");
			System.exit(-1);
		}
		m_inner.push(o);
	}

	// pre_condition for pop: stack is non-empty
	// post: will be removed
	public Object pop() {
		if(m_inner.getLength() <= 0) {
			System.out.println("What are you thinking: pop() does not like to be called on an empty stack.");
			System.exit(-2);
		}
		return(m_inner.pop());
	}

	// pre_condition for getTop: stack is non-empty
	// post: return the top
	public Object getTop() {
		if(m_inner.getLength() <= 0) {
			System.out.println("Something's wrong with you: getTop() does not like to be called on an empty stack.");
			System.exit(-2);
		}
		return(m_inner.getTop());
	}

	// pre_condition for getLength: none
	// post: returns the length
	public int getLength() {
		return(m_inner.getLength());
	}

	// pre_condition for getLength: none
	// post: clears it
	public void clear() {
		m_inner = null;
	}

}
