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

java.lang.Object
  extended by org.apache.commons.math.stat.descriptive.SummaryStatistics
      extended by org.apache.commons.math.stat.descriptive.SynchronizedSummaryStatistics
All Implemented Interfaces:
java.io.Serializable, StatisticalSummary

public class SynchronizedSummaryStatistics
extends SummaryStatistics

Implementation of SummaryStatistics 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: 618097 $ $Date: 2008-02-03 14:39:08 -0700 (Sun, 03 Feb 2008) $
See Also:
Serialized Form

Field Summary
private static long serialVersionUID
          Serialization UID
 
Fields inherited from class org.apache.commons.math.stat.descriptive.SummaryStatistics
geoMean, max, mean, min, n, secondMoment, sum, sumLog, sumsq, variance
 
Constructor Summary
SynchronizedSummaryStatistics()
          Construct a SynchronizedSummaryStatistics instance
 
Method Summary
 void addValue(double value)
          Add a value to the data
 void clear()
          Resets all statistics and storage
 boolean equals(java.lang.Object object)
          Returns true iff object is a SummaryStatistics instance and all statistics have the same values as this.
 StorelessUnivariateStatistic getGeoMeanImpl()
          Returns the currently configured geometric mean implementation
 double getGeometricMean()
          Returns the geometric mean of the values that have been added.
 double getMax()
          Returns the maximum of the values that have been added.
 StorelessUnivariateStatistic getMaxImpl()
          Returns the currently configured maximum implementation
 double getMean()
          Returns the mean of the values that have been added.
 StorelessUnivariateStatistic getMeanImpl()
          Returns the currently configured mean implementation
 double getMin()
          Returns the minimum of the values that have been added.
 StorelessUnivariateStatistic getMinImpl()
          Returns the currently configured minimum implementation
 long getN()
          Returns the number of available values
 double getStandardDeviation()
          Returns the standard deviation of the values that have been added.
 double getSum()
          Returns the sum of the values that have been added
 StorelessUnivariateStatistic getSumImpl()
          Returns the currently configured Sum implementation
 StorelessUnivariateStatistic getSumLogImpl()
          Returns the currently configured sum of logs implementation
 StatisticalSummary getSummary()
          Return a StatisticalSummaryValues instance reporting current statistics.
 double getSumsq()
          Returns the sum of the squares of the values that have been added.
 StorelessUnivariateStatistic getSumsqImpl()
          Returns the currently configured sum of squares implementation
 double getVariance()
          Returns the variance of the values that have been added.
 StorelessUnivariateStatistic getVarianceImpl()
          Returns the currently configured variance implementation
 int hashCode()
          Returns hash code based on values of statistics
 void setGeoMeanImpl(StorelessUnivariateStatistic geoMeanImpl)
          Sets the implementation for the geometric mean.
 void setMaxImpl(StorelessUnivariateStatistic maxImpl)
          Sets the implementation for the maximum.
 void setMeanImpl(StorelessUnivariateStatistic meanImpl)
          Sets the implementation for the mean.
 void setMinImpl(StorelessUnivariateStatistic minImpl)
          Sets the implementation for the minimum.
 void setSumImpl(StorelessUnivariateStatistic sumImpl)
          Sets the implementation for the Sum.
 void setSumLogImpl(StorelessUnivariateStatistic sumLogImpl)
          Sets the implementation for the sum of logs.
 void setSumsqImpl(StorelessUnivariateStatistic sumsqImpl)
          Sets the implementation for the sum of squares.
 void setVarianceImpl(StorelessUnivariateStatistic varianceImpl)
          Sets the implementation for the variance.
 java.lang.String toString()
          Generates a text report displaying summary statistics from values that have been added.
 
Methods inherited from class org.apache.commons.math.stat.descriptive.SummaryStatistics
getSumOfLogs, newInstance, newInstance
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Serialization UID

See Also:
Constant Field Values
Constructor Detail

SynchronizedSummaryStatistics

public SynchronizedSummaryStatistics()
Construct a SynchronizedSummaryStatistics instance

Method Detail

getSummary

public StatisticalSummary getSummary()
Description copied from class: SummaryStatistics
Return a StatisticalSummaryValues instance reporting current statistics.

Overrides:
getSummary in class SummaryStatistics
Returns:
Current values of statistics
See Also:
SummaryStatistics.getSummary()

addValue

public void addValue(double value)
Description copied from class: SummaryStatistics
Add a value to the data

Overrides:
addValue in class SummaryStatistics
Parameters:
value - the value to add
See Also:
SummaryStatistics.addValue(double)

getN

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

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

getSum

public double getSum()
Description copied from class: SummaryStatistics
Returns the sum of the values that have been added

Specified by:
getSum in interface StatisticalSummary
Overrides:
getSum in class SummaryStatistics
Returns:
The sum or Double.NaN if no values have been added
See Also:
SummaryStatistics.getSum()

getSumsq

public double getSumsq()
Description copied from class: SummaryStatistics
Returns the sum of the squares of the values that have been added.

Double.NaN is returned if no values have been added.

Overrides:
getSumsq in class SummaryStatistics
Returns:
The sum of squares
See Also:
SummaryStatistics.getSumsq()

getMean

public double getMean()
Description copied from class: SummaryStatistics
Returns the mean of the values that have been added.

Double.NaN is returned if no values have been added.

Specified by:
getMean in interface StatisticalSummary
Overrides:
getMean in class SummaryStatistics
Returns:
the mean
See Also:
SummaryStatistics.getMean()

getStandardDeviation

public double getStandardDeviation()
Description copied from class: SummaryStatistics
Returns the standard deviation of the values that have been added.

Double.NaN is returned if no values have been added.

Specified by:
getStandardDeviation in interface StatisticalSummary
Overrides:
getStandardDeviation in class SummaryStatistics
Returns:
the standard deviation
See Also:
SummaryStatistics.getStandardDeviation()

getVariance

public double getVariance()
Description copied from class: SummaryStatistics
Returns the variance of the values that have been added.

Double.NaN is returned if no values have been added.

Specified by:
getVariance in interface StatisticalSummary
Overrides:
getVariance in class SummaryStatistics
Returns:
the variance
See Also:
SummaryStatistics.getVariance()

getMax

public double getMax()
Description copied from class: SummaryStatistics
Returns the maximum of the values that have been added.

Double.NaN is returned if no values have been added.

Specified by:
getMax in interface StatisticalSummary
Overrides:
getMax in class SummaryStatistics
Returns:
the maximum
See Also:
SummaryStatistics.getMax()

getMin

public double getMin()
Description copied from class: SummaryStatistics
Returns the minimum of the values that have been added.

Double.NaN is returned if no values have been added.

Specified by:
getMin in interface StatisticalSummary
Overrides:
getMin in class SummaryStatistics
Returns:
the minimum
See Also:
SummaryStatistics.getMin()

getGeometricMean

public double getGeometricMean()
Description copied from class: SummaryStatistics
Returns the geometric mean of the values that have been added.

Double.NaN is returned if no values have been added.

Overrides:
getGeometricMean in class SummaryStatistics
Returns:
the geometric mean
See Also:
SummaryStatistics.getGeometricMean()

toString

public java.lang.String toString()
Description copied from class: SummaryStatistics
Generates a text report displaying summary statistics from values that have been added.

Overrides:
toString in class SummaryStatistics
Returns:
String with line feeds displaying statistics
See Also:
SummaryStatistics.toString()

clear

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

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

equals

public boolean equals(java.lang.Object object)
Description copied from class: SummaryStatistics
Returns true iff object is a SummaryStatistics instance and all statistics have the same values as this.

Overrides:
equals in class SummaryStatistics
Parameters:
object - the object to test equality against.
Returns:
true if object equals this
See Also:
SummaryStatistics.equals(Object)

hashCode

public int hashCode()
Description copied from class: SummaryStatistics
Returns hash code based on values of statistics

Overrides:
hashCode in class SummaryStatistics
Returns:
hash code
See Also:
SummaryStatistics.hashCode()

getSumImpl

public StorelessUnivariateStatistic getSumImpl()
Description copied from class: SummaryStatistics
Returns the currently configured Sum implementation

Overrides:
getSumImpl in class SummaryStatistics
Returns:
the StorelessUnivariateStatistic implementing the sum
See Also:
SummaryStatistics.getSumImpl()

setSumImpl

public void setSumImpl(StorelessUnivariateStatistic sumImpl)
Description copied from class: SummaryStatistics

Sets the implementation for the Sum.

This method must be activated before any data has been added - i.e., before addValue has been used to add data; otherwise an IllegalStateException will be thrown.

Overrides:
setSumImpl in class SummaryStatistics
Parameters:
sumImpl - the StorelessUnivariateStatistic instance to use for computing the Sum
See Also:
SummaryStatistics.setSumImpl(StorelessUnivariateStatistic)

getSumsqImpl

public StorelessUnivariateStatistic getSumsqImpl()
Description copied from class: SummaryStatistics
Returns the currently configured sum of squares implementation

Overrides:
getSumsqImpl in class SummaryStatistics
Returns:
the StorelessUnivariateStatistic implementing the sum of squares
See Also:
SummaryStatistics.getSumsqImpl()

setSumsqImpl

public void setSumsqImpl(StorelessUnivariateStatistic sumsqImpl)
Description copied from class: SummaryStatistics

Sets the implementation for the sum of squares.

This method must be activated before any data has been added - i.e., before addValue has been used to add data; otherwise an IllegalStateException will be thrown.

Overrides:
setSumsqImpl in class SummaryStatistics
Parameters:
sumsqImpl - the StorelessUnivariateStatistic instance to use for computing the sum of squares
See Also:
SummaryStatistics.setSumsqImpl(StorelessUnivariateStatistic)

getMinImpl

public StorelessUnivariateStatistic getMinImpl()
Description copied from class: SummaryStatistics
Returns the currently configured minimum implementation

Overrides:
getMinImpl in class SummaryStatistics
Returns:
the StorelessUnivariateStatistic implementing the minimum
See Also:
SummaryStatistics.getMinImpl()

setMinImpl

public void setMinImpl(StorelessUnivariateStatistic minImpl)
Description copied from class: SummaryStatistics

Sets the implementation for the minimum.

This method must be activated before any data has been added - i.e., before addValue has been used to add data; otherwise an IllegalStateException will be thrown.

Overrides:
setMinImpl in class SummaryStatistics
Parameters:
minImpl - the StorelessUnivariateStatistic instance to use for computing the minimum
See Also:
SummaryStatistics.setMinImpl(StorelessUnivariateStatistic)

getMaxImpl

public StorelessUnivariateStatistic getMaxImpl()
Description copied from class: SummaryStatistics
Returns the currently configured maximum implementation

Overrides:
getMaxImpl in class SummaryStatistics
Returns:
the StorelessUnivariateStatistic implementing the maximum
See Also:
SummaryStatistics.getMaxImpl()

setMaxImpl

public void setMaxImpl(StorelessUnivariateStatistic maxImpl)
Description copied from class: SummaryStatistics

Sets the implementation for the maximum.

This method must be activated before any data has been added - i.e., before addValue has been used to add data; otherwise an IllegalStateException will be thrown.

Overrides:
setMaxImpl in class SummaryStatistics
Parameters:
maxImpl - the StorelessUnivariateStatistic instance to use for computing the maximum
See Also:
SummaryStatistics.setMaxImpl(StorelessUnivariateStatistic)

getSumLogImpl

public StorelessUnivariateStatistic getSumLogImpl()
Description copied from class: SummaryStatistics
Returns the currently configured sum of logs implementation

Overrides:
getSumLogImpl in class SummaryStatistics
Returns:
the StorelessUnivariateStatistic implementing the log sum
See Also:
SummaryStatistics.getSumLogImpl()

setSumLogImpl

public void setSumLogImpl(StorelessUnivariateStatistic sumLogImpl)
Description copied from class: SummaryStatistics

Sets the implementation for the sum of logs.

This method must be activated before any data has been added - i.e., before addValue has been used to add data; otherwise an IllegalStateException will be thrown.

Overrides:
setSumLogImpl in class SummaryStatistics
Parameters:
sumLogImpl - the StorelessUnivariateStatistic instance to use for computing the log sum
See Also:
SummaryStatistics.setSumLogImpl(StorelessUnivariateStatistic)

getGeoMeanImpl

public StorelessUnivariateStatistic getGeoMeanImpl()
Description copied from class: SummaryStatistics
Returns the currently configured geometric mean implementation

Overrides:
getGeoMeanImpl in class SummaryStatistics
Returns:
the StorelessUnivariateStatistic implementing the geometric mean
See Also:
SummaryStatistics.getGeoMeanImpl()

setGeoMeanImpl

public void setGeoMeanImpl(StorelessUnivariateStatistic geoMeanImpl)
Description copied from class: SummaryStatistics

Sets the implementation for the geometric mean.

This method must be activated before any data has been added - i.e., before addValue has been used to add data; otherwise an IllegalStateException will be thrown.

Overrides:
setGeoMeanImpl in class SummaryStatistics
Parameters:
geoMeanImpl - the StorelessUnivariateStatistic instance to use for computing the geometric mean
See Also:
SummaryStatistics.setGeoMeanImpl(StorelessUnivariateStatistic)

getMeanImpl

public StorelessUnivariateStatistic getMeanImpl()
Description copied from class: SummaryStatistics
Returns the currently configured mean implementation

Overrides:
getMeanImpl in class SummaryStatistics
Returns:
the StorelessUnivariateStatistic implementing the mean
See Also:
SummaryStatistics.getMeanImpl()

setMeanImpl

public void setMeanImpl(StorelessUnivariateStatistic meanImpl)
Description copied from class: SummaryStatistics

Sets the implementation for the mean.

This method must be activated before any data has been added - i.e., before addValue has been used to add data; otherwise an IllegalStateException will be thrown.

Overrides:
setMeanImpl in class SummaryStatistics
Parameters:
meanImpl - the StorelessUnivariateStatistic instance to use for computing the mean
See Also:
SummaryStatistics.setMeanImpl(StorelessUnivariateStatistic)

getVarianceImpl

public StorelessUnivariateStatistic getVarianceImpl()
Description copied from class: SummaryStatistics
Returns the currently configured variance implementation

Overrides:
getVarianceImpl in class SummaryStatistics
Returns:
the StorelessUnivariateStatistic implementing the variance
See Also:
SummaryStatistics.getVarianceImpl()

setVarianceImpl

public void setVarianceImpl(StorelessUnivariateStatistic varianceImpl)
Description copied from class: SummaryStatistics

Sets the implementation for the variance.

This method must be activated before any data has been added - i.e., before addValue has been used to add data; otherwise an IllegalStateException will be thrown.

Overrides:
setVarianceImpl in class SummaryStatistics
Parameters:
varianceImpl - the StorelessUnivariateStatistic instance to use for computing the variance
See Also:
SummaryStatistics.setVarianceImpl(StorelessUnivariateStatistic)