BinningAggregation implements
    Aggregation<BinningAggregationOptions<P, T>, Map<String, R>, T> { @Override public void aggregate(T entry) { final String[] bins = this.options.binningStrategy.binEntry(entry); for (String bin : bins) { if (this.result.containsKey(bin)) { this.result.get(bin).aggregate(entry); } else if (this.options.maxBins == -1 || this.result.size() < this.options.maxBins) { this.result.put(bin, this.instantiateBaseAggregation()); this.result.get(bin).aggregate(entry); } } } BinningAggregation();  BinningAggregation(
      Aggregation<P, R, T> baseAggregation,
      AggregationBinningStrategy<T> binningStrategy,
      int maxBins); @Override Map<String, R> getResult(); @Override Map<String, R> merge(Map<String, R> result1, Map<String, R> result2); @Override void aggregate(T entry); @Override void clearResult(); @Override BinningAggregationOptions<P, T> getParameters(); @Override void setParameters(BinningAggregationOptions<P, T> parameters); @Override byte[] resultToBinary(Map<String, R> result); @Override Map<String, R> resultFromBinary(byte[] binary); @Override byte[] toBinary(); @Override void fromBinary(byte[] bytes);  }
@Test public void testAggregate() { BinningAggregation<Persistable, Long, CommonIndexedPersistenceEncoding> agg = new BinningAggregation<>(new CountAggregation(), randomBinStrategy, -1); agg.aggregate(null); Map<String, Long> result = agg.getResult(); assertThat(result.size(), is(1)); agg.aggregate(null); result = agg.getResult(); assertThat(result.size(), is(2)); agg.clearResult(); agg.aggregate(null); result = agg.getResult(); assertThat(result.size(), is(1)); }