ExponentiallyDecayingReservoir implements Reservoir { @Override public Snapshot getSnapshot() { rescaleIfNeeded(); lockForRegularUsage(); try { return new WeightedSnapshot(values.values()); } finally { unlockForRegularUsage(); } } ExponentiallyDecayingReservoir();  ExponentiallyDecayingReservoir(int size, double alpha);  ExponentiallyDecayingReservoir(int size, double alpha, Clock clock); @Override int size(); @Override void update(long value); void update(long value, long timestamp); @Override Snapshot getSnapshot();  }
@Test public void removeZeroWeightsInSamplesToPreventNaNInMeanValues() { final ManualClock clock = new ManualClock(); final ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir(1028, 0.015, clock); Timer timer = new Timer(reservoir, clock); Context context = timer.time(); clock.addMillis(100); context.stop(); for (int i = 1; i < 48; i++) { clock.addHours(1); assertThat(reservoir.getSnapshot().getMean()).isBetween(0.0, Double.MAX_VALUE); } }