ApproximateCounter { public static long adjustOffset(long oldCount, long calculatedOffset, int resolution) { if (oldCount + calculatedOffset < 0) { return -oldCount; } if (resolution <= 10 || oldCount < resolution * 10) { return calculatedOffset; } return RANDOM.nextInt(10) == 0 ? calculatedOffset * 10 : 0; } private  ApproximateCounter(); static long calculateOffset(long offset, int resolution); static long adjustOffset(long oldCount, long calculatedOffset,
            int resolution); static void adjustCountSync(NodeBuilder builder, long offset); static long getCountSync(NodeState node); static final String COUNT_PROPERTY_PREFIX; static final int COUNT_RESOLUTION; static final int COUNT_MAX; }
@Test public void keepAboveZero() { assertEquals(1234, ApproximateCounter.adjustOffset(-1234, -100, 10)); }
@Test public void highResolutionAdjust() { for (int i = 0; i < 10; i++) { assertEquals(123, ApproximateCounter.adjustOffset(i, 123, 1)); } }