public int streamCount() { return refCountByStreamIdMap.size() + refCountByStreamIdAndSessionIdMap.size(); }
/** * Compact the backing arrays by rehashing with a capacity just larger than current size * and giving consideration to the load factor. */ public void compact() { @DoNotSub final int idealCapacity = (int)Math.round(size() * (1.0d / loadFactor)); rehash(findNextPositivePowerOfTwo(Math.max(MIN_CAPACITY, idealCapacity))); }
@Test public void sizeShouldReturnNumberOfEntries() { final int count = 100; for (int key = 0; key < count; key++) { map.put(key, 1); } assertEquals(count, map.size()); }
@Test public void shouldReturnOldValueForGetAndAddNot0IfKeyExists() { map.put(1, 1); int amount; do { amount = ThreadLocalRandom.current().nextInt(); } while (amount == 0); final int val = map.getAndAdd(1, amount); assertEquals(1, val); assertEquals(1, map.size()); }
@Test public void shouldInitiallyBeEmpty() { assertEquals(0, map.size()); assertTrue(map.isEmpty()); }
@Test public void shouldReturnOldValueForGetAndAdd0IfKeyExists() { map.put(1, 1); final int val = map.getAndAdd(1, 0); assertEquals(1, val); assertEquals(1, map.size()); }
@Test public void clearShouldResetSize() { map.put(1, 1); map.put(100, 100); map.clear(); assertEquals(0, map.size()); assertTrue(map.isEmpty()); }
@Test public void shouldResultInNotEmptyAfterIncAndDecWhenHaveKey() { map.put(1, 1); map.incrementAndGet(1); map.decrementAndGet(1); assertEquals(1, map.get(1)); assertEquals(1, map.size()); }
@Test public void shouldAllowInitialValueAsKey() { map.put(INITIAL_VALUE, 1); assertEquals(1, map.get(INITIAL_VALUE)); assertTrue(map.containsKey(INITIAL_VALUE)); assertEquals(1, map.size()); final int[] tuple = new int[2]; map.forEach((k, v) -> { tuple[0] = k; tuple[1] = v; }); assertEquals(INITIAL_VALUE, tuple[0]); assertEquals(1, tuple[1]); assertEquals(1, map.remove(INITIAL_VALUE)); assertEquals(0, map.size()); assertEquals(INITIAL_VALUE, map.get(INITIAL_VALUE)); }
public int streamCount() { return refCountByStreamIdMap.size() + refCountByStreamIdAndSessionIdMap.size(); }
public int streamCount() { return refCountByStreamIdMap.size() + refCountByStreamIdAndSessionIdMap.size(); }
/** * Compact the backing arrays by rehashing with a capacity just larger than current size * and giving consideration to the load factor. */ public void compact() { @DoNotSub final int idealCapacity = (int)Math.round(size() * (1.0d / loadFactor)); rehash(findNextPositivePowerOfTwo(Math.max(MIN_CAPACITY, idealCapacity))); }