org.apache.commons.math.stat.descriptive
Class SynchronizedDescriptiveStatistics

java.lang.Object
  extended by org.apache.commons.math.stat.descriptive.DescriptiveStatistics
      extended by org.apache.commons.math.stat.descriptive.SynchronizedDescriptiveStatistics
All Implemented Interfaces:
java.io.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:
$Revision: 608819 $ $Date: 2008-01-04 05:46:21 -0700 (Fri, 04 Jan 2008) $
See Also:
Serialized Form

Field Summary
private static long serialVersionUID
          Serialization UID
 
Fields inherited from class org.apache.commons.math.stat.descriptive.DescriptiveStatistics
eDA, INFINITE_WINDOW, windowSize
 
Constructor Summary
SynchronizedDescriptiveStatistics()
          Construct an instance with infinite window
SynchronizedDescriptiveStatistics(int window)
          Construct an instance with finite window
 
Method Summary
 void addValue(double v)
          Adds the value to the dataset.
 double apply(UnivariateStatistic stat)
          Apply the given statistic to this univariate collection.
 void clear()
          Resets all statistics and storage
 double getElement(int index)
          Returns the element at the specified index
 long getN()
          Returns the number of available values
 double getStandardDeviation()
          Returns the standard deviation of the available values.
 double[] getValues()
          Returns the current set of values in an array of double primitives.
 int getWindowSize()
          Access the window size.
 void setWindowSize(int windowSize)
          WindowSize controls the number of values which contribute to the reported statistics.
 java.lang.String toString()
          Generates a text report displaying univariate statistics from values that have been added.
 
Methods inherited from class org.apache.commons.math.stat.descriptive.DescriptiveStatistics
getGeometricMean, getGeometricMeanImpl, getKurtosis, getKurtosisImpl, getMax, getMaxImpl, getMean, getMeanImpl, getMin, getMinImpl, getPercentile, getPercentileImpl, getSkewness, getSkewnessImpl, getSortedValues, getSum, getSumImpl, getSumsq, getSumsqImpl, getVariance, getVarianceImpl, newInstance, newInstance, setGeometricMeanImpl, setKurtosisImpl, setMaxImpl, setMeanImpl, setMinImpl, setPercentileImpl, setSkewnessImpl, setSumImpl, setSumsqImpl, setVarianceImpl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Serialization UID

See Also:
Constant Field Values
Constructor Detail

SynchronizedDescriptiveStatistics

public SynchronizedDescriptiveStatistics()
Construct an instance with infinite window


SynchronizedDescriptiveStatistics

public SynchronizedDescriptiveStatistics(int window)
Construct an instance with finite window

Parameters:
window - the finite window size.
Method Detail

addValue

public void addValue(double v)
Description copied from class: DescriptiveStatistics
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:
addValue in class DescriptiveStatistics
Parameters:
v - the value to be added
See Also:
DescriptiveStatistics.addValue(double)

apply

public double apply(UnivariateStatistic stat)
Apply the given statistic to this univariate collection.

Overrides:
apply in class DescriptiveStatistics
Parameters:
stat - the statistic to apply
Returns:
the computed value of the statistic.

clear

public void clear()
Description copied from class: DescriptiveStatistics
Resets all statistics and storage

Overrides:
clear in class DescriptiveStatistics
See Also:
DescriptiveStatistics.clear()

getElement

public double getElement(int index)
Description copied from class: DescriptiveStatistics
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
See Also:
DescriptiveStatistics.getElement(int)

getN

public long getN()
Description copied from class: DescriptiveStatistics
Returns the number of available values

Specified by:
getN in interface StatisticalSummary
Overrides:
getN in class DescriptiveStatistics
Returns:
The number of available values
See Also:
DescriptiveStatistics.getN()

getStandardDeviation

public double getStandardDeviation()
Returns the standard deviation of the available values.

Specified by:
getStandardDeviation in interface StatisticalSummary
Overrides:
getStandardDeviation in class DescriptiveStatistics
Returns:
The standard deviation, Double.NaN if no values have been added or 0.0 for a single value set.

getValues

public double[] getValues()
Description copied from class: DescriptiveStatistics
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
See Also:
DescriptiveStatistics.getValues()

getWindowSize

public int getWindowSize()
Access the window size.

Overrides:
getWindowSize in class DescriptiveStatistics
Returns:
the current window size.

setWindowSize

public void setWindowSize(int windowSize)
Description copied from class: DescriptiveStatistics
WindowSize controls the number of values which 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

Overrides:
setWindowSize in class DescriptiveStatistics
Parameters:
windowSize - sets the size of the window.
See Also:
DescriptiveStatistics.setWindowSize(int)

toString

public java.lang.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