org.apache.commons.math3.stat.descriptive

## Class SynchronizedDescriptiveStatistics

• All Implemented Interfaces:
Serializable, StatisticalSummary

public class SynchronizedDescriptiveStatistics
extends DescriptiveStatistics
Implementation of DescriptiveStatistics that is safe to use in a multithreaded environment. Multiple threads can safely operate on a single instance without causing runtime exceptions due to race conditions. In effect, this implementation makes modification and access methods atomic operations for a single instance. That is to say, as one thread is computing a statistic from the instance, no other thread can modify the instance nor compute another statistic.
Since:
1.2
Version:
$Id: SynchronizedDescriptiveStatistics.java 1416643 2012-12-03 19:37:14Z tn$
Serialized Form
• ### Method Detail

Adds the value to the dataset. If the dataset is at the maximum size (i.e., the number of stored elements equals the currently configured windowSize), the first (oldest) element in the dataset is discarded to make room for the new value.
Overrides:
Parameters:
v - the value to be added
• #### apply

public double apply(UnivariateStatistic stat)
Apply the given statistic to the data associated with this set of statistics.
Overrides:
apply in class DescriptiveStatistics
Parameters:
stat - the statistic to apply
Returns:
the computed value of the statistic.
• #### getElement

public double getElement(int index)
Returns the element at the specified index
Overrides:
getElement in class DescriptiveStatistics
Parameters:
index - The Index of the element
Returns:
return the element at the specified index
• #### getValues

public double[] getValues()
Returns the current set of values in an array of double primitives. The order of addition is preserved. The returned array is a fresh copy of the underlying data -- i.e., it is not a reference to the stored data.
Overrides:
getValues in class DescriptiveStatistics
Returns:
returns the current set of numbers in the order in which they were added to this set
• #### getWindowSize

public int getWindowSize()
Returns the maximum number of values that can be stored in the dataset, or INFINITE_WINDOW (-1) if there is no limit.
Overrides:
getWindowSize in class DescriptiveStatistics
Returns:
The current window size or -1 if its Infinite.
• #### setWindowSize

public void setWindowSize(int windowSize)
throws MathIllegalArgumentException
WindowSize controls the number of values that contribute to the reported statistics. For example, if windowSize is set to 3 and the values {1,2,3,4,5} have been added in that order then the available values are {3,4,5} and all reported statistics will be based on these values. If windowSize is decreased as a result of this call and there are more than the new value of elements in the current dataset, values from the front of the array are discarded to reduce the dataset to windowSize elements.
Overrides:
setWindowSize in class DescriptiveStatistics
Parameters:
windowSize - sets the size of the window.
Throws:
MathIllegalArgumentException - if window size is less than 1 but not equal to DescriptiveStatistics.INFINITE_WINDOW
• #### toString

public String toString()
Generates a text report displaying univariate statistics from values that have been added. Each statistic is displayed on a separate line.
Overrides:
toString in class DescriptiveStatistics
Returns:
String with line feeds displaying statistics