org.nfunk.jep.function
Class PostfixMathCommand

java.lang.Object
  extended by org.nfunk.jep.function.PostfixMathCommand
All Implemented Interfaces:
PostfixMathCommandI
Direct Known Subclasses:
Abs, Add, ArcCosine, ArcCosineH, ArcSine, ArcSineH, ArcTangent, ArcTangent2, ArcTanH, Arg, Assign, Binomial, Ceil, Comparative, ComplexPFMC, Conjugate, Cosine, CosineH, Cross, Define, Determinant, Diagonal, Diff, Divide, Dot, Ele, Ele, Eval, Exp, ExteriorProduct, Floor, FromBase, GAdd, GComparative, GDivide, GenMat, GetDiagonal, GList, GLogical, GMod, GMultiply, GNot, GPower, GSubtract, GUMinus, Id, If, Imaginary, Inverse, Length, List, Logarithm, Logical, MacroFunction, MDiff, MIf, Modulus, Multiply, NaturalLogarithm, Not, Polar, Power, Random, Range, Rank, Real, Round, Sine, SineH, Size, Solve, SquareRoot, Str, Subtract, Sum, SumType, Tangent, TanH, ToBase, Trace, Transpose, UMinus, VEle, VMap, VPower, VSum

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
 boolean checkNumberOfParameters(int n)
          Checks the number of parameters of the function.
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

checkNumberOfParameters

public boolean checkNumberOfParameters(int n)
Checks the number of parameters of the function. Functions which set numberOfParameter=-1 should overload this method

Specified by:
checkNumberOfParameters in interface PostfixMathCommandI
Parameters:
n - number of parameters function will be called with.
Returns:
False if an illegal number of parameters is supplied, true otherwise.

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 © 2007 Singular Systems