ValueStats implements JmxRefreshableStats<ValueStats>, JmxStatsWithReset, JmxStatsWithSmoothingWindow { public ValueStats withUnit(String unit) { this.unit = unit; return this; } private  ValueStats(double smoothingWindow); private  ValueStats(); static ValueStats createAccumulator(); static ValueStats create(Duration smoothingWindow); ValueStats withUnit(String unit); ValueStats withRate(String rateUnit); ValueStats withRate(); ValueStats withHistogram(JmxHistogram histogram); ValueStats withHistogram(int[] histogram); ValueStats withAbsoluteValues(boolean value); ValueStats withAverageAndDeviation(boolean value); ValueStats withMinMax(boolean value); ValueStats withLastValue(boolean value); ValueStats withPrecision(int precision); ValueStats withScientificNotation(); void setHistogram(JmxHistogram histogram); void setHistogram(int[] levels); @Override void resetStats(); void recordValue(int value); void recordValue(double value); @Override void refresh(long timestamp); @Override void add(ValueStats anotherStats); @JmxAttribute(optional = true) double getLastValue(); @JmxAttribute(optional = true) double getSmoothedAverage(); @JmxAttribute(optional = true) double getSmoothedStandardDeviation(); @JmxAttribute(name = "min", optional = true) double getSmoothedMin(); @JmxAttribute(name = "max", optional = true) double getSmoothedMax(); @JmxAttribute(name = "absoluteMin", optional = true) double getAbsosuteMin(); @JmxAttribute(name = "absoluteMax", optional = true) double getAbsoluteMax(); @JmxAttribute(optional = true) double getAverage(); @JmxAttribute(optional = true) double getSmoothedRate(); @Override @JmxAttribute(optional = true) Duration getSmoothingWindow(); @Override @JmxAttribute(optional = true) void setSmoothingWindow(Duration smoothingWindow); @JmxAttribute(optional = true) long getCount(); @SuppressWarnings({"OptionalGetWithoutIsPresent", "ConstantConditions"}) @Nullable @JmxAttribute(optional = true) List<String> getHistogram(); @JmxAttribute String get(); @Override String toString();  }
@Test public void testWithUnit() { ValueStats valueStats = ValueStats.create(Duration.ofSeconds(10)).withUnit("bytes"); long currentTimestamp = 0; double inputValue = 1; int iterations = 100; for (int i = 0; i < iterations; i++) { valueStats.recordValue(inputValue); currentTimestamp += ONE_SECOND_IN_MILLIS; valueStats.refresh(currentTimestamp); inputValue += 100; } assertEquals("8518±1408 bytes [7152...9901] last: 9901", valueStats.toString()); }