org.nfunk.jep.function
Class PostfixMathCommand

java.lang.Object
  extended byorg.nfunk.jep.function.PostfixMathCommand
All Implemented Interfaces:
PostfixMathCommandI
Direct Known Subclasses:
Abs, Add, ArcCosine, ArcCosineH, ArcSine, ArcSineH, ArcTangent, ArcTangent2, ArcTanH, Arg, Assign, Comparative, ComplexPFMC, Cosine, CosineH, Cross, Diff, Divide, Dot, Ele, Eval, Exp, ExteriorProduct, GAdd, GComparative, GDivide, GList, GLogical, GMod, GMultiply, GNot, GPower, GSubtract, GUMinus, If, Imaginary, List, Logarithm, Logical, MacroFunction, MIf, Modulus, MPower, Multiply, NaturalLogarithm, Not, Polar, Power, Random, Real, Sine, SineH, SquareRoot, Str, Subtract, Sum, SumType, Tangent, TanH, UMinus

public class PostfixMathCommand
extends java.lang.Object
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.
 
Constructor Summary
PostfixMathCommand()
          Creates a new PostfixMathCommand class.
 
Method Summary
protected  void checkStack(java.util.Stack inStack)
          Check whether the stack is not null, throw a ParseException 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().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

numberOfParameters

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


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).

Constructor Detail

PostfixMathCommand

public PostfixMathCommand()
Creates a new PostfixMathCommand class.

Method Detail

checkStack

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

Throws:
ParseException

getNumberOfParameters

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

Specified by:
getNumberOfParameters in interface PostfixMathCommandI

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

run

public void run(java.util.Stack s)
         throws ParseException
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
Throws:
ParseException


http://www.singularsys.com/jep Copyright © 2004 Singular Systems