IncrementalSortMap implements ConcurrentNavigableMap<K, V> { @Override public int size() { long[] stamps = grabAllSegmentWriteLocks(); try { sort(); return sorted.size(); } finally { releaseSegmentLocks(stamps); } } @SuppressWarnings("unchecked") private  IncrementalSortMap(Comparator<? super K> comparator); static IncrementalSortMap<K, V> create(); static IncrementalSortMap<K, V> create(
            Comparator<? super K> comparator); @Override java.util.Map.Entry<K, V> ceilingEntry(K key); @Override K ceilingKey(K key); @Override void clear(); @Override Comparator<? super K> comparator(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override NavigableSet<K> descendingKeySet(); @Override ConcurrentNavigableMap<K, V> descendingMap(); @Override Set<java.util.Map.Entry<K, V>> entrySet(); @SuppressWarnings("rawtypes") @Override boolean equals(Object obj); @Override java.util.Map.Entry<K, V> firstEntry(); @Override K firstKey(); @Override java.util.Map.Entry<K, V> floorEntry(K key); @Override K floorKey(K key); @Override V get(Object key); @Override int hashCode(); @Override ConcurrentNavigableMap<K, V> headMap(K key); @Override ConcurrentNavigableMap<K, V> headMap(K toKey, boolean inclusive); @Override java.util.Map.Entry<K, V> higherEntry(K key); @Override K higherKey(K key); @Override boolean isEmpty(); @Override NavigableSet<K> keySet(); @Override java.util.Map.Entry<K, V> lastEntry(); @Override K lastKey(); @Override java.util.Map.Entry<K, V> lowerEntry(K key); @Override K lowerKey(K key); @Override NavigableSet<K> navigableKeySet(); @Override java.util.Map.Entry<K, V> pollFirstEntry(); @Override java.util.Map.Entry<K, V> pollLastEntry(); @Override @Nullable V put(K key, V value); @Override void putAll(Map<? extends K, ? extends V> m); @Override V putIfAbsent(K key, V value); @Override V remove(Object key); @Override boolean remove(Object key, Object value); @Override V replace(K key, V value); @Override boolean replace(K key, V oldValue, V newValue); @Override int size(); @Override ConcurrentNavigableMap<K, V> subMap(K fromKey, boolean fromInclusive,
            K toKey, boolean toInclusive); @Override ConcurrentNavigableMap<K, V> subMap(K fromKey, K toKey); @Override ConcurrentNavigableMap<K, V> tailMap(K fromKey); @Override ConcurrentNavigableMap<K, V> tailMap(K fromKey, boolean inclusive); @Override String toString(); @Override Collection<V> values();  }
@Test public void testSize() { IncrementalSortMap<Integer, String> map = map5(); IncrementalSortMap<Integer, String> empty = IncrementalSortMap.create(); assertEquals(0, empty.size()); assertEquals(5, map.size()); }