scranton.stack
Class StackViaLinear1

java.lang.Object
  extended byscranton.stack.StackViaLinear1
All Implemented Interfaces:
Stack

public class StackViaLinear1
extends java.lang.Object
implements Stack

An implementation of the Stack interface applying the the Linear1 class via composition. Invariant: The class warranty is voided is a client directly applies any Linear1 class method.


Field Summary
protected  Linear1 actual
          The stack is provided through aggregation, as a protected attribute within the class.
 
Constructor Summary
StackViaLinear1()
          Constructs an empty stack.
 
Method Summary
 Stack factory()
           
 boolean isEmpty()
          Stack does not change, returns true iff the stack is empty.
 java.lang.Object pop()
          Decrease the size of the stack by one by removing and returning the object at the top.
 void push(java.lang.Object item)
          Increase the size of the stack by one by placing item as the new top of the stack.
 java.lang.Object topOf()
          Stack does not change, returns the reference to the top object in the stack.
 java.lang.String toString()
          Returns a string representation of the stack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

actual

protected Linear1 actual
The stack is provided through aggregation, as a protected attribute within the class.

Constructor Detail

StackViaLinear1

public StackViaLinear1()
Constructs an empty stack.

Method Detail

isEmpty

public boolean isEmpty()
Description copied from interface: Stack
Stack does not change, returns true iff the stack is empty.

Specifications:
S'=S
Return S==()

Specified by:
isEmpty in interface Stack
Returns:
boolean this==().

topOf

public java.lang.Object topOf()
Description copied from interface: Stack
Stack does not change, returns the reference to the top object in the stack.

Specifications:
S!=()
S'=S

Return an-1

Specified by:
topOf in interface Stack
Returns:
Object Top of stack.

push

public void push(java.lang.Object item)
Description copied from interface: Stack
Increase the size of the stack by one by placing item as the new top of the stack.

Specifications:
S'=(S, obj)

Specified by:
push in interface Stack
Parameters:
item - The new top of stack

pop

public java.lang.Object pop()
Description copied from interface: Stack
Decrease the size of the stack by one by removing and returning the object at the top. Note: that the stack cannot be empty.

Specifications:
S!=()
S = (S', an-1)
Return: an-1

Specified by:
pop in interface Stack
Returns:
Object Top of stack.

factory

public Stack factory()

toString

public java.lang.String toString()
Description copied from interface: Stack
Returns a string representation of the stack. The format is, "TOP[Otop\t...\tObottom]BOTTOM"

Specified by:
toString in interface Stack