org.jscience.ml.sbml.jep.function
Class PostfixMathCommand

java.lang.Object
  extended by org.jscience.ml.sbml.SBase
      extended by org.jscience.ml.sbml.SBaseId
          extended by org.jscience.ml.sbml.FunctionDefinition
              extended by org.jscience.ml.sbml.jep.function.PostfixMathCommand
All Implemented Interfaces:
PostfixMathCommandI, MathElement

public class PostfixMathCommand
extends FunctionDefinition
implements PostfixMathCommandI

Function classes extend this class. It is an implementation of the PostfixMathCommandI interface.

It includes a numberOfParameters member, that is checked when parsing the expression. This member should be initialized to an appropriate value for all classes extending this class. If an arbitrary number of parameters should be allowed, initialize this member to -1.


Field Summary
protected  int curNumberOfParameters
          Number of parameters to be used for the next run() invocation.
protected  int numberOfParameters
          Number of parameters a the function requires.
 
Fields inherited from class org.jscience.ml.sbml.SBaseId
id, name
 
Constructor Summary
PostfixMathCommand(int numParameters)
          Creates a new PostfixMathCommand class.
 
Method Summary
protected  void checkStack(java.util.Stack inStack)
          Check whether the stack is not null, throw an Exception if it is.
 int getNumberOfParameters()
          Return the required number of parameters.
 void run(java.util.Stack s)
          Throws an exception because this method should never be called under normal circumstances.
 void setCurNumberOfParameters(int n)
          Sets the number of current number of parameters used in the next call of run().
 void setNumberOfParameters(int n)
          Convenience method for use with the parser to set the parameters if they have changed.
 
Methods inherited from class org.jscience.ml.sbml.FunctionDefinition
getMath, setMath, toString
 
Methods inherited from class org.jscience.ml.sbml.SBaseId
getId, getName, setId, setName
 
Methods inherited from class org.jscience.ml.sbml.SBase
getAnnotations, getMetaid, getNotes, getRDF, printList, printShortForm, setMetaid, setRDF, setRDF
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

curNumberOfParameters

protected int curNumberOfParameters
Number of parameters to be used for the next run() invocation. Applies only if the required umber of parameters is variable (numberOfParameters = -1).


numberOfParameters

protected int numberOfParameters
Number of parameters a the function requires. Initialize this value to -1 if any number of parameters should be allowed.

Constructor Detail

PostfixMathCommand

public PostfixMathCommand(int numParameters)
Creates a new PostfixMathCommand class.

Method Detail

getNumberOfParameters

public int getNumberOfParameters()
Return the required number of parameters.

Specified by:
getNumberOfParameters in interface PostfixMathCommandI
Returns:
DOCUMENT ME!

run

public void run(java.util.Stack s)
         throws java.lang.Exception
Throws an exception because this method should never be called under normal circumstances. Each function should use it's own run() method for evaluating the function. This includes popping off the parameters from the stack, and pushing the result back on the stack.

Specified by:
run in interface PostfixMathCommandI
Parameters:
s - DOCUMENT ME!
Throws:
java.lang.Exception - DOCUMENT ME!

setCurNumberOfParameters

public void setCurNumberOfParameters(int n)
Sets the number of current number of parameters used in the next call of run(). This method is only called when the reqNumberOfParameters is -1.

Specified by:
setCurNumberOfParameters in interface PostfixMathCommandI
Parameters:
n - DOCUMENT ME!

setNumberOfParameters

public void setNumberOfParameters(int n)
Convenience method for use with the parser to set the parameters if they have changed.


checkStack

protected void checkStack(java.util.Stack inStack)
                   throws java.lang.Exception
Check whether the stack is not null, throw an Exception if it is.

Throws:
java.lang.Exception