public abstract class ArrayFunctionBase extends PostfixMathCommand
1,[2,[3, 4]]
becomes [1, 2, 3, 4]
which is passed in to the calc method as a List<Object>.Modifier and Type | Class and Description |
---|---|
static class |
ArrayFunctionBase.ZeroLengthErrorBehaviour
How to respond to a zero length array as argument
|
curNumberOfParameters, name, NaN, numberOfParameters
Constructor and Description |
---|
ArrayFunctionBase()
Default the number of parameters to any number of params (-1).
|
Modifier and Type | Method and Description |
---|---|
protected void |
addToArray(java.util.List<java.lang.Object> l,
java.lang.Object val)
Adds a value
val to the array l . |
protected abstract java.lang.Object |
calc(java.util.List<java.lang.Object> l)
Abstract method for performing the array calculation.
|
boolean |
checkNumberOfParameters(int n)
Must have one or more parameter
|
ArrayFunctionBase.ZeroLengthErrorBehaviour |
getZeroLengthErrorBehaviour() |
void |
run(java.util.Stack<java.lang.Object> stack)
Calls the calc method after concatenating all elements into list.
|
void |
setZeroLengthErrorBehaviour(ArrayFunctionBase.ZeroLengthErrorBehaviour zeroLengthErrorBehaviour)
Sets how to respond to arguments with zero length arrays.
|
protected void |
throwAtLeastOneExcep() |
asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, getName, getNumberOfParameters, setCurNumberOfParameters, setName, toString, toString
public ArrayFunctionBase()
public boolean checkNumberOfParameters(int n)
checkNumberOfParameters
in interface PostfixMathCommandI
checkNumberOfParameters
in class PostfixMathCommand
n
- number of parameters function will be called with.public void run(java.util.Stack<java.lang.Object> stack) throws EvaluationException
run
in interface PostfixMathCommandI
run
in class PostfixMathCommand
stack
- arguments for functionEvaluationException
- if function cannot be evaluatedprotected void addToArray(java.util.List<java.lang.Object> l, java.lang.Object val)
val
to the array l
. This method
flattens Vectors and nested Vectors so 1,[2,[3, 4]]
becomes
[1, 2, 3, 4]
.l
- The list to which to add a
.val
- The value to be added (can be a Vector).protected abstract java.lang.Object calc(java.util.List<java.lang.Object> l) throws EvaluationException
l
- The list to operate on. Note this is in reverse order of the arguments of the function.EvaluationException
- if the calculation cannot be performedprotected void throwAtLeastOneExcep() throws EvaluationException
EvaluationException
public ArrayFunctionBase.ZeroLengthErrorBehaviour getZeroLengthErrorBehaviour()
public void setZeroLengthErrorBehaviour(ArrayFunctionBase.ZeroLengthErrorBehaviour zeroLengthErrorBehaviour)
zeroLengthErrorBehaviour
- either EXCEPTION or NANCopyright © 2018 Singular Systems http://www.singularsys.com/jep