ApproximateCounter { public static long calculateOffset(long offset, int resolution) { if (offset == 0 || resolution <= 1) { return offset; } int add = resolution; if (offset < 0) { offset = -offset; add = -add; } long result = 0; for (long i = 0; i < offset; i++) { if (RANDOM.nextInt(resolution) == 0) { result += add; } } return result; } 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 veryHighResolution() { for (int i = -100; i < 100; i++) { assertEquals(i, ApproximateCounter.calculateOffset(i, -1)); assertEquals(i, ApproximateCounter.calculateOffset(i, 0)); assertEquals(i, ApproximateCounter.calculateOffset(i, 1)); } }