replace string concatenation with StringBuffer.append calls.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@635150 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brent Worden 2008-03-09 03:30:30 +00:00
parent 7d28e0f53d
commit 80416d808e
2 changed files with 226 additions and 225 deletions

View File

@ -411,15 +411,17 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable {
*/ */
public String toString() { public String toString() {
StringBuffer outBuffer = new StringBuffer(); StringBuffer outBuffer = new StringBuffer();
outBuffer.append("DescriptiveStatistics:\n"); String endl = "\n";
outBuffer.append("n: " + getN() + "\n"); outBuffer.append("DescriptiveStatistics:").append(endl);
outBuffer.append("min: " + getMin() + "\n"); outBuffer.append("n: ").append(getN()).append(endl);
outBuffer.append("max: " + getMax() + "\n"); outBuffer.append("min: ").append(getMin()).append(endl);
outBuffer.append("mean: " + getMean() + "\n"); outBuffer.append("max: ").append(getMax()).append(endl);
outBuffer.append("std dev: " + getStandardDeviation() + "\n"); outBuffer.append("mean: ").append(getMean()).append(endl);
outBuffer.append("median: " + getPercentile(50) + "\n"); outBuffer.append("std dev: ").append(getStandardDeviation())
outBuffer.append("skewness: " + getSkewness() + "\n"); .append(endl);
outBuffer.append("kurtosis: " + getKurtosis() + "\n"); outBuffer.append("median: ").append(getPercentile(50)).append(endl);
outBuffer.append("skewness: ").append(getSkewness()).append(endl);
outBuffer.append("kurtosis: ").append(getKurtosis()).append(endl);
return outBuffer.toString(); return outBuffer.toString();
} }

View File

@ -1,18 +1,15 @@
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with this
* this work for additional information regarding copyright ownership. * work for additional information regarding copyright ownership. The ASF
* The ASF licenses this file to You under the Apache License, Version 2.0 * licenses this file to You under the Apache License, Version 2.0 (the
* (the "License"); you may not use this file except in compliance with * "License"); you may not use this file except in compliance with the License.
* the License. You may obtain a copy of the License at * You may obtain a copy of the License at
* * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
* http://www.apache.org/licenses/LICENSE-2.0 * or agreed to in writing, software distributed under the License is
* * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* Unless required by applicable law or agreed to in writing, software * KIND, either express or implied. See the License for the specific language
* distributed under the License is distributed on an "AS IS" BASIS, * governing permissions and limitations under the License.
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package org.apache.commons.math.stat.descriptive; package org.apache.commons.math.stat.descriptive;
@ -31,25 +28,29 @@ import org.apache.commons.math.stat.descriptive.summary.SumOfSquares;
import org.apache.commons.math.util.MathUtils; import org.apache.commons.math.util.MathUtils;
/** /**
* <p>Computes summary statistics for a stream of data values added using the * <p>
* Computes summary statistics for a stream of data values added using the
* {@link #addValue(double) addValue} method. The data values are not stored in * {@link #addValue(double) addValue} method. The data values are not stored in
* memory, so this class can be used to compute statistics for very large * memory, so this class can be used to compute statistics for very large data
* data streams.</p> * streams.
* * </p>
* <p>The {@link StorelessUnivariateStatistic} instances used to maintain * <p>
* summary state and compute statistics are configurable via setters. * The {@link StorelessUnivariateStatistic} instances used to maintain summary
* For example, the default implementation for the variance can be overridden by * state and compute statistics are configurable via setters. For example, the
* calling {@link #setVarianceImpl(StorelessUnivariateStatistic)}. Actual * default implementation for the variance can be overridden by calling
* parameters to these methods must implement the * {@link #setVarianceImpl(StorelessUnivariateStatistic)}. Actual parameters to
* {@link StorelessUnivariateStatistic} interface and configuration must be * these methods must implement the {@link StorelessUnivariateStatistic}
* completed before <code>addValue</code> is called. No configuration is * interface and configuration must be completed before <code>addValue</code>
* necessary to use the default, commons-math provided implementations.</p> * is called. No configuration is necessary to use the default, commons-math
* * provided implementations.
* <p>Note: This class is not thread-safe. Use * </p>
* <p>
* Note: This class is not thread-safe. Use
* {@link SynchronizedSummaryStatistics} if concurrent access from multiple * {@link SynchronizedSummaryStatistics} if concurrent access from multiple
* threads is required.</p> * threads is required.
* * </p>
* @version $Revision$ $Date$ * @version $Revision$ $Date: 2008-02-10 13:28:59 -0600 (Sun, 10 Feb
* 2008) $
*/ */
public class SummaryStatistics implements StatisticalSummary, Serializable { public class SummaryStatistics implements StatisticalSummary, Serializable {
@ -58,24 +59,20 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
/** /**
* Create an instance of a <code>SummaryStatistics</code> * Create an instance of a <code>SummaryStatistics</code>
* * @param cls the type of <code>SummaryStatistics</code> object to create.
* @param cls the type of <code>SummaryStatistics</code> object to
* create.
* @return a new instance. * @return a new instance.
* @deprecated to be removed in commons-math 2.0 * @deprecated to be removed in commons-math 2.0
* @throws InstantiationException is thrown if the object can not be * @throws InstantiationException is thrown if the object can not be
* created. * created.
* @throws IllegalAccessException is thrown if the type's default * @throws IllegalAccessException is thrown if the type's default
* constructor is not accessible. * constructor is not accessible.
*/ */
public static SummaryStatistics newInstance(Class cls) throws public static SummaryStatistics newInstance(Class cls) throws InstantiationException, IllegalAccessException {
InstantiationException, IllegalAccessException {
return (SummaryStatistics)cls.newInstance(); return (SummaryStatistics)cls.newInstance();
} }
/** /**
* Create an instance of a <code>SummaryStatistics</code> * Create an instance of a <code>SummaryStatistics</code>
*
* @return a new SummaryStatistics instance. * @return a new SummaryStatistics instance.
* @deprecated to be removed in commons-math 2.0 * @deprecated to be removed in commons-math 2.0
*/ */
@ -83,10 +80,8 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
SummaryStatistics instance = null; SummaryStatistics instance = null;
try { try {
DiscoverClass dc = new DiscoverClass(); DiscoverClass dc = new DiscoverClass();
instance = (SummaryStatistics) dc.newInstance( instance = (SummaryStatistics)dc.newInstance(SummaryStatistics.class, "org.apache.commons.math.stat.descriptive.SummaryStatisticsImpl");
SummaryStatistics.class, } catch (Throwable t) {
"org.apache.commons.math.stat.descriptive.SummaryStatisticsImpl");
} catch(Throwable t) {
return new SummaryStatisticsImpl(); return new SummaryStatisticsImpl();
} }
return instance; return instance;
@ -155,18 +150,15 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
/** /**
* Return a {@link StatisticalSummaryValues} instance reporting current * Return a {@link StatisticalSummaryValues} instance reporting current
* statistics. * statistics.
*
* @return Current values of statistics * @return Current values of statistics
*/ */
public StatisticalSummary getSummary() { public StatisticalSummary getSummary() {
return new StatisticalSummaryValues(getMean(), getVariance(), getN(), return new StatisticalSummaryValues(getMean(), getVariance(), getN(), getMax(), getMin(), getSum());
getMax(), getMin(), getSum());
} }
/** /**
* Add a value to the data * Add a value to the data
* * @param value the value to add
* @param value the value to add
*/ */
public void addValue(double value) { public void addValue(double value) {
sumImpl.increment(value); sumImpl.increment(value);
@ -178,7 +170,7 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
// If mean, variance or geomean have been overridden, // If mean, variance or geomean have been overridden,
// need to increment these // need to increment these
if (!(meanImpl instanceof Mean)) { if (!(meanImpl instanceof Mean)) {
meanImpl.increment(value); meanImpl.increment(value);
} }
if (!(varianceImpl instanceof Variance)) { if (!(varianceImpl instanceof Variance)) {
varianceImpl.increment(value); varianceImpl.increment(value);
@ -208,8 +200,8 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
/** /**
* Returns the sum of the squares of the values that have been added. * Returns the sum of the squares of the values that have been added.
* <p> * <p>
* Double.NaN is returned if no values have been added.</p> * Double.NaN is returned if no values have been added.
* * </p>
* @return The sum of squares * @return The sum of squares
*/ */
public double getSumsq() { public double getSumsq() {
@ -219,23 +211,23 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
/** /**
* Returns the mean of the values that have been added. * Returns the mean of the values that have been added.
* <p> * <p>
* Double.NaN is returned if no values have been added.</p> * Double.NaN is returned if no values have been added.
* * </p>
* @return the mean * @return the mean
*/ */
public double getMean() { public double getMean() {
if (mean == meanImpl) { if (mean == meanImpl) {
return new Mean(secondMoment).getResult(); return new Mean(secondMoment).getResult();
} else { } else {
return meanImpl.getResult(); return meanImpl.getResult();
} }
} }
/** /**
* Returns the standard deviation of the values that have been added. * Returns the standard deviation of the values that have been added.
* <p> * <p>
* Double.NaN is returned if no values have been added.</p> * Double.NaN is returned if no values have been added.
* * </p>
* @return the standard deviation * @return the standard deviation
*/ */
public double getStandardDeviation() { public double getStandardDeviation() {
@ -253,8 +245,8 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
/** /**
* Returns the variance of the values that have been added. * Returns the variance of the values that have been added.
* <p> * <p>
* Double.NaN is returned if no values have been added.</p> * Double.NaN is returned if no values have been added.
* * </p>
* @return the variance * @return the variance
*/ */
public double getVariance() { public double getVariance() {
@ -268,8 +260,8 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
/** /**
* Returns the maximum of the values that have been added. * Returns the maximum of the values that have been added.
* <p> * <p>
* Double.NaN is returned if no values have been added.</p> * Double.NaN is returned if no values have been added.
* * </p>
* @return the maximum * @return the maximum
*/ */
public double getMax() { public double getMax() {
@ -279,8 +271,8 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
/** /**
* Returns the minimum of the values that have been added. * Returns the minimum of the values that have been added.
* <p> * <p>
* Double.NaN is returned if no values have been added.</p> * Double.NaN is returned if no values have been added.
* * </p>
* @return the minimum * @return the minimum
*/ */
public double getMin() { public double getMin() {
@ -290,8 +282,8 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
/** /**
* Returns the geometric mean of the values that have been added. * Returns the geometric mean of the values that have been added.
* <p> * <p>
* Double.NaN is returned if no values have been added.</p> * Double.NaN is returned if no values have been added.
* * </p>
* @return the geometric mean * @return the geometric mean
*/ */
public double getGeometricMean() { public double getGeometricMean() {
@ -301,8 +293,8 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
/** /**
* Returns the sum of the logs of the values that have been added. * Returns the sum of the logs of the values that have been added.
* <p> * <p>
* Double.NaN is returned if no values have been added.</p> * Double.NaN is returned if no values have been added.
* * </p>
* @return the sum of logs * @return the sum of logs
* @since 1.2 * @since 1.2
*/ */
@ -311,24 +303,26 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
} }
/** /**
* Generates a text report displaying * Generates a text report displaying summary statistics from values that
* summary statistics from values that
* have been added. * have been added.
* @return String with line feeds displaying statistics * @return String with line feeds displaying statistics
* @since 1.2 * @since 1.2
*/ */
public String toString() { public String toString() {
StringBuffer outBuffer = new StringBuffer(); StringBuffer outBuffer = new StringBuffer();
outBuffer.append("SummaryStatistics:\n"); String endl = "\n";
outBuffer.append("n: " + getN() + "\n"); outBuffer.append("SummaryStatistics:").append(endl);
outBuffer.append("min: " + getMin() + "\n"); outBuffer.append("n: ").append(getN()).append(endl);
outBuffer.append("max: " + getMax() + "\n"); outBuffer.append("min: ").append(getMin()).append(endl);
outBuffer.append("mean: " + getMean() + "\n"); outBuffer.append("max: ").append(getMax()).append(endl);
outBuffer.append("geometric mean: " + getGeometricMean() + "\n"); outBuffer.append("mean: ").append(getMean()).append(endl);
outBuffer.append("variance: " + getVariance() + "\n"); outBuffer.append("geometric mean: ").append(getGeometricMean())
outBuffer.append("sum of squares: " + getSumsq() + "\n"); .append(endl);
outBuffer.append("standard deviation: " + getStandardDeviation() + "\n"); outBuffer.append("variance: ").append(getVariance()).append(endl);
outBuffer.append("sum of logs: " + getSumOfLogs() + "\n"); outBuffer.append("sum of squares: ").append(getSumsq()).append(endl);
outBuffer.append("standard deviation: ").append(getStandardDeviation())
.append(endl);
outBuffer.append("sum of logs: ").append(getSumOfLogs()).append(endl);
return outBuffer.toString(); return outBuffer.toString();
} }
@ -353,33 +347,28 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
} }
/** /**
* Returns true iff <code>object</code> is a <code>SummaryStatistics</code> * Returns true iff <code>object</code> is a
* instance and all statistics have the same values as this. * <code>SummaryStatistics</code> instance and all statistics have the
* same values as this.
* @param object the object to test equality against. * @param object the object to test equality against.
* @return true if object equals this * @return true if object equals this
*/ */
public boolean equals(Object object) { public boolean equals(Object object) {
if (object == this ) { if (object == this) {
return true; return true;
} }
if (object instanceof SummaryStatistics == false) { if (object instanceof SummaryStatistics == false) {
return false; return false;
} }
SummaryStatistics stat = (SummaryStatistics) object; SummaryStatistics stat = (SummaryStatistics)object;
return (MathUtils.equals(stat.getGeometricMean(), return (MathUtils.equals(stat.getGeometricMean(), this.getGeometricMean()) && MathUtils.equals(stat.getMax(), this.getMax())
this.getGeometricMean()) && && MathUtils.equals(stat.getMean(), this.getMean()) && MathUtils.equals(stat.getMin(), this.getMin()) && MathUtils.equals(stat.getN(), this.getN())
MathUtils.equals(stat.getMax(), this.getMax()) && && MathUtils.equals(stat.getSum(), this.getSum()) && MathUtils.equals(stat.getSumsq(), this.getSumsq()) && MathUtils.equals(stat.getVariance(),
MathUtils.equals(stat.getMean(),this.getMean()) && this.getVariance()));
MathUtils.equals(stat.getMin(),this.getMin()) &&
MathUtils.equals(stat.getN(), this.getN()) &&
MathUtils.equals(stat.getSum(), this.getSum()) &&
MathUtils.equals(stat.getSumsq(),this.getSumsq()) &&
MathUtils.equals(stat.getVariance(),this.getVariance()));
} }
/** /**
* Returns hash code based on values of statistics * Returns hash code based on values of statistics
*
* @return hash code * @return hash code
*/ */
public int hashCode() { public int hashCode() {
@ -398,7 +387,6 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
// Getters and setters for statistics implementations // Getters and setters for statistics implementations
/** /**
* Returns the currently configured Sum implementation * Returns the currently configured Sum implementation
*
* @return the StorelessUnivariateStatistic implementing the sum * @return the StorelessUnivariateStatistic implementing the sum
* @since 1.2 * @since 1.2
*/ */
@ -407,15 +395,18 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
} }
/** /**
* <p>Sets the implementation for the Sum.</p> * <p>
* <p>This method must be activated before any data has been added - i.e., * Sets the implementation for the Sum.
* </p>
* <p>
* This method must be activated before any data has been added - i.e.,
* before {@link #addValue(double) addValue} has been used to add data; * before {@link #addValue(double) addValue} has been used to add data;
* otherwise an IllegalStateException will be thrown.</p> * otherwise an IllegalStateException will be thrown.
* * </p>
* @param sumImpl the StorelessUnivariateStatistic instance to use * @param sumImpl the StorelessUnivariateStatistic instance to use for
* for computing the Sum * computing the Sum
* @throws IllegalStateException if data has already been added * @throws IllegalStateException if data has already been added (i.e if n >
* (i.e if n > 0) * 0)
* @since 1.2 * @since 1.2
*/ */
public void setSumImpl(StorelessUnivariateStatistic sumImpl) { public void setSumImpl(StorelessUnivariateStatistic sumImpl) {
@ -425,7 +416,6 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
/** /**
* Returns the currently configured sum of squares implementation * Returns the currently configured sum of squares implementation
*
* @return the StorelessUnivariateStatistic implementing the sum of squares * @return the StorelessUnivariateStatistic implementing the sum of squares
* @since 1.2 * @since 1.2
*/ */
@ -434,26 +424,27 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
} }
/** /**
* <p>Sets the implementation for the sum of squares.</p> * <p>
* <p>This method must be activated before any data has been added - i.e., * Sets the implementation for the sum of squares.
* </p>
* <p>
* This method must be activated before any data has been added - i.e.,
* before {@link #addValue(double) addValue} has been used to add data; * before {@link #addValue(double) addValue} has been used to add data;
* otherwise an IllegalStateException will be thrown.</p> * otherwise an IllegalStateException will be thrown.
* * </p>
* @param sumsqImpl the StorelessUnivariateStatistic instance to use * @param sumsqImpl the StorelessUnivariateStatistic instance to use for
* for computing the sum of squares * computing the sum of squares
* @throws IllegalStateException if data has already been added * @throws IllegalStateException if data has already been added (i.e if n >
* (i.e if n > 0) * 0)
* @since 1.2 * @since 1.2
*/ */
public void setSumsqImpl( public void setSumsqImpl(StorelessUnivariateStatistic sumsqImpl) {
StorelessUnivariateStatistic sumsqImpl) {
checkEmpty(); checkEmpty();
this.sumsqImpl = sumsqImpl; this.sumsqImpl = sumsqImpl;
} }
/** /**
* Returns the currently configured minimum implementation * Returns the currently configured minimum implementation
*
* @return the StorelessUnivariateStatistic implementing the minimum * @return the StorelessUnivariateStatistic implementing the minimum
* @since 1.2 * @since 1.2
*/ */
@ -462,15 +453,18 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
} }
/** /**
* <p>Sets the implementation for the minimum.</p> * <p>
* <p>This method must be activated before any data has been added - i.e., * Sets the implementation for the minimum.
* </p>
* <p>
* This method must be activated before any data has been added - i.e.,
* before {@link #addValue(double) addValue} has been used to add data; * before {@link #addValue(double) addValue} has been used to add data;
* otherwise an IllegalStateException will be thrown.</p> * otherwise an IllegalStateException will be thrown.
* * </p>
* @param minImpl the StorelessUnivariateStatistic instance to use * @param minImpl the StorelessUnivariateStatistic instance to use for
* for computing the minimum * computing the minimum
* @throws IllegalStateException if data has already been added * @throws IllegalStateException if data has already been added (i.e if n >
* (i.e if n > 0) * 0)
* @since 1.2 * @since 1.2
*/ */
public void setMinImpl(StorelessUnivariateStatistic minImpl) { public void setMinImpl(StorelessUnivariateStatistic minImpl) {
@ -480,7 +474,6 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
/** /**
* Returns the currently configured maximum implementation * Returns the currently configured maximum implementation
*
* @return the StorelessUnivariateStatistic implementing the maximum * @return the StorelessUnivariateStatistic implementing the maximum
* @since 1.2 * @since 1.2
*/ */
@ -489,15 +482,18 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
} }
/** /**
* <p>Sets the implementation for the maximum.</p> * <p>
* <p>This method must be activated before any data has been added - i.e., * Sets the implementation for the maximum.
* </p>
* <p>
* This method must be activated before any data has been added - i.e.,
* before {@link #addValue(double) addValue} has been used to add data; * before {@link #addValue(double) addValue} has been used to add data;
* otherwise an IllegalStateException will be thrown.</p> * otherwise an IllegalStateException will be thrown.
* * </p>
* @param maxImpl the StorelessUnivariateStatistic instance to use * @param maxImpl the StorelessUnivariateStatistic instance to use for
* for computing the maximum * computing the maximum
* @throws IllegalStateException if data has already been added * @throws IllegalStateException if data has already been added (i.e if n >
* (i.e if n > 0) * 0)
* @since 1.2 * @since 1.2
*/ */
public void setMaxImpl(StorelessUnivariateStatistic maxImpl) { public void setMaxImpl(StorelessUnivariateStatistic maxImpl) {
@ -507,7 +503,6 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
/** /**
* Returns the currently configured sum of logs implementation * Returns the currently configured sum of logs implementation
*
* @return the StorelessUnivariateStatistic implementing the log sum * @return the StorelessUnivariateStatistic implementing the log sum
* @since 1.2 * @since 1.2
*/ */
@ -516,19 +511,21 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
} }
/** /**
* <p>Sets the implementation for the sum of logs.</p> * <p>
* <p>This method must be activated before any data has been added - i.e., * Sets the implementation for the sum of logs.
* </p>
* <p>
* This method must be activated before any data has been added - i.e.,
* before {@link #addValue(double) addValue} has been used to add data; * before {@link #addValue(double) addValue} has been used to add data;
* otherwise an IllegalStateException will be thrown.</p> * otherwise an IllegalStateException will be thrown.
* * </p>
* @param sumLogImpl the StorelessUnivariateStatistic instance to use * @param sumLogImpl the StorelessUnivariateStatistic instance to use for
* for computing the log sum * computing the log sum
* @throws IllegalStateException if data has already been added * @throws IllegalStateException if data has already been added (i.e if n >
* (i.e if n > 0) * 0)
* @since 1.2 * @since 1.2
*/ */
public void setSumLogImpl( public void setSumLogImpl(StorelessUnivariateStatistic sumLogImpl) {
StorelessUnivariateStatistic sumLogImpl) {
checkEmpty(); checkEmpty();
this.sumLogImpl = sumLogImpl; this.sumLogImpl = sumLogImpl;
geoMean.setSumLogImpl(sumLogImpl); geoMean.setSumLogImpl(sumLogImpl);
@ -536,7 +533,6 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
/** /**
* Returns the currently configured geometric mean implementation * Returns the currently configured geometric mean implementation
*
* @return the StorelessUnivariateStatistic implementing the geometric mean * @return the StorelessUnivariateStatistic implementing the geometric mean
* @since 1.2 * @since 1.2
*/ */
@ -545,26 +541,27 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
} }
/** /**
* <p>Sets the implementation for the geometric mean.</p> * <p>
* <p>This method must be activated before any data has been added - i.e., * Sets the implementation for the geometric mean.
* </p>
* <p>
* This method must be activated before any data has been added - i.e.,
* before {@link #addValue(double) addValue} has been used to add data; * before {@link #addValue(double) addValue} has been used to add data;
* otherwise an IllegalStateException will be thrown.</p> * otherwise an IllegalStateException will be thrown.
* * </p>
* @param geoMeanImpl the StorelessUnivariateStatistic instance to use * @param geoMeanImpl the StorelessUnivariateStatistic instance to use for
* for computing the geometric mean * computing the geometric mean
* @throws IllegalStateException if data has already been added * @throws IllegalStateException if data has already been added (i.e if n >
* (i.e if n > 0) * 0)
* @since 1.2 * @since 1.2
*/ */
public void setGeoMeanImpl( public void setGeoMeanImpl(StorelessUnivariateStatistic geoMeanImpl) {
StorelessUnivariateStatistic geoMeanImpl) {
checkEmpty(); checkEmpty();
this.geoMeanImpl = geoMeanImpl; this.geoMeanImpl = geoMeanImpl;
} }
/** /**
* Returns the currently configured mean implementation * Returns the currently configured mean implementation
*
* @return the StorelessUnivariateStatistic implementing the mean * @return the StorelessUnivariateStatistic implementing the mean
* @since 1.2 * @since 1.2
*/ */
@ -573,26 +570,27 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
} }
/** /**
* <p>Sets the implementation for the mean.</p> * <p>
* <p>This method must be activated before any data has been added - i.e., * Sets the implementation for the mean.
* </p>
* <p>
* This method must be activated before any data has been added - i.e.,
* before {@link #addValue(double) addValue} has been used to add data; * before {@link #addValue(double) addValue} has been used to add data;
* otherwise an IllegalStateException will be thrown.</p> * otherwise an IllegalStateException will be thrown.
* * </p>
* @param meanImpl the StorelessUnivariateStatistic instance to use * @param meanImpl the StorelessUnivariateStatistic instance to use for
* for computing the mean * computing the mean
* @throws IllegalStateException if data has already been added * @throws IllegalStateException if data has already been added (i.e if n >
* (i.e if n > 0) * 0)
* @since 1.2 * @since 1.2
*/ */
public void setMeanImpl( public void setMeanImpl(StorelessUnivariateStatistic meanImpl) {
StorelessUnivariateStatistic meanImpl) {
checkEmpty(); checkEmpty();
this.meanImpl = meanImpl; this.meanImpl = meanImpl;
} }
/** /**
* Returns the currently configured variance implementation * Returns the currently configured variance implementation
*
* @return the StorelessUnivariateStatistic implementing the variance * @return the StorelessUnivariateStatistic implementing the variance
* @since 1.2 * @since 1.2
*/ */
@ -601,19 +599,21 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
} }
/** /**
* <p>Sets the implementation for the variance.</p> * <p>
* <p>This method must be activated before any data has been added - i.e., * Sets the implementation for the variance.
* </p>
* <p>
* This method must be activated before any data has been added - i.e.,
* before {@link #addValue(double) addValue} has been used to add data; * before {@link #addValue(double) addValue} has been used to add data;
* otherwise an IllegalStateException will be thrown.</p> * otherwise an IllegalStateException will be thrown.
* * </p>
* @param varianceImpl the StorelessUnivariateStatistic instance to use * @param varianceImpl the StorelessUnivariateStatistic instance to use for
* for computing the variance * computing the variance
* @throws IllegalStateException if data has already been added * @throws IllegalStateException if data has already been added (i.e if n >
* (i.e if n > 0) * 0)
* @since 1.2 * @since 1.2
*/ */
public void setVarianceImpl( public void setVarianceImpl(StorelessUnivariateStatistic varianceImpl) {
StorelessUnivariateStatistic varianceImpl) {
checkEmpty(); checkEmpty();
this.varianceImpl = varianceImpl; this.varianceImpl = varianceImpl;
} }
@ -623,8 +623,7 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
*/ */
private void checkEmpty() { private void checkEmpty() {
if (n > 0) { if (n > 0) {
throw new IllegalStateException( throw new IllegalStateException("Implementations must be configured before values are added.");
"Implementations must be configured before values are added.");
} }
} }