RangeLock { public int size() { synchronized (lockInternal) { return cache.size(); } }  Range lock(final K fromKey, final K toKey); void unlock(RangeLock<?>.Range lock); int size();  }
@Test public void testTreeMap() { final NavigableMap<Integer, Integer> cache = new TreeMap<Integer, Integer>(); cache.put(10, 10); cache.put(20, 20); cache.put(30, 30); cache.put(40, 40); NavigableMap<Integer, Integer> tmp = cache.subMap(20, true, 30, true); Assert.assertEquals(2, tmp.size()); tmp.put(25, 25); Assert.assertEquals(3, tmp.size()); }