Counter extends BaseMeter { @Override public MeterData.Builder transform() { final double currentValue = get(); double count; if (Objects.equals(mode, CounterMode.RATE)) { final Double previousValue = previous.getAndSet(currentValue); if (previousValue == null) { count = currentValue; } else { count = currentValue - previousValue; } } else { count = currentValue; } final MeterData.Builder builder = MeterData.newBuilder(); builder.setSingleValue(MeterSingleValue.newBuilder() .setName(getName()) .addAllLabels(transformTags()) .setValue(count).build()); return builder; } Counter(MeterId meterId, CounterMode mode); void increment(double count); double get(); @Override MeterData.Builder transform();  }
@Test public void testTransform() { final Counter counter = MeterFactory.counter("test").tag("k1", "v1").build(); counter.increment(2d); validateMeterData("test", Arrays.asList(Label.newBuilder().setName("k1").setValue("v1").build()), 2d, counter.transform()); }