diff --git a/agrona/src/main/java/org/agrona/collections/Object2IntCounterMap.java b/agrona/src/main/java/org/agrona/collections/Object2IntCounterMap.java index 9fdfc7acf..90eaa3220 100644 --- a/agrona/src/main/java/org/agrona/collections/Object2IntCounterMap.java +++ b/agrona/src/main/java/org/agrona/collections/Object2IntCounterMap.java @@ -123,7 +123,7 @@ public float loadFactor() /** * The current size of the map which at not at {@link #initialValue()}. * - * @return map size, counters at {@link #initialValue()} are not counted + * @return map size, counters at {@link #initialValue()} are not counted. */ @DoNotSub public int size() { @@ -143,7 +143,7 @@ public boolean isEmpty() /** * Get the value of a counter associated with a key or {@link #initialValue()} if not found. * - * @param key lookup key + * @param key lookup key. * @return counter value associated with key or {@link #initialValue()} if not found. */ public int get(final K key) @@ -171,10 +171,10 @@ public int get(final K key) /** * Put the value for a key in the map. * - * @param key lookup key - * @param value new value, must not be initialValue - * @return current counter value associated with key, or {@link #initialValue()} if none found - * @throws IllegalArgumentException if value is {@link #initialValue()} + * @param key lookup key. + * @param value new value, must not be initialValue. + * @return current counter value associated with key, or {@link #initialValue()} if none found. + * @throws IllegalArgumentException if value is {@link #initialValue()}. */ public int put(final K key, final int value) { @@ -241,8 +241,8 @@ public int decrementAndGet(final K key) * current value and associate key with {@link #initialValue()} + amount unless amount is 0, in which case map * remains unchanged. * - * @param key new or existing - * @param amount to be added + * @param key new or existing. + * @param amount to be added. * @return the new value associated with the specified key, or * {@link #initialValue()} + amount if there was no mapping for the key. */ @@ -278,8 +278,8 @@ public int getAndDecrement(final K key) * current value and associate key with {@link #initialValue()} + amount unless amount is 0, in which case map * remains unchanged. * - * @param key new or existing - * @param amount to be added + * @param key new or existing. + * @param amount to be added. * @return the previous value associated with the specified key, or * {@link #initialValue()} if there was no mapping for the key. */ @@ -432,8 +432,8 @@ public int computeIfAbsent(final K key, final ToIntFunction mappingFu /** * Remove a counter value for a given key. * - * @param key to be removed - * @return old value for key + * @param key to be removed. + * @return old value for key. */ public int remove(final K key) { diff --git a/agrona/src/test/java/org/agrona/collections/Int2IntCounterMapTest.java b/agrona/src/test/java/org/agrona/collections/Int2IntCounterMapTest.java index 67158499f..9ee6060a8 100644 --- a/agrona/src/test/java/org/agrona/collections/Int2IntCounterMapTest.java +++ b/agrona/src/test/java/org/agrona/collections/Int2IntCounterMapTest.java @@ -18,8 +18,6 @@ import org.junit.jupiter.api.Test; import org.mockito.InOrder; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.ThreadLocalRandom; import java.util.function.IntUnaryOperator; import java.util.stream.IntStream; @@ -243,27 +241,13 @@ void sizeShouldReturnNumberOfEntries() @Test void shouldNotSupportLoadFactorOfGreaterThanOne() { - assertThrows(IllegalArgumentException.class, () -> new Int2IntHashMap(4, 2, 0)); + assertThrows(IllegalArgumentException.class, () -> new Int2IntCounterMap(4, 2, 0)); } @Test void shouldNotSupportLoadFactorOfOne() { - assertThrows(IllegalArgumentException.class, () -> new Int2IntHashMap(4, 1, 0)); - } - - @Test - void correctSizeAfterRehash() - { - final Int2IntHashMap map = new Int2IntHashMap(16, 0.6f, -1); - - IntStream.range(1, 17).forEach((i) -> map.put(i, i)); - assertEquals(16, map.size(), "Map has correct size"); - - final List keys = new ArrayList<>(map.keySet()); - keys.forEach(map::remove); - - assertTrue(map.isEmpty(), "Map isn't empty"); + assertThrows(IllegalArgumentException.class, () -> new Int2IntCounterMap(4, 1, 0)); } @Test diff --git a/agrona/src/test/java/org/agrona/collections/Object2IntCounterMapTest.java b/agrona/src/test/java/org/agrona/collections/Object2IntCounterMapTest.java index 0d47c2c59..3121ad290 100644 --- a/agrona/src/test/java/org/agrona/collections/Object2IntCounterMapTest.java +++ b/agrona/src/test/java/org/agrona/collections/Object2IntCounterMapTest.java @@ -18,8 +18,6 @@ import org.junit.jupiter.api.Test; import org.mockito.InOrder; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.ThreadLocalRandom; import java.util.function.ObjIntConsumer; import java.util.function.ToIntFunction; @@ -245,27 +243,13 @@ void sizeShouldReturnNumberOfEntries() @Test void shouldNotSupportLoadFactorOfGreaterThanOne() { - assertThrows(IllegalArgumentException.class, () -> new Int2IntHashMap(4, 2, 0)); + assertThrows(IllegalArgumentException.class, () -> new Object2IntCounterMap<>(4, 2, 0)); } @Test void shouldNotSupportLoadFactorOfOne() { - assertThrows(IllegalArgumentException.class, () -> new Int2IntHashMap(4, 1, 0)); - } - - @Test - void correctSizeAfterRehash() - { - final Int2IntHashMap map = new Int2IntHashMap(16, 0.6f, -1); - - IntStream.range(1, 17).forEach((i) -> map.put(i, i)); - assertEquals(16, map.size(), "Map has correct size"); - - final List keys = new ArrayList<>(map.keySet()); - keys.forEach(map::remove); - - assertTrue(map.isEmpty(), "Map isn't empty"); + assertThrows(IllegalArgumentException.class, () -> new Object2IntCounterMap<>(4, 1, 0)); } @Test @@ -412,8 +396,7 @@ void shouldNotContainInitialValue() @Test void shouldCompactMap() { - final Object2IntCounterMap map = - new Object2IntCounterMap<>(2, 0.9f, Integer.MIN_VALUE); + final Object2IntCounterMap map = new Object2IntCounterMap<>(2, 0.9f, Integer.MIN_VALUE); assertEquals(8, map.capacity()); assertEquals(7, map.resizeThreshold()); assertEquals(0, map.size()); @@ -445,6 +428,7 @@ void shouldCompareKeyCorrectly() { final Object2IntCounterMap map = new Object2IntCounterMap<>(0); map.put(new CharSequenceKey("abc"), 100); + final CharSequenceKey xyzKey = new CharSequenceKey("xyz"); map.put(xyzKey, 2);