Package com.singularsys.jep.functions
Class ArrayFunctionBase
java.lang.Object
com.singularsys.jep.functions.PostfixMathCommand
com.singularsys.jep.functions.ArrayFunctionBase
- All Implemented Interfaces:
PostfixMathCommandI
,Serializable
Base class for functions that operate on arrays such as Average, MinMax,
and VSum. The shared functionality such as array flattening is implemented
here. In the run() method, before calling calc(), Vectors and nested Vectors
are flattened so
1,[2,[3, 4]]
becomes [1, 2, 3, 4]
which is passed in to the calc method as a List<Object>.- Since:
- 3.4.0
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
How to respond to a zero length array as argument -
Field Summary
Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand
curNumberOfParameters, name, NaN, numberOfParameters
-
Constructor Summary
ConstructorDescriptionDefault the number of parameters to any number of params (-1). -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addToArray
(List<Object> l, Object val) Adds a valueval
to the arrayl
.protected abstract Object
Abstract method for performing the array calculation.boolean
checkNumberOfParameters
(int n) Must have one or more parametervoid
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
Methods inherited from class com.singularsys.jep.functions.PostfixMathCommand
asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, getName, getNumberOfParameters, setCurNumberOfParameters, setName, toString, toString
-
Constructor Details
-
ArrayFunctionBase
public ArrayFunctionBase()Default the number of parameters to any number of params (-1).
-
-
Method Details
-
checkNumberOfParameters
public boolean checkNumberOfParameters(int n) Must have one or more parameter- Specified by:
checkNumberOfParameters
in interfacePostfixMathCommandI
- Overrides:
checkNumberOfParameters
in classPostfixMathCommand
- Parameters:
n
- number of parameters function will be called with.- Returns:
- false if an illegal number of parameters is supplied, true otherwise.
-
run
Calls the calc method after concatenating all elements into list.- Specified by:
run
in interfacePostfixMathCommandI
- Overrides:
run
in classPostfixMathCommand
- Parameters:
stack
- arguments for function- Throws:
EvaluationException
- if function cannot be evaluated
-
addToArray
Adds a valueval
to the arrayl
. This method flattens Vectors and nested Vectors so1,[2,[3, 4]]
becomes[1, 2, 3, 4]
.- Parameters:
l
- The list to which to adda
.val
- The value to be added (can be a Vector).
-
calc
Abstract method for performing the array calculation.- Parameters:
l
- The list to operate on. Note this is in reverse order of the arguments of the function.- Returns:
- The result of the calculation.
- Throws:
EvaluationException
- if the calculation cannot be performed
-
throwAtLeastOneExcep
- Throws:
EvaluationException
-
getZeroLengthErrorBehaviour
-
setZeroLengthErrorBehaviour
public void setZeroLengthErrorBehaviour(ArrayFunctionBase.ZeroLengthErrorBehaviour zeroLengthErrorBehaviour) Sets how to respond to arguments with zero length arrays. Either an Exception is thrown or NaN is returned.- Parameters:
zeroLengthErrorBehaviour
- either EXCEPTION or NAN
-