Initial code for the Stack Lab
package umm.softwaredesign.stacklab;
/**
* Implementation of the StackIF interface for a basic stack.
*
* @author Nic McPhee, last changed by $Author: elenam $
* on $Date: 2005/08/28 21:49:44 $
* @version $Revision: 1.1.1.1 $
*/
public class Stack implements StackIF {
/**
* Construct an empty stack.
*/
public Stack() {
super();
throw new UnsupportedOperationException();
}
/**
* Makes a (shallow) copy of the given stack. "Shallow" here
* means that we don't copy the items on the stack as well, so
* both stacks contain references to the same items in the same
* order.
*
* We need this for (at least) testing purposes, as we want to be
* able to make copies of stacks before we manipulate them so we
* can compare the stack at the end of a process to the stack we
* had at the beginning. There are also no doubt non-testing
* contexts where cloning could be useful as well.
*
* @param stack the stack to copy
*/
public Stack(final Stack stack) {
throw new UnsupportedOperationException();
}
/**
* Push the specified value onto the stack.
*
* @param value the value to be pushed.
*/
// WARNING - this parameter should be final so you can't reassign to it
// in the body of the method. This should be flagged by Checkstyle/PMD.
public final void push(final Object value) {
// WARNING there are tabs in this method instead of
// groups of spaces. This should be flagged by Checkstyle/PMD.
throw new UnsupportedOperationException();
}
/**
* Return the value on top of the stack. This does not change the
* stack in any way. If the stack is empty a StackUnderflowException
* is thrown.
*
* @return the top value on the stack
*/
public final Object top() {
// This should throw a StackUnderflowException if the stack is empty.
throw new UnsupportedOperationException();
}
/**
* Removes the top value from the stack. If the stack is empty a
* StackUnderflowException is thrown.
*/
// WARNING - this method should be declared as final to prevent it from
// being overridden incorrectly in a subclass. This should be flagged
// by Checkstyle/PMD.
public void pop() {
// This should throw a StackUnderflowException if the stack is empty.
throw new UnsupportedOperationException();
}
/**
* Computes the size of the stack.
*
* @return the number of elements on the stack
*/
public final int size() {
throw new UnsupportedOperationException();
}
/**
* Determines if a stack is empty.
*
* @return true if the stack is empty, false otherwise
*/
public final boolean isEmpty() {
throw new UnsupportedOperationException();
}
/**
* Determines if a stack is full.
*
* If you use an appropriate Java library Container class to store
* the stack elements, this should always return false.
*
* @return true if the stack is full, false otherwise
*/
public final boolean isFull() {
throw new UnsupportedOperationException();
}
/**
* Determines if this stack is equal to another. Two stacks are equal
* if they have the same elements (as determined by the equals
* on the underlying object) in the same order.
*
* @param other the object to compare to. equals() will return false
* if other isn't a Stack.
*
* @return true exactly when this stack is equal to other.
*/
public final boolean equals(final Object other) {
throw new UnsupportedOperationException();
}
/**
* Computes a hash code for this stack.
*
* We need to override the default behavior for hashCode() because
* we've overridden the default behavior of equals(). If we don't
* also do hashCode(), then, e.g., containers like HashSet won't
* won't work if we put stacks in them. See Item 8 in Bloch's
* Effective Java for more on this.
*
* @return a hashCode for this stack
*/
public final int hashCode() {
throw new UnsupportedOperationException();
}
/**
* Generate a string representation of our stack. A stack
* containing elements [x0, x1, x2, ..., xn] (where x0 is the
* bottom of the stack and x1 is the top) is represented by
* the string "Stack[s0, s1, s2, ..., sn]", where the si are
* the string (printed) representations of the elements xi.
*
* @return a string of this stack
*/
public final String toString() {
throw new UnsupportedOperationException();
}
}
This is an example from CSci 3601 course.