Skip to content

Commit

Permalink
Tidy up after merge of PR #257.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpt777 committed May 23, 2022
1 parent fae38f9 commit fb7e0c6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -432,8 +432,8 @@ public int computeIfAbsent(final K key, final ToIntFunction<? super K> 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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Integer> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Integer> 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
Expand Down Expand Up @@ -412,8 +396,7 @@ void shouldNotContainInitialValue()
@Test
void shouldCompactMap()
{
final Object2IntCounterMap<Integer> map =
new Object2IntCounterMap<>(2, 0.9f, Integer.MIN_VALUE);
final Object2IntCounterMap<Integer> map = new Object2IntCounterMap<>(2, 0.9f, Integer.MIN_VALUE);
assertEquals(8, map.capacity());
assertEquals(7, map.resizeThreshold());
assertEquals(0, map.size());
Expand Down Expand Up @@ -445,6 +428,7 @@ void shouldCompareKeyCorrectly()
{
final Object2IntCounterMap<CharSequenceKey> map = new Object2IntCounterMap<>(0);
map.put(new CharSequenceKey("abc"), 100);

final CharSequenceKey xyzKey = new CharSequenceKey("xyz");
map.put(xyzKey, 2);

Expand Down

0 comments on commit fb7e0c6

Please sign in to comment.