vmm.functions
Class EvalStack

java.lang.Object
  extended by vmm.functions.EvalStack

public final class EvalStack
extends java.lang.Object

An object of type EvalStack is used in the evaluation of an expression or function (as defined, for example, in the classes Expression, Function, and ComplexFunction). The value() methods in such expressions and fuctions can, optionally, take a parameter of type EvalStack. In fact, the only thing that you can do with an EvalStack, outside of the package vmm.functions, is construct it and pass it as a parameter to one of these value() methods; the only reason to do this is to evaluate functions and expressions in a thread-safe way.


Constructor Summary
EvalStack()
          Create an EvalStack with an initial size of 30.
EvalStack(int initialSize)
          Create an EvalStack with a specified initial size.
 
Method Summary
static EvalStack perThread()
          Returns an EvalStack that is unique to the current thread.
static EvalStack perThread(java.lang.Thread thread)
          The first time this method is called by a given thread, it creates and returns a new EvalStack; subsequent calls with return the same EvalStack rather than create a new one.
static void perThreadRelease(java.lang.Thread thread)
          Discard the EvalStack, if any, that has been created for the specified thread by perThread() or perThread(Thread).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EvalStack

public EvalStack()
Create an EvalStack with an initial size of 30.


EvalStack

public EvalStack(int initialSize)
Create an EvalStack with a specified initial size. The size will grow, if necessary, so it is generally sufficient to use the default constructor.

Parameters:
initialSize - the initial size of the stack. If a size less than 1 is specified, then the initial size will be 1.
Method Detail

perThread

public static final EvalStack perThread()
Returns an EvalStack that is unique to the current thread. This method simply calls perThread(Thread), with Thread.currentThread() as its parameter.


perThread

public static final EvalStack perThread(java.lang.Thread thread)
The first time this method is called by a given thread, it creates and returns a new EvalStack; subsequent calls with return the same EvalStack rather than create a new one. This meant to support thread-safe evalution of functions; this capability is used in evaluation methods such as Expression.value(), Function.value(double[]) and ComplexFunction.value(Complex[]). The method perThreadRelease(Thread) can be called to discard the EvalStack that has been created for a given thread.

Parameters:
thread - the Thread whose associated EvalStack is to be returned. If thread is null, the return value is also null.

perThreadRelease

public static void perThreadRelease(java.lang.Thread thread)
Discard the EvalStack, if any, that has been created for the specified thread by perThread() or perThread(Thread).

Parameters:
thread - The thread whose EvalStack is to be discarded. If the value is null or if there is not EvalStack for the specified stack, nothing is done; this is not an error.