Package microsim.collection
Class AverageClosure<T>
java.lang.Object
microsim.collection.AverageClosure<T>
- Type Parameters:
T- A generic agent type.
- All Implemented Interfaces:
org.apache.commons.collections4.Closure<T>
public abstract class AverageClosure<T>
extends Object
implements org.apache.commons.collections4.Closure<T>
A generic implementation of
Closure, calculates some average.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final jamjam.Sum.Accumulatorprotected long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(double value) Adds a value to the total sum and increments the total number of values by1.voidadd(double @NonNull [] value) Adds together all values in the array and stores both the total sum and the total number of elements to date inaccumulatorandcount, respectively.voidadd(@NonNull DoubleStream value) Adds all values fromDoubleStreamto the total sum and increments the total number by the corresponding stream length.doubleCalculates the average accumulated value.doublegetSum()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.commons.collections4.Closure
execute
-
Field Details
-
accumulator
protected final jamjam.Sum.Accumulator accumulator -
count
protected long count
-
-
Constructor Details
-
AverageClosure
public AverageClosure()
-
-
Method Details
-
getSum
public double getSum() -
getAverage
public double getAverage()Calculates the average accumulated value.- Returns:
- the average value.
-
add
public void add(double value) Adds a value to the total sum and increments the total number of values by1.- Parameters:
value- The value to be added to the sum.
-
add
public void add(double @NonNull [] value) Adds together all values in the array and stores both the total sum and the total number of elements to date inaccumulatorandcount, respectively.- Throws:
NullPointerException- whenvalueisnull.- See Also:
-
add
Adds all values fromDoubleStreamto the total sum and increments the total number by the corresponding stream length.- Throws:
NullPointerException- whenvalueisnull.- See Also:
-