Aggregation implements Iterable<Sample>, Serializable { public void add(long ts, double value) { AggregatedValue val = buckets.get(ts); if (null == val) { buckets.put(ts, val = new AggregatedValue()); } val.setValue(aggregator.aggregate(val.getValue(), val.getCount(), value)); val.incrementCount(); } Aggregation(Aggregator agg); void add(long ts, double value); void merge(Aggregation other); @Override Iterator<Sample> iterator(); @Override String toString(); static Aggregation combineAggregation(Collection<Aggregation> samples, QueryRequest.RateOption rateOption); void clear(); int getNumBuckets();  }
@Test public void simple() { Aggregation asample = new Aggregation(new Avg()); for (int i = 10; i < 30; i++) { asample.add(i, i - 10); } for (int i = 10; i < 30; i++) { asample.add(i, i); } int i = 0; for (Sample sample : asample) { assertEquals(10 + i, sample.timestamp); assertTrue(sample.timestamp < 30); assertEquals(i + 5, (int) sample.value); i++; } assertEquals(20, i); asample = new Aggregation(new Sum()); for (int j = 0; j < 5; j++) { for (int k = 10; k < 100; k++) { asample.add(k, j + 0.); } } i = 0; for (Sample sample : asample) { assertEquals(10 + i, sample.timestamp); assertEquals((1 + 2 + 3 + 4), sample.value, 0.0D); i++; } assertEquals(100 - 10, i); }