1dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond/*
2dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Licensed to the Apache Software Foundation (ASF) under one or more
3dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * contributor license agreements.  See the NOTICE file distributed with
4dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * this work for additional information regarding copyright ownership.
5dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The ASF licenses this file to You under the Apache License, Version 2.0
6dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * (the "License"); you may not use this file except in compliance with
7dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * the License.  You may obtain a copy of the License at
8dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *
9dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *      http://www.apache.org/licenses/LICENSE-2.0
10dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *
11dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Unless required by applicable law or agreed to in writing, software
12dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * distributed under the License is distributed on an "AS IS" BASIS,
13dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * See the License for the specific language governing permissions and
15dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * limitations under the License.
16dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */
17dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondpackage org.apache.commons.math.stat.descriptive;
18dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
19dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport java.io.Serializable;
20dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport java.lang.reflect.InvocationTargetException;
21dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport java.util.Arrays;
22dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
23dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.MathRuntimeException;
24dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.exception.util.LocalizedFormats;
25dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.stat.descriptive.moment.GeometricMean;
26dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.stat.descriptive.moment.Kurtosis;
27dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.stat.descriptive.moment.Mean;
28dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.stat.descriptive.moment.Skewness;
29dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.stat.descriptive.moment.Variance;
30dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.stat.descriptive.rank.Max;
31dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.stat.descriptive.rank.Min;
32dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.stat.descriptive.rank.Percentile;
33dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.stat.descriptive.summary.Sum;
34dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.stat.descriptive.summary.SumOfSquares;
35dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.util.ResizableDoubleArray;
36dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.util.FastMath;
37dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
38dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
39dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond/**
40dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Maintains a dataset of values of a single variable and computes descriptive
41dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * statistics based on stored data. The {@link #getWindowSize() windowSize}
42dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * property sets a limit on the number of values that can be stored in the
43dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * dataset.  The default value, INFINITE_WINDOW, puts no limit on the size of
44dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * the dataset.  This value should be used with caution, as the backing store
45dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * will grow without bound in this case.  For very large datasets,
46dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * {@link SummaryStatistics}, which does not store the dataset, should be used
47dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * instead of this class. If <code>windowSize</code> is not INFINITE_WINDOW and
48dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * more values are added than can be stored in the dataset, new values are
49dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * added in a "rolling" manner, with new values replacing the "oldest" values
50dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * in the dataset.
51dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *
52dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p>Note: this class is not threadsafe.  Use
53dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * {@link SynchronizedDescriptiveStatistics} if concurrent access from multiple
54dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * threads is required.</p>
55dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *
56dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @version $Revision: 1054186 $ $Date: 2011-01-01 03:28:46 +0100 (sam. 01 janv. 2011) $
57dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */
58dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondpublic class DescriptiveStatistics implements StatisticalSummary, Serializable {
59dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
60dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
61dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Represents an infinite window size.  When the {@link #getWindowSize()}
62dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * returns this value, there is no limit to the number of data values
63dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * that can be stored in the dataset.
64dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
65dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public static final int INFINITE_WINDOW = -1;
66dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
67dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Serialization UID */
68dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private static final long serialVersionUID = 4133067267405273064L;
69dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
70dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Name of the setQuantile method. */
71dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private static final String SET_QUANTILE_METHOD_NAME = "setQuantile";
72dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
73dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** hold the window size **/
74dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    protected int windowSize = INFINITE_WINDOW;
75dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
76dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
77dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *  Stored data values
78dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
79dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    protected ResizableDoubleArray eDA = new ResizableDoubleArray();
80dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
81dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Mean statistic implementation - can be reset by setter. */
82dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private UnivariateStatistic meanImpl = new Mean();
83dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
84dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Geometric mean statistic implementation - can be reset by setter. */
85dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private UnivariateStatistic geometricMeanImpl = new GeometricMean();
86dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
87dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Kurtosis statistic implementation - can be reset by setter. */
88dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private UnivariateStatistic kurtosisImpl = new Kurtosis();
89dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
90dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Maximum statistic implementation - can be reset by setter. */
91dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private UnivariateStatistic maxImpl = new Max();
92dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
93dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Minimum statistic implementation - can be reset by setter. */
94dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private UnivariateStatistic minImpl = new Min();
95dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
96dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Percentile statistic implementation - can be reset by setter. */
97dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private UnivariateStatistic percentileImpl = new Percentile();
98dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
99dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Skewness statistic implementation - can be reset by setter. */
100dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private UnivariateStatistic skewnessImpl = new Skewness();
101dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
102dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Variance statistic implementation - can be reset by setter. */
103dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private UnivariateStatistic varianceImpl = new Variance();
104dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
105dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Sum of squares statistic implementation - can be reset by setter. */
106dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private UnivariateStatistic sumsqImpl = new SumOfSquares();
107dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
108dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Sum statistic implementation - can be reset by setter. */
109dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private UnivariateStatistic sumImpl = new Sum();
110dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
111dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
112dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Construct a DescriptiveStatistics instance with an infinite window
113dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
114dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public DescriptiveStatistics() {
115dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
116dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
117dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
118dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Construct a DescriptiveStatistics instance with the specified window
119dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
120dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param window the window size.
121dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
122dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public DescriptiveStatistics(int window) {
123dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        setWindowSize(window);
124dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
125dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
126dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
127dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Construct a DescriptiveStatistics instance with an infinite window
128dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * and the initial data values in double[] initialDoubleArray.
129dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * If initialDoubleArray is null, then this constructor corresponds to
130dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * DescriptiveStatistics()
131dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
132dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param initialDoubleArray the initial double[].
133dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
134dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public DescriptiveStatistics(double[] initialDoubleArray) {
135dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (initialDoubleArray != null) {
136dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            eDA = new ResizableDoubleArray(initialDoubleArray);
137dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
138dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
139dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
140dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
141dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Copy constructor.  Construct a new DescriptiveStatistics instance that
142dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * is a copy of original.
143dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
144dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param original DescriptiveStatistics instance to copy
145dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
146dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public DescriptiveStatistics(DescriptiveStatistics original) {
147dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        copy(original, this);
148dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
149dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
150dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
151dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Adds the value to the dataset. If the dataset is at the maximum size
152dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * (i.e., the number of stored elements equals the currently configured
153dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * windowSize), the first (oldest) element in the dataset is discarded
154dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * to make room for the new value.
155dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
156dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param v the value to be added
157dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
158dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public void addValue(double v) {
159dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (windowSize != INFINITE_WINDOW) {
160dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            if (getN() == windowSize) {
161dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                eDA.addElementRolling(v);
162dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            } else if (getN() < windowSize) {
163dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                eDA.addElement(v);
164dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            }
165dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        } else {
166dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            eDA.addElement(v);
167dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
168dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
169dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
170dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
171dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Removes the most recent value from the dataset.
172dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
173dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public void removeMostRecentValue() {
174dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        eDA.discardMostRecentElements(1);
175dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
176dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
177dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
178dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Replaces the most recently stored value with the given value.
179dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * There must be at least one element stored to call this method.
180dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
181dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param v the value to replace the most recent stored value
182dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return replaced value
183dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
184dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double replaceMostRecentValue(double v) {
185dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return eDA.substituteMostRecentElement(v);
186dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
187dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
188dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
189dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the <a href="http://www.xycoon.com/arithmetic_mean.htm">
190dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * arithmetic mean </a> of the available values
191dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return The mean or Double.NaN if no values have been added.
192dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
193dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double getMean() {
194dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return apply(meanImpl);
195dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
196dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
197dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
198dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the <a href="http://www.xycoon.com/geometric_mean.htm">
199dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * geometric mean </a> of the available values
200dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return The geometricMean, Double.NaN if no values have been added,
201dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * or if the product of the available values is less than or equal to 0.
202dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
203dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double getGeometricMean() {
204dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return apply(geometricMeanImpl);
205dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
206dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
207dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
208dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the variance of the available values.
209dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return The variance, Double.NaN if no values have been added
210dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * or 0.0 for a single value set.
211dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
212dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double getVariance() {
213dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return apply(varianceImpl);
214dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
215dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
216dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
217dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the standard deviation of the available values.
218dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return The standard deviation, Double.NaN if no values have been added
219dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * or 0.0 for a single value set.
220dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
221dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double getStandardDeviation() {
222dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        double stdDev = Double.NaN;
223dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (getN() > 0) {
224dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            if (getN() > 1) {
225dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                stdDev = FastMath.sqrt(getVariance());
226dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            } else {
227dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                stdDev = 0.0;
228dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            }
229dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
230dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return stdDev;
231dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
232dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
233dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
234dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the skewness of the available values. Skewness is a
235dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * measure of the asymmetry of a given distribution.
236dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return The skewness, Double.NaN if no values have been added
237dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * or 0.0 for a value set &lt;=2.
238dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
239dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double getSkewness() {
240dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return apply(skewnessImpl);
241dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
242dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
243dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
244dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the Kurtosis of the available values. Kurtosis is a
245dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * measure of the "peakedness" of a distribution
246dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return The kurtosis, Double.NaN if no values have been added, or 0.0
247dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * for a value set &lt;=3.
248dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
249dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double getKurtosis() {
250dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return apply(kurtosisImpl);
251dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
252dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
253dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
254dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the maximum of the available values
255dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return The max or Double.NaN if no values have been added.
256dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
257dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double getMax() {
258dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return apply(maxImpl);
259dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
260dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
261dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
262dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    * Returns the minimum of the available values
263dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    * @return The min or Double.NaN if no values have been added.
264dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    */
265dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double getMin() {
266dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return apply(minImpl);
267dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
268dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
269dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
270dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the number of available values
271dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return The number of available values
272dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
273dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public long getN() {
274dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return eDA.getNumElements();
275dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
276dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
277dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
278dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the sum of the values that have been added to Univariate.
279dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return The sum or Double.NaN if no values have been added
280dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
281dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double getSum() {
282dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return apply(sumImpl);
283dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
284dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
285dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
286dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the sum of the squares of the available values.
287dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return The sum of the squares or Double.NaN if no
288dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * values have been added.
289dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
290dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double getSumsq() {
291dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return apply(sumsqImpl);
292dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
293dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
294dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
295dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Resets all statistics and storage
296dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
297dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public void clear() {
298dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        eDA.clear();
299dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
300dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
301dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
302dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
303dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the maximum number of values that can be stored in the
304dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * dataset, or INFINITE_WINDOW (-1) if there is no limit.
305dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
306dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return The current window size or -1 if its Infinite.
307dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
308dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public int getWindowSize() {
309dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return windowSize;
310dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
311dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
312dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
313dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * WindowSize controls the number of values which contribute
314dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * to the reported statistics.  For example, if
315dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * windowSize is set to 3 and the values {1,2,3,4,5}
316dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * have been added <strong> in that order</strong>
317dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * then the <i>available values</i> are {3,4,5} and all
318dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * reported statistics will be based on these values
319dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param windowSize sets the size of the window.
320dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
321dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public void setWindowSize(int windowSize) {
322dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (windowSize < 1) {
323dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            if (windowSize != INFINITE_WINDOW) {
324dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                throw MathRuntimeException.createIllegalArgumentException(
325dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                      LocalizedFormats.NOT_POSITIVE_WINDOW_SIZE, windowSize);
326dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            }
327dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
328dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
329dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.windowSize = windowSize;
330dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
331dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        // We need to check to see if we need to discard elements
332dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        // from the front of the array.  If the windowSize is less than
333dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        // the current number of elements.
334dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (windowSize != INFINITE_WINDOW && windowSize < eDA.getNumElements()) {
335dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            eDA.discardFrontElements(eDA.getNumElements() - windowSize);
336dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
337dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
338dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
339dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
340dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the current set of values in an array of double primitives.
341dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * The order of addition is preserved.  The returned array is a fresh
342dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * copy of the underlying data -- i.e., it is not a reference to the
343dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * stored data.
344dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
345dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return returns the current set of numbers in the order in which they
346dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *         were added to this set
347dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
348dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double[] getValues() {
349dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return eDA.getElements();
350dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
351dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
352dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
353dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the current set of values in an array of double primitives,
354dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * sorted in ascending order.  The returned array is a fresh
355dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * copy of the underlying data -- i.e., it is not a reference to the
356dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * stored data.
357dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return returns the current set of
358dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * numbers sorted in ascending order
359dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
360dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double[] getSortedValues() {
361dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        double[] sort = getValues();
362dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        Arrays.sort(sort);
363dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return sort;
364dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
365dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
366dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
367dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the element at the specified index
368dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param index The Index of the element
369dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return return the element at the specified index
370dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
371dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double getElement(int index) {
372dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return eDA.getElement(index);
373dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
374dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
375dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
376dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns an estimate for the pth percentile of the stored values.
377dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
378dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * The implementation provided here follows the first estimation procedure presented
379dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc252.htm">here.</a>
380dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p><p>
381dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <strong>Preconditions</strong>:<ul>
382dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <li><code>0 &lt; p &le; 100</code> (otherwise an
383dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <code>IllegalArgumentException</code> is thrown)</li>
384dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <li>at least one value must be stored (returns <code>Double.NaN
385dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *     </code> otherwise)</li>
386dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </ul></p>
387dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
388dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param p the requested percentile (scaled from 0 - 100)
389dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return An estimate for the pth percentile of the stored data
390dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @throws IllegalStateException if percentile implementation has been
391dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *  overridden and the supplied implementation does not support setQuantile
392dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * values
393dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
394dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double getPercentile(double p) {
395dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (percentileImpl instanceof Percentile) {
396dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            ((Percentile) percentileImpl).setQuantile(p);
397dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        } else {
398dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            try {
399dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                percentileImpl.getClass().getMethod(SET_QUANTILE_METHOD_NAME,
400dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                        new Class[] {Double.TYPE}).invoke(percentileImpl,
401dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                                new Object[] {Double.valueOf(p)});
402dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            } catch (NoSuchMethodException e1) { // Setter guard should prevent
403dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                throw MathRuntimeException.createIllegalArgumentException(
404dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                      LocalizedFormats.PERCENTILE_IMPLEMENTATION_UNSUPPORTED_METHOD,
405dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                      percentileImpl.getClass().getName(), SET_QUANTILE_METHOD_NAME);
406dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            } catch (IllegalAccessException e2) {
407dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                throw MathRuntimeException.createIllegalArgumentException(
408dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                      LocalizedFormats.PERCENTILE_IMPLEMENTATION_CANNOT_ACCESS_METHOD,
409dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                      SET_QUANTILE_METHOD_NAME, percentileImpl.getClass().getName());
410dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            } catch (InvocationTargetException e3) {
411dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                throw MathRuntimeException.createIllegalArgumentException(e3.getCause());
412dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            }
413dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
414dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return apply(percentileImpl);
415dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
416dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
417dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
418dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Generates a text report displaying univariate statistics from values
419dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * that have been added.  Each statistic is displayed on a separate
420dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * line.
421dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
422dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return String with line feeds displaying statistics
423dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
424dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    @Override
425dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public String toString() {
426dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        StringBuilder outBuffer = new StringBuilder();
427dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        String endl = "\n";
428dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        outBuffer.append("DescriptiveStatistics:").append(endl);
429dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        outBuffer.append("n: ").append(getN()).append(endl);
430dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        outBuffer.append("min: ").append(getMin()).append(endl);
431dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        outBuffer.append("max: ").append(getMax()).append(endl);
432dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        outBuffer.append("mean: ").append(getMean()).append(endl);
433dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        outBuffer.append("std dev: ").append(getStandardDeviation())
434dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            .append(endl);
435dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        outBuffer.append("median: ").append(getPercentile(50)).append(endl);
436dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        outBuffer.append("skewness: ").append(getSkewness()).append(endl);
437dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        outBuffer.append("kurtosis: ").append(getKurtosis()).append(endl);
438dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return outBuffer.toString();
439dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
440dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
441dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
442dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Apply the given statistic to the data associated with this set of statistics.
443dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param stat the statistic to apply
444dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the computed value of the statistic.
445dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
446dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double apply(UnivariateStatistic stat) {
447dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return stat.evaluate(eDA.getInternalValues(), eDA.start(), eDA.getNumElements());
448dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
449dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
450dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    // Implementation getters and setter
451dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
452dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
453dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the currently configured mean implementation.
454dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
455dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the UnivariateStatistic implementing the mean
456dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
457dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
458dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public synchronized UnivariateStatistic getMeanImpl() {
459dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return meanImpl;
460dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
461dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
462dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
463dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>Sets the implementation for the mean.</p>
464dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
465dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param meanImpl the UnivariateStatistic instance to use
466dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * for computing the mean
467dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
468dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
469dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public synchronized void setMeanImpl(UnivariateStatistic meanImpl) {
470dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.meanImpl = meanImpl;
471dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
472dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
473dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
474dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the currently configured geometric mean implementation.
475dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
476dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the UnivariateStatistic implementing the geometric mean
477dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
478dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
479dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public synchronized UnivariateStatistic getGeometricMeanImpl() {
480dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return geometricMeanImpl;
481dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
482dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
483dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
484dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>Sets the implementation for the gemoetric mean.</p>
485dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
486dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param geometricMeanImpl the UnivariateStatistic instance to use
487dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * for computing the geometric mean
488dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
489dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
490dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public synchronized void setGeometricMeanImpl(
491dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            UnivariateStatistic geometricMeanImpl) {
492dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.geometricMeanImpl = geometricMeanImpl;
493dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
494dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
495dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
496dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the currently configured kurtosis implementation.
497dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
498dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the UnivariateStatistic implementing the kurtosis
499dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
500dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
501dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public synchronized UnivariateStatistic getKurtosisImpl() {
502dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return kurtosisImpl;
503dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
504dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
505dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
506dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>Sets the implementation for the kurtosis.</p>
507dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
508dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param kurtosisImpl the UnivariateStatistic instance to use
509dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * for computing the kurtosis
510dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
511dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
512dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public synchronized void setKurtosisImpl(UnivariateStatistic kurtosisImpl) {
513dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.kurtosisImpl = kurtosisImpl;
514dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
515dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
516dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
517dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the currently configured maximum implementation.
518dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
519dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the UnivariateStatistic implementing the maximum
520dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
521dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
522dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public synchronized UnivariateStatistic getMaxImpl() {
523dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return maxImpl;
524dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
525dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
526dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
527dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>Sets the implementation for the maximum.</p>
528dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
529dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param maxImpl the UnivariateStatistic instance to use
530dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * for computing the maximum
531dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
532dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
533dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public synchronized void setMaxImpl(UnivariateStatistic maxImpl) {
534dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.maxImpl = maxImpl;
535dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
536dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
537dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
538dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the currently configured minimum implementation.
539dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
540dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the UnivariateStatistic implementing the minimum
541dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
542dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
543dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public synchronized UnivariateStatistic getMinImpl() {
544dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return minImpl;
545dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
546dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
547dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
548dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>Sets the implementation for the minimum.</p>
549dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
550dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param minImpl the UnivariateStatistic instance to use
551dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * for computing the minimum
552dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
553dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
554dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public synchronized void setMinImpl(UnivariateStatistic minImpl) {
555dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.minImpl = minImpl;
556dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
557dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
558dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
559dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the currently configured percentile implementation.
560dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
561dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the UnivariateStatistic implementing the percentile
562dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
563dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
564dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public synchronized UnivariateStatistic getPercentileImpl() {
565dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return percentileImpl;
566dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
567dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
568dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
569dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Sets the implementation to be used by {@link #getPercentile(double)}.
570dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * The supplied <code>UnivariateStatistic</code> must provide a
571dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <code>setQuantile(double)</code> method; otherwise
572dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <code>IllegalArgumentException</code> is thrown.
573dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
574dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param percentileImpl the percentileImpl to set
575dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @throws IllegalArgumentException if the supplied implementation does not
576dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *  provide a <code>setQuantile</code> method
577dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
578dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
579dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public synchronized void setPercentileImpl(
580dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            UnivariateStatistic percentileImpl) {
581dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        try {
582dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            percentileImpl.getClass().getMethod(SET_QUANTILE_METHOD_NAME,
583dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                    new Class[] {Double.TYPE}).invoke(percentileImpl,
584dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                            new Object[] {Double.valueOf(50.0d)});
585dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        } catch (NoSuchMethodException e1) {
586dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            throw MathRuntimeException.createIllegalArgumentException(
587dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                  LocalizedFormats.PERCENTILE_IMPLEMENTATION_UNSUPPORTED_METHOD,
588dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                  percentileImpl.getClass().getName(), SET_QUANTILE_METHOD_NAME);
589dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        } catch (IllegalAccessException e2) {
590dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            throw MathRuntimeException.createIllegalArgumentException(
591dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                  LocalizedFormats.PERCENTILE_IMPLEMENTATION_CANNOT_ACCESS_METHOD,
592dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                  SET_QUANTILE_METHOD_NAME, percentileImpl.getClass().getName());
593dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        } catch (InvocationTargetException e3) {
594dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            throw MathRuntimeException.createIllegalArgumentException(e3.getCause());
595dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
596dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.percentileImpl = percentileImpl;
597dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
598dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
599dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
600dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the currently configured skewness implementation.
601dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
602dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the UnivariateStatistic implementing the skewness
603dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
604dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
605dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public synchronized UnivariateStatistic getSkewnessImpl() {
606dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return skewnessImpl;
607dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
608dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
609dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
610dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>Sets the implementation for the skewness.</p>
611dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
612dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param skewnessImpl the UnivariateStatistic instance to use
613dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * for computing the skewness
614dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
615dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
616dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public synchronized void setSkewnessImpl(
617dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            UnivariateStatistic skewnessImpl) {
618dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.skewnessImpl = skewnessImpl;
619dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
620dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
621dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
622dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the currently configured variance implementation.
623dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
624dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the UnivariateStatistic implementing the variance
625dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
626dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
627dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public synchronized UnivariateStatistic getVarianceImpl() {
628dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return varianceImpl;
629dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
630dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
631dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
632dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>Sets the implementation for the variance.</p>
633dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
634dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param varianceImpl the UnivariateStatistic instance to use
635dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * for computing the variance
636dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
637dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
638dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public synchronized void setVarianceImpl(
639dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            UnivariateStatistic varianceImpl) {
640dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.varianceImpl = varianceImpl;
641dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
642dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
643dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
644dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the currently configured sum of squares implementation.
645dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
646dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the UnivariateStatistic implementing the sum of squares
647dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
648dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
649dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public synchronized UnivariateStatistic getSumsqImpl() {
650dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return sumsqImpl;
651dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
652dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
653dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
654dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>Sets the implementation for the sum of squares.</p>
655dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
656dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param sumsqImpl the UnivariateStatistic instance to use
657dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * for computing the sum of squares
658dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
659dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
660dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public synchronized void setSumsqImpl(UnivariateStatistic sumsqImpl) {
661dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.sumsqImpl = sumsqImpl;
662dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
663dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
664dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
665dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the currently configured sum implementation.
666dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
667dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the UnivariateStatistic implementing the sum
668dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
669dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
670dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public synchronized UnivariateStatistic getSumImpl() {
671dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return sumImpl;
672dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
673dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
674dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
675dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>Sets the implementation for the sum.</p>
676dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
677dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param sumImpl the UnivariateStatistic instance to use
678dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * for computing the sum
679dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
680dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
681dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public synchronized void setSumImpl(UnivariateStatistic sumImpl) {
682dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.sumImpl = sumImpl;
683dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
684dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
685dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
686dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns a copy of this DescriptiveStatistics instance with the same internal state.
687dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
688dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return a copy of this
689dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
690dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public DescriptiveStatistics copy() {
691dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        DescriptiveStatistics result = new DescriptiveStatistics();
692dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        copy(this, result);
693dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return result;
694dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
695dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
696dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
697dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Copies source to dest.
698dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>Neither source nor dest can be null.</p>
699dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
700dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param source DescriptiveStatistics to copy
701dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param dest DescriptiveStatistics to copy to
702dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @throws NullPointerException if either source or dest is null
703dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
704dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public static void copy(DescriptiveStatistics source, DescriptiveStatistics dest) {
705dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        // Copy data and window size
706dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        dest.eDA = source.eDA.copy();
707dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        dest.windowSize = source.windowSize;
708dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
709dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        // Copy implementations
710dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        dest.maxImpl = source.maxImpl.copy();
711dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        dest.meanImpl = source.meanImpl.copy();
712dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        dest.minImpl = source.minImpl.copy();
713dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        dest.sumImpl = source.sumImpl.copy();
714dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        dest.varianceImpl = source.varianceImpl.copy();
715dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        dest.sumsqImpl = source.sumsqImpl.copy();
716dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        dest.geometricMeanImpl = source.geometricMeanImpl.copy();
717dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        dest.kurtosisImpl = source.kurtosisImpl;
718dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        dest.skewnessImpl = source.skewnessImpl;
719dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        dest.percentileImpl = source.percentileImpl;
720dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
721dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond}
722