vmm.functions
Class Function

java.lang.Object
  extended by vmm.functions.Function
Direct Known Subclasses:
Expression, Function1, Function2, Function3

public class Function
extends java.lang.Object

Represents a real-valued function of any number of real arguments. A Function can only be created by a Parser. This class has subclasses Expression, Function1, Function2, and Function3, that represent functions of zero, one, two, and three arguments; the subclasses exist only to provide more natural value() methods that take the expected number of arguments.

See Also:
Parser.parseFunction(String, String, String[])

Field Summary
protected  vmm.functions.ProgFunction func
           
 
Method Summary
 int getArity()
          Get the number of arguments required by this function.
 java.lang.String getName()
          Get the name of the Function.
 void setName(java.lang.String name)
          Change the name of this function.
 double value(double[] argumentValues)
          Find the value of this function for a specified list of arguments.
 double value(double[] argumentValues, EvalStack stack)
          Find the value of this function for a specified list of arguments.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

func

protected vmm.functions.ProgFunction func
Method Detail

getName

public java.lang.String getName()
Get the name of the Function. The name was specified in the call to Parser.parseFunction(String, String, String[]) that created this function. It can be null. A non-null name is really only required if this Function is to be added to a Parser so that it can be used in expressions that are parsed by that parser.


setName

public void setName(java.lang.String name)
Change the name of this function. It should not be changed after the function has been added to a Parser; even if it is changed, the Parser will continue to use the old name.


getArity

public int getArity()
Get the number of arguments required by this function.


value

public double value(double[] argumentValues)
Find the value of this function for a specified list of arguments. This method evaluates the function using an EvalStack that is unique to the current Thread, which allows thread-safe evaluation.

Parameters:
argumentValues - The length of this array must be the same as the number of arguments of the function. If the function has arrity zero, then the argumentValues array can be null.
Returns:
the value of the function at the specified arguments.
Throws:
java.lang.IllegalArgumentException - if the number of arguments is incorrect.

value

public double value(double[] argumentValues,
                    EvalStack stack)
Find the value of this function for a specified list of arguments. This method evaluates the function using an EvalStack that is provided as a parameter to this method.

Parameters:
argumentValues - the values of the arguments. The length of this array must be the same as the number of arguments of the function. If the function has arrity zero, then the argumentValues array can be null.
stack - a non-null EvalStack that will be used for computing the value of this Function
Returns:
the value of the function at the specified arguments.
Throws:
java.lang.IllegalArgumentException - if the number of arguments is incorrect.