public abstract class PostfixMathCommand extends java.lang.Object implements PostfixMathCommandI
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.
The asString(int, java.lang.Object)
and similar method are convenience
methods for use by subclasses to ease conversion of arguments to particular types.
Modifier and Type | Field and Description |
---|---|
protected int |
curNumberOfParameters
Number of parameters to be used for the next run() invocation.
|
java.lang.String |
name |
static java.lang.Double |
NaN
Double.valueOf(Double.NaN)
|
protected int |
numberOfParameters
Number of parameters a the function requires.
|
Constructor and Description |
---|
PostfixMathCommand()
Creates a new PostfixMathCommand class.
|
PostfixMathCommand(int nParam)
Creates a new PostfixMathCommand class.
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.Object[] |
asArray(java.util.Stack<java.lang.Object> stack)
Pop the arguments off the stack and put them in an array
|
protected boolean |
asBool(int pos,
java.lang.Object value,
boolean allowNumbers)
Attempt to convert argument to a boolean
|
protected double |
asDouble(int position,
java.lang.Object value)
Converts an argument to a double, with error checking, floating point values will be rounded.
|
protected int |
asInt(int position,
java.lang.Object value)
Converts an argument to a int, floating point values will be rounded.
|
protected long |
asLong(int position,
java.lang.Object value)
Converts an argument to a long, with error checking, floating point values will be rounded.
|
protected int |
asStrictInt(int position,
java.lang.Object value)
Converts an argument to a int, floating point values must represent integers.
|
protected java.lang.String |
asString(int position,
java.lang.Object value)
Converts an argument to a string, with error checking.
|
boolean |
checkNumberOfParameters(int n)
Checks the number of parameters of the function.
|
java.lang.String |
getName()
The name of the function used in error messages
|
int |
getNumberOfParameters()
Return the required number of parameters.
|
void |
run(java.util.Stack<java.lang.Object> 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 |
setName(java.lang.String name)
Sets the name of the function used for error messages
|
java.lang.String |
toString() |
protected java.lang.String |
toString(java.lang.Object... args)
Return a string representation of the function with its arguments.
|
public static final java.lang.Double NaN
protected int numberOfParameters
protected transient int curNumberOfParameters
public java.lang.String name
public PostfixMathCommand()
public PostfixMathCommand(int nParam)
nParam
- number of parameters for the functionpublic java.lang.String getName()
PostfixMathCommandI
getName
in interface PostfixMathCommandI
public void setName(java.lang.String name)
PostfixMathCommandI
setName
in interface PostfixMathCommandI
name
- the function namepublic int getNumberOfParameters()
getNumberOfParameters
in interface PostfixMathCommandI
public void setCurNumberOfParameters(int n)
setCurNumberOfParameters
in interface PostfixMathCommandI
n
- number of parameter for next call of functionpublic boolean checkNumberOfParameters(int n)
checkNumberOfParameters
in interface PostfixMathCommandI
n
- number of parameters function will be called with.public void run(java.util.Stack<java.lang.Object> s) throws EvaluationException
run
in interface PostfixMathCommandI
s
- arguments for functionEvaluationException
- if function cannot be evaluatedprotected java.lang.String asString(int position, java.lang.Object value) throws IllegalParameterException
position
- argument number (starting from 0) used in error reportingvalue
- the argument to convertIllegalParameterException
- if the argument cannot be cast to a Stringprotected int asInt(int position, java.lang.Object value) throws IllegalParameterException
position
- argument number (starting from 0) used in error reportingvalue
- the argument to convertIllegalParameterException
- if the argument cannot be cast to a Numberprotected int asStrictInt(int position, java.lang.Object value) throws IllegalParameterException
position
- argument number (starting from 0) used in error reportingvalue
- the argument to convertIllegalParameterException
- if the argument cannot be cast to a Number or intValue() != doubleValue()protected long asLong(int position, java.lang.Object value) throws EvaluationException
position
- argument number (starting from 0) used in error reportingvalue
- the argument to convertIllegalParameterException
- if the argument cannot be cast to a NumberEvaluationException
protected double asDouble(int position, java.lang.Object value) throws EvaluationException
position
- argument number (starting from 0) used in error reportingvalue
- the argument to convertIllegalParameterException
- if the argument cannot be cast to a NumberEvaluationException
protected boolean asBool(int pos, java.lang.Object value, boolean allowNumbers) throws EvaluationException
pos
- position in argument listvalue
- actual value of objectallowNumbers
- if true non zero numbers are true and zero numbers are falseEvaluationException
- if value cannot be converted to a boolean, strings, fractional numbersprotected java.lang.Object[] asArray(java.util.Stack<java.lang.Object> stack)
stack
- inputprotected java.lang.String toString(java.lang.Object... args)
args
- the arguments to the functionpublic java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2018 Singular Systems http://www.singularsys.com/jep