Package com.singularsys.jep.functions
Class Average
java.lang.Object
com.singularsys.jep.functions.PostfixMathCommand
com.singularsys.jep.functions.ArrayFunctionBase
com.singularsys.jep.functions.Average
- All Implemented Interfaces:
ZeroLengthBehaviourI,PostfixMathCommandI,RealUnaryFunction,Serializable
Average function class, calculates the average of all its arguments.
Since Jep 3.4 this function will flatten its arguments so avg([1,[2,3]])
will be 2.
- Since:
- 3.1.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.singularsys.jep.functions.ZeroLengthBehaviourI
ZeroLengthBehaviourI.DefaultZeroLengthBehaviourI, ZeroLengthBehaviourI.ZeroLengthErrorBehaviour, ZeroLengthBehaviourI.ZeroLengthHelper -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AddFunction used to add pairs of elementsprotected final DivideFunction used to divide sum of elements by the number of elementsFields inherited from class com.singularsys.jep.functions.PostfixMathCommand
curNumberOfParameters, description, name, NaN, numberOfParameters -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class com.singularsys.jep.functions.ArrayFunctionBase
addToArray, checkNumberOfParameters, getZeroLengthErrorBehaviour, getZeroLengthValue, run, setZeroLengthErrorBehaviour, setZeroLengthValue, throwAtLeastOneExcepMethods inherited from class com.singularsys.jep.functions.PostfixMathCommand
asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, asType, getDescription, getDescription, getDescriptionWithType, getName, getNumberOfParameters, setCurNumberOfParameters, setDescription, setName, toString, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.singularsys.jep.functions.ZeroLengthBehaviourI
getErrorMessage, getValueOrException, zeroLengthResultOrException
-
Field Details
-
add
Function used to add pairs of elements -
div
Function used to divide sum of elements by the number of elements
-
-
Constructor Details
-
Average
Constructor with specified Add and Divide objects. -
Average
public Average()
-
-
Method Details
-
calc
Called by the run method, default is to callaverage(List)but subclasses can override.- Specified by:
calcin classArrayFunctionBase- Parameters:
v- a list of objects to calculate the average of.- Returns:
- result of calculation
- Throws:
EvaluationException- if the calculation cannot be performed- Since:
- 3.4.0
-
average
Returns the average of a set of values. Depends on the Add and Divide classes to perform the calculation.- Parameters:
vals- Values to be averaged- Returns:
- the average of the values
- Throws:
EvaluationException- if the calculation cannot be performed
-
evaluate
public double evaluate(double val) Just returns its argument.- Specified by:
evaluatein interfaceRealUnaryFunction- Parameters:
val- the argument- Returns:
- the result of applying the function to the argument
-