com.singularsys.jep.functions
Class ArrayFunctionBase

java.lang.Object
  extended by com.singularsys.jep.functions.PostfixMathCommand
      extended by com.singularsys.jep.functions.ArrayFunctionBase
All Implemented Interfaces:
PostfixMathCommandI, java.io.Serializable
Direct Known Subclasses:
Average, MinMax, VSum

public abstract class ArrayFunctionBase
extends PostfixMathCommand

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:
Serialized Form

Nested Class Summary
static class ArrayFunctionBase.ZeroLengthErrorBehaviour
          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
ArrayFunctionBase()
          Default the number of parameters to any number of params (-1).
 
Method Summary
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()
           
 
Methods inherited from class com.singularsys.jep.functions.PostfixMathCommand
asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, checkStack, getName, getNumberOfParameters, setCurNumberOfParameters, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayFunctionBase

public ArrayFunctionBase()
Default the number of parameters to any number of params (-1).

Method Detail

checkNumberOfParameters

public boolean checkNumberOfParameters(int n)
Must have one or more parameter

Specified by:
checkNumberOfParameters in interface PostfixMathCommandI
Overrides:
checkNumberOfParameters in class PostfixMathCommand
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<java.lang.Object> stack)
         throws EvaluationException
Calls the calc method after concatenating all elements into list.

Throws:
EvaluationException

calc

protected abstract java.lang.Object calc(java.util.List<java.lang.Object> l)
                                  throws EvaluationException
Abstract method for performing the array calculation.

Parameters:
l - The list to operate on.
Returns:
The result of the calculation.
Throws:
EvaluationException

throwAtLeastOneExcep

protected void throwAtLeastOneExcep()
                             throws EvaluationException
Throws:
EvaluationException

getZeroLengthErrorBehaviour

public ArrayFunctionBase.ZeroLengthErrorBehaviour 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 -


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