AvgLabeledFunction extends Metrics implements AcceptableValue<DataTable>, LabeledValueHolder { @Override public final void calculate() { Set<String> keys = count.keys(); for (String key : keys) { Long s = summation.get(key); if (Objects.isNull(s)) { continue; } Long c = count.get(key); if (Objects.isNull(c)) { continue; } long result = s / c; if (result == 0 && s > 0) { result = 1; } value.put(key, result); } }  @Override final void combine(Metrics metrics); @Override final void calculate(); @Override Metrics toHour(); @Override Metrics toDay(); @Override int remoteHashCode(); @Override void deserialize(final RemoteData remoteData); @Override RemoteData.Builder serialize(); @Override String id(); @Override void accept(final MeterEntity entity, final DataTable value); @Override Class<? extends AvgLabeledStorageBuilder> builder(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void testCalculate() { function.accept(MeterEntity.newService("request_count"), build(asList("200", "404"), asList(10L, 2L))); function.accept(MeterEntity.newService("request_count"), build(asList("200", "500"), asList(2L, 3L))); function.calculate(); assertThat(function.getValue().sortedKeys(Comparator.naturalOrder()), is(asList("200", "404", "500"))); assertThat(function.getValue().sortedValues(Comparator.naturalOrder()), is(asList(6L, 2L, 3L))); }