tenua.symbol
Class DoubleStack

java.lang.Object
  extended by tenua.symbol.DoubleStack
All Implemented Interfaces:
java.lang.Cloneable

public class DoubleStack
extends java.lang.Object
implements java.lang.Cloneable

A simple stack of doubles. Until autoboxing is implemented, it's too hard to keep casting back and forth, using java.util.Stack.
Is NOT thread-safe.

Author:
Daniel Wachsstock

Constructor Summary
DoubleStack()
          construct a new DoubleStack with initial capacity == 10.
DoubleStack(int capacity)
          construct a new DoubleStack with initial capacity == capacity.
DoubleStack(Vec d)
          construct a new DoubleStack with given initial values.
 
Method Summary
 void clear()
          clear the stack.
 java.lang.Object clone()
          clones the stack
 Vec getValues()
          return a copy of the numbers in the stack
 double peek()
          return the top of the stack without removing it.
 double pop()
          pop a value off the stack.
 void push(double d)
          push a value onto the stack.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DoubleStack

public DoubleStack()
construct a new DoubleStack with initial capacity == 10.


DoubleStack

public DoubleStack(int capacity)
construct a new DoubleStack with initial capacity == capacity.

Parameters:
capacity - the initial capacity

DoubleStack

public DoubleStack(Vec d)
construct a new DoubleStack with given initial values.

Parameters:
d - the values to load onto the stack. The top of the stack will be d.get(d.size()-1); the bottom of the stack will be d.get(0);
Method Detail

push

public void push(double d)
push a value onto the stack.

Parameters:
d - the value to push

pop

public double pop()
pop a value off the stack.

Returns:
the previous top of the stack
Throws:
EmptyStackException - if the stack is empty

peek

public double peek()
return the top of the stack without removing it.

Returns:
the top of the stack
Throws:
EmptyStackException - if the stack is empty

clear

public void clear()
clear the stack.


getValues

public Vec getValues()
return a copy of the numbers in the stack

Returns:
a Vec_array that contains the values in the stack

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
clones the stack

Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException