calculator
Class RatPolyStack

java.lang.Object
  extended by calculator.RatPolyStack
All Implemented Interfaces:
java.lang.Iterable<RatPoly>

public final class RatPolyStack
extends java.lang.Object
implements java.lang.Iterable<RatPoly>

RatPolyStack is a mutable finite sequence of RatPoly objects.

Each RatPolyStack can be described by [p1, p2, ... ], where [] is an empty stack, [p1] is a one element stack containing the Poly 'p1', and so on. RatPolyStacks can also be described constructively, with the append operation, ':'. such that [p1]:S is the result of putting p1 at the front of the RatPolyStack S.

A finite sequence has an associated size, corresponding to the number of elements in the sequence. Thus the size of [] is 0, the size of [p1] is 1, the size of [p1, p1] is 2, and so on.


Constructor Summary
RatPolyStack()
           
 
Method Summary
 void add()
          Pops two elements off of the stack, adds them, and places the result on top of the stack.
 void clear()
          Clears the stack.
 void differentiate()
          Pops the top element off of the stack, differentiates it, and places the result on top of the stack.
 void div()
          Divides the next from top poly by the top poly, pops both off the stack, and places the result on top of the stack.
 void dup()
          Duplicates the top RatPoly on this.
 RatPoly getNthFromTop(int index)
          Returns the RatPoly that is 'index' elements from the top of the stack.
 void integrate()
          Pops the top element off of the stack, integrates it, and places the result on top of the stack.
 java.util.Iterator<RatPoly> iterator()
          Returns an iterator of the elements contained in the stack.
 void mul()
          Pops two elements off of the stack, multiplies them, and places the result on top of the stack.
 RatPoly pop()
          Removes and returns the top RatPoly.
 void push(RatPoly p)
          Pushes a RatPoly onto the top of this.
 int size()
          Returns the number of RayPolys in this RatPolyStack.
 void sub()
          Subtracts the top poly from the next from top poly, pops both off the stack, and places the result on top of the stack.
 void swap()
          Swaps the top two elements of this.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RatPolyStack

public RatPolyStack()
Effects:
Constructs a new RatPolyStack, [].
Method Detail

size

public int size()
Returns the number of RayPolys in this RatPolyStack.

Returns:
the size of this sequence.

push

public void push(RatPoly p)
Pushes a RatPoly onto the top of this.

Effects:
this_post = [p]:this
Modifies:
this
Requires:
p != null

pop

public RatPoly pop()
Removes and returns the top RatPoly.

Returns:
p where this = [p]:S
Effects:
If this = [p]:S then this_post = S
Modifies:
this
Requires:
this.size() > 0

dup

public void dup()
Duplicates the top RatPoly on this.

Effects:
If this = [p]:S then this_post = [p, p]:S
Modifies:
this
Requires:
this.size() > 0

swap

public void swap()
Swaps the top two elements of this.

Effects:
If this = [p1, p2]:S then this_post = [p2, p1]:S
Modifies:
this
Requires:
this.size() >= 2

clear

public void clear()
Clears the stack.

Effects:
this_post = []
Modifies:
this

getNthFromTop

public RatPoly getNthFromTop(int index)
Returns the RatPoly that is 'index' elements from the top of the stack.

Returns:
If this = S:[p]:T where S.size() = index, then returns p.
Requires:
index >= 0 && index < this.size()

add

public void add()
Pops two elements off of the stack, adds them, and places the result on top of the stack.

Effects:
If this = [p1, p2]:S then this_post = [p3]:S where p3 = p1 + p2
Modifies:
this
Requires:
this.size() >= 2

sub

public void sub()
Subtracts the top poly from the next from top poly, pops both off the stack, and places the result on top of the stack.

Effects:
If this = [p1, p2]:S then this_post = [p3]:S where p3 = p2 - p1
Modifies:
this
Requires:
this.size() >= 2

mul

public void mul()
Pops two elements off of the stack, multiplies them, and places the result on top of the stack.

Effects:
If this = [p1, p2]:S then this_post = [p3]:S where p3 = p1 * p2
Modifies:
this
Requires:
this.size() >= 2

div

public void div()
Divides the next from top poly by the top poly, pops both off the stack, and places the result on top of the stack.

Effects:
If this = [p1, p2]:S then this_post = [p3]:S where p3 = p2 / p1
Modifies:
this
Requires:
this.size() >= 2

differentiate

public void differentiate()
Pops the top element off of the stack, differentiates it, and places the result on top of the stack.

Effects:
If this = [p1]:S then this_post = [p2]:S where p2 = derivative of p1
Modifies:
this
Requires:
this.size() >= 1

integrate

public void integrate()
Pops the top element off of the stack, integrates it, and places the result on top of the stack.

Effects:
If this = [p1]:S then this_post = [p2]:S where p2 = indefinite integral of p1 with integration constant 0
Modifies:
this
Requires:
this.size() >= 1

iterator

public java.util.Iterator<RatPoly> iterator()
Returns an iterator of the elements contained in the stack.

Specified by:
iterator in interface java.lang.Iterable<RatPoly>
Returns:
an iterator of the elements contained in the stack in order from the bottom of the stack to the top of the stack.