com.singularsys.jep.functions
Class Average

java.lang.Object
  extended by com.singularsys.jep.functions.PostfixMathCommand
      extended by com.singularsys.jep.functions.ArrayFunctionBase
          extended by com.singularsys.jep.functions.Average
All Implemented Interfaces:
PostfixMathCommandI, RealUnaryFunction, java.io.Serializable

public class Average
extends ArrayFunctionBase
implements RealUnaryFunction

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

Nested Class Summary
 
Nested classes/interfaces inherited from class com.singularsys.jep.functions.ArrayFunctionBase
ArrayFunctionBase.ZeroLengthErrorBehaviour
 
Field Summary
protected static Add add
          Function used to add pairs of elements
protected static Divide div
          Function used to divide sum of elements by the number of elements
 
Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand
curNumberOfParameters, name, NaN, numberOfParameters
 
Constructor Summary
Average()
           
 
Method Summary
 java.lang.Object average(java.util.List<java.lang.Object> vals)
          Returns the average of a set of values.
protected  java.lang.Object calc(java.util.List<java.lang.Object> v)
          Called by the run method, default is to call average(List) but subclasses can override.
 double evaluate(double val)
          Just returns its argument.
 
Methods inherited from class com.singularsys.jep.functions.ArrayFunctionBase
checkNumberOfParameters, getZeroLengthErrorBehaviour, run, setZeroLengthErrorBehaviour, 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
 

Field Detail

add

protected static Add add
Function used to add pairs of elements


div

protected static Divide div
Function used to divide sum of elements by the number of elements

Constructor Detail

Average

public Average()
Method Detail

calc

protected java.lang.Object calc(java.util.List<java.lang.Object> v)
                         throws EvaluationException
Called by the run method, default is to call average(List) but subclasses can override.

Specified by:
calc in class ArrayFunctionBase
Parameters:
v - a list of objects to calculate the average of.
Returns:
result of calculation
Throws:
EvaluationException
Since:
3.4.0

average

public java.lang.Object average(java.util.List<java.lang.Object> vals)
                         throws EvaluationException
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 vals
Throws:
EvaluationException

evaluate

public double evaluate(double val)
Just returns its argument.

Specified by:
evaluate in interface RealUnaryFunction


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