Class SynchronizedDescriptiveStatistics

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

      • SynchronizedDescriptiveStatistics

        public SynchronizedDescriptiveStatistics()
        Construct an instance with infinite window
      • SynchronizedDescriptiveStatistics

        public SynchronizedDescriptiveStatistics​(int window)
        Construct an instance with finite window
        window - the finite window size.
      • SynchronizedDescriptiveStatistics

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

      • addValue

        public void addValue​(double v)
        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.
        addValue in class DescriptiveStatistics
        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.
        apply in class DescriptiveStatistics
        stat - the statistic to apply
        the computed value of the statistic.
      • getElement

        public double getElement​(int index)
        Returns the element at the specified index
        getElement in class DescriptiveStatistics
        index - The Index of the element
        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.
        getValues in class DescriptiveStatistics
        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.
        getWindowSize in class DescriptiveStatistics
        The current window size or -1 if its Infinite.
      • setWindowSize

        public void setWindowSize​(int windowSize)
        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
        setWindowSize in class DescriptiveStatistics
        windowSize - sets the size of the window.
      • 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.
        toString in class DescriptiveStatistics
        String with line feeds displaying statistics
      • copy

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

        Neither source nor dest can be null.

        Acquires synchronization lock on source, then dest before copying.

        source - SynchronizedDescriptiveStatistics to copy
        dest - SynchronizedDescriptiveStatistics to copy to
        java.lang.NullPointerException - if either source or dest is null