public int decRefToStream(final int streamId) { final int count = refCountByStreamIdMap.decrementAndGet(streamId); if (-1 == count) { refCountByStreamIdMap.remove(streamId); throw new IllegalStateException("could not find stream Id to decrement: " + streamId); } return count; }
@Test public void removeShouldReturnMissing() { assertEquals(INITIAL_VALUE, map.remove(1)); }
@Test public void shouldOnlyRemoveTheSpecifiedEntry() { IntStream.range(1, 8).forEach((i) -> map.put(i, i * 2)); map.remove(5); IntStream .range(1, 8) .filter((i) -> i != 5L) .forEach((i) -> { assertTrue(map.containsKey(i)); assertTrue(map.containsValue(2 * i)); }); }
@Test public void removeShouldReturnValueRemoved() { map.put(1, 2); assertEquals(2, map.remove(1)); }
@Test public void removeShouldRemoveEntry() { map.put(1, 2); map.remove(1); assertTrue(map.isEmpty()); assertFalse(map.containsKey(1)); assertFalse(map.containsValue(2)); }
@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 decRefToStream(final int streamId) { final int count = refCountByStreamIdMap.decrementAndGet(streamId); if (-1 == count) { refCountByStreamIdMap.remove(streamId); throw new IllegalStateException("could not find stream Id to decrement: " + streamId); } return count; }
public int decRefToStream(final int streamId) { final int count = refCountByStreamIdMap.decrementAndGet(streamId); if (-1 == count) { refCountByStreamIdMap.remove(streamId); throw new IllegalStateException("could not find stream Id to decrement: " + streamId); } return count; }