goldman.collection.positional
Class Stack<E>

java.lang.Object
  extended by goldman.collection.positional.Stack<E>

public class Stack<E>
extends Object

More specialized than a buffer, a stack is natural for applications that insert and remove elements only at one end of the buffer. That is, a stack implements a last-in-first-out (LIFO) line. A stack is a more specialized abstraction than a buffer that maintains a last-in, first-out (LIFO) line. A stack is logically viewed as a vertical line in which elements are inserted and removed at the "top" of the stack.


Constructor Summary
Stack()
          Creates an bounded, untracked stack with a default initial capacity
Stack(int capacity)
          Creates an unbounded, untracked stack with the given capacity
Stack(int capacity, boolean bounded)
          Creates an untracked stack satisfying the given requirements
Stack(int capacity, boolean bounded, boolean tracked)
          Creates a stack satisfying the given requirements
 
Method Summary
 void clear()
          Removes all elements from the stack.
 boolean contains(E value)
          Returns true if and only if the given value is contained within the stack.
 int getSize()
          Returns the number of elements in the stack.
 boolean isEmpty()
          Returns true if and only if there are no elements in the stack.
 Locator<E> iterator()
          Returns an iterator initialized at FORE.
 E peek()
          Returns the object on the top of the stack.
 E pop()
          Removes the item at the top of the stack
 void push(E element)
          Inserts the given element at the top of the stack.
 String toString()
          Returns a string representation of the elements in the stack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Stack

public Stack(int capacity,
             boolean bounded,
             boolean tracked)
Creates a stack satisfying the given requirements

Parameters:
capacity - the initial capacity for the stack
bounded - a boolean that indicates if the stack should be bounded
tracked - a boolean that indicates if a tracked implementation is needed

Stack

public Stack()
Creates an bounded, untracked stack with a default initial capacity


Stack

public Stack(int capacity)
Creates an unbounded, untracked stack with the given capacity

Parameters:
capacity - the initial capacity for the stack

Stack

public Stack(int capacity,
             boolean bounded)
Creates an untracked stack satisfying the given requirements

Parameters:
capacity - the initial capacity for the stack
bounded - which indicates if the stack should be bounded
Method Detail

contains

public boolean contains(E value)
Returns true if and only if the given value is contained within the stack.


clear

public void clear()
Removes all elements from the stack.


getSize

public int getSize()
Returns the number of elements in the stack.


isEmpty

public boolean isEmpty()
Returns true if and only if there are no elements in the stack.


iterator

public Locator<E> iterator()
Returns an iterator initialized at FORE.


toString

public String toString()
Returns a string representation of the elements in the stack.

Overrides:
toString in class Object

peek

public E peek()
Returns the object on the top of the stack. The stack is not changed Returns the object on the top of the stack. The stack is not changed.


push

public void push(E element)
Inserts the given element at the top of the stack.

Parameters:
element - the new element to insert
Throws:
AtCapacityException - a bounded stack is full

pop

public E pop()
Removes the item at the top of the stack

Returns:
the removed element
Throws:
NoSuchElementException - the stack is empty