Class SynchronizedSummaryStatistics

  • All Implemented Interfaces:
    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
    See Also:
    Serialized Form
    • Constructor Detail

      • SynchronizedSummaryStatistics

        public SynchronizedSummaryStatistics()
        Construct a SynchronizedSummaryStatistics instance
      • SynchronizedSummaryStatistics

        public SynchronizedSummaryStatistics​(SynchronizedSummaryStatistics original)
        A copy constructor. Creates a deep-copy of the original.
        Parameters:
        original - the SynchronizedSummaryStatistics instance to copy
    • Method Detail

      • addValue

        public void addValue​(double value)
        Add a value to the data
        Overrides:
        addValue in class SummaryStatistics
        Parameters:
        value - the value to add
      • getSum

        public double getSum()
        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
      • getSumsq

        public double getSumsq()
        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
      • getMean

        public double getMean()
        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
      • getVariance

        public double getVariance()
        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
      • getMax

        public double getMax()
        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
      • getMin

        public double getMin()
        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
      • getGeometricMean

        public double getGeometricMean()
        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
      • toString

        public String toString()
        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
      • equals

        public boolean equals​(Object object)
        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
      • hashCode

        public int hashCode()
        Returns hash code based on values of statistics
        Overrides:
        hashCode in class SummaryStatistics
        Returns:
        hash code
      • setSumImpl

        public void setSumImpl​(StorelessUnivariateStatistic sumImpl)

        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
      • setSumsqImpl

        public void setSumsqImpl​(StorelessUnivariateStatistic sumsqImpl)

        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
      • setMinImpl

        public void setMinImpl​(StorelessUnivariateStatistic minImpl)

        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
      • setMaxImpl

        public void setMaxImpl​(StorelessUnivariateStatistic maxImpl)

        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
      • setSumLogImpl

        public void setSumLogImpl​(StorelessUnivariateStatistic sumLogImpl)

        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
      • setGeoMeanImpl

        public void setGeoMeanImpl​(StorelessUnivariateStatistic geoMeanImpl)

        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
      • setMeanImpl

        public void setMeanImpl​(StorelessUnivariateStatistic meanImpl)

        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
      • setVarianceImpl

        public void setVarianceImpl​(StorelessUnivariateStatistic varianceImpl)

        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
      • copy

        public static void copy​(SynchronizedSummaryStatistics source,
                                SynchronizedSummaryStatistics dest)
        Copies source to dest.

        Neither source nor dest can be null.

        Acquires synchronization lock on source, then dest before copying.

        Parameters:
        source - SynchronizedSummaryStatistics to copy
        dest - SynchronizedSummaryStatistics to copy to
        Throws:
        NullPointerException - if either source or dest is null