// // simple bounded stack class for arbitrary objects // used only for JUnit explanation ... // public class BoundedStack { private Object[] stack; private int tos = -1; public BoundedStack(int capacity) { stack = new Object[capacity]; } public void push(Object o) { if (++tos < getCapacity()) stack[tos] = o; else throw new RuntimeException("stack full"); } public Object peek() { return (tos < 0) ? null : stack[tos]; } public Object pop() { if (tos < 0) return null; else return stack[--tos]; } public int getCapacity() { return (stack == null) ? 0 : stack.length; } }