Skip to content

Commit b983752

Browse files
committed
Add convenience method for initialization
1 parent bfa5b60 commit b983752

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/main/java/org/apache/commons/math4/stat/descriptive/SummaryStatistics.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,26 @@ public SummaryStatistics(SummaryStatistics original) throws NullArgumentExceptio
132132
copy(original, this);
133133
}
134134

135+
/**
136+
* Construct a SummaryStatistics instance filling it with the given initialDoubleArray
137+
* @param initialDoubleArray values for filling the array
138+
*/
139+
public SummaryStatistics(double[] initialDoubleArray) {
140+
for (double initialValue : initialDoubleArray) {
141+
addValue(initialValue);
142+
}
143+
}
144+
145+
/**
146+
* Construct a SummaryStatistics instance filling it with the given initialDoubleArray
147+
* @param initialDoubleArray values for filling the array
148+
*/
149+
public SummaryStatistics(Double[] initialDoubleArray) {
150+
for (Double initialValue : initialDoubleArray) {
151+
addValue(initialValue);
152+
}
153+
}
154+
135155
/**
136156
* Return a {@link StatisticalSummaryValues} instance reporting current
137157
* statistics.

src/test/java/org/apache/commons/math4/stat/descriptive/SummaryStatisticsTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ public void testQuadraticMean() {
315315
expected = Math.sqrt(expected);
316316

317317
Assert.assertEquals(expected, stats.getQuadraticMean(), Math.ulp(expected));
318+
319+
SummaryStatistics convenienceMethodStatistics = new SummaryStatistics(values);
320+
Assert.assertEquals(expected, convenienceMethodStatistics.getQuadraticMean(), Math.ulp(expected));
318321
}
319322

320323
/**

0 commit comments

Comments
 (0)