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
Modifier and TypeFieldDescriptionprotected final jamjam.Sum.Accumulator
protected long
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(double value) Adds a value to the total sum and increments the total number of values by1
.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 inaccumulator
andcount
, respectively.void
add
(@NonNull DoubleStream value) Adds all values fromDoubleStream
to the total sum and increments the total number by the corresponding stream length.double
Calculates the average accumulated value.double
getSum()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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 inaccumulator
andcount
, respectively.- Throws:
NullPointerException
- whenvalue
isnull
.- See Also:
-
add
Adds all values fromDoubleStream
to the total sum and increments the total number by the corresponding stream length.- Throws:
NullPointerException
- whenvalue
isnull
.- See Also:
-