StatsBuffer { public void computeStats() { if (statsComputed.getAndSet(true)) { return; } if (curSize == 0) { return; } Arrays.sort(values, 0, curSize); min = values[0]; max = values[curSize - 1]; total = 0L; double sumSquares = 0.0; for (int i = 0; i < curSize; ++i) { total += values[i]; sumSquares += values[i] * values[i]; } mean = (double) total / curSize; if (curSize == 1) { variance = 0d; } else { variance = (sumSquares - ((double) total * total / curSize)) / (curSize - 1); } stddev = Math.sqrt(variance); computePercentiles(curSize); } StatsBuffer(int size, double[] percentiles); void reset(); void record(long n); void computeStats(); int getCount(); double getMean(); double getVariance(); double getStdDev(); long getMin(); long getMax(); long getTotalTime(); double[] getPercentileValues(); double[] getPercentiles(); double getPercentileValueForIdx(int index);  }
@Test public void testEmptyBuffer() { StatsBuffer buffer = new StatsBuffer(SIZE, PERCENTILES); assertEmpty(buffer); buffer.computeStats(); assertEmpty(buffer); }