diff --git a/agrona/src/main/java/org/agrona/collections/Int2NullableObjectHashMap.java b/agrona/src/main/java/org/agrona/collections/Int2NullableObjectHashMap.java index 826884c05..60602856e 100644 --- a/agrona/src/main/java/org/agrona/collections/Int2NullableObjectHashMap.java +++ b/agrona/src/main/java/org/agrona/collections/Int2NullableObjectHashMap.java @@ -29,8 +29,7 @@ public Int2NullableObjectHashMap() } public Int2NullableObjectHashMap( - @DoNotSub final int initialCapacity, - final float loadFactor) + @DoNotSub final int initialCapacity, final float loadFactor) { super(initialCapacity, loadFactor); } @@ -42,9 +41,7 @@ public Int2NullableObjectHashMap( * @param shouldAvoidAllocation should allocation be avoided by caching iterators and map entries. */ public Int2NullableObjectHashMap( - @DoNotSub final int initialCapacity, - final float loadFactor, - final boolean shouldAvoidAllocation) + @DoNotSub final int initialCapacity, final float loadFactor, final boolean shouldAvoidAllocation) { super(initialCapacity, loadFactor, shouldAvoidAllocation); } @@ -59,13 +56,12 @@ public Int2NullableObjectHashMap(final Int2ObjectHashMap mapToCopy) super(mapToCopy); } - @Override protected Object mapNullValue(final Object value) { return value == null ? NullReference.INSTANCE : value; } - @Override + @SuppressWarnings("unchecked") protected V unmapNullValue(final Object value) { return value == NullReference.INSTANCE ? null : (V)value; diff --git a/agrona/src/main/java/org/agrona/collections/Int2ObjectHashMap.java b/agrona/src/main/java/org/agrona/collections/Int2ObjectHashMap.java index 2461c67a3..42c30fc24 100644 --- a/agrona/src/main/java/org/agrona/collections/Int2ObjectHashMap.java +++ b/agrona/src/main/java/org/agrona/collections/Int2ObjectHashMap.java @@ -289,7 +289,7 @@ public V put(final Integer key, final V value) public V put(final int key, final V value) { final V val = (V)mapNullValue(value); - requireNonNull(val, "Value cannot be null"); + requireNonNull(val, "value cannot be null"); V oldValue = null; @DoNotSub final int mask = values.length - 1; @@ -520,6 +520,7 @@ protected Object mapNullValue(final Object value) return value; } + @SuppressWarnings("unchecked") protected V unmapNullValue(final Object value) { return (V)value; @@ -570,7 +571,7 @@ private void increaseCapacity() @DoNotSub final int newCapacity = values.length << 1; if (newCapacity < 0) { - throw new IllegalStateException("Max capacity reached at size=" + size); + throw new IllegalStateException("max capacity reached at size=" + size); } rehash(newCapacity); @@ -756,7 +757,7 @@ public void clear() public boolean contains(final Object o) { final Entry entry = (Entry)o; - final int key = ((Integer)entry.getKey()).intValue(); + final int key = (Integer)entry.getKey(); final V value = getMapped(key); return value != null && value.equals(mapNullValue(entry.getValue())); } @@ -965,7 +966,7 @@ public V getValue() public V setValue(final V value) { final V val = (V)mapNullValue(value); - requireNonNull(val, "Value cannot be null"); + requireNonNull(val, "value cannot be null"); if (!this.isPositionValid) { diff --git a/agrona/src/main/java/org/agrona/collections/Object2NullableObjectHashMap.java b/agrona/src/main/java/org/agrona/collections/Object2NullableObjectHashMap.java index f6cc98208..c33335565 100644 --- a/agrona/src/main/java/org/agrona/collections/Object2NullableObjectHashMap.java +++ b/agrona/src/main/java/org/agrona/collections/Object2NullableObjectHashMap.java @@ -24,9 +24,7 @@ public Object2NullableObjectHashMap() { } - public Object2NullableObjectHashMap( - final int initialCapacity, - final float loadFactor) + public Object2NullableObjectHashMap(final int initialCapacity, final float loadFactor) { super(initialCapacity, loadFactor); } @@ -37,20 +35,17 @@ public Object2NullableObjectHashMap( * @param shouldAvoidAllocation should allocation be avoided by caching iterators and map entries. */ public Object2NullableObjectHashMap( - final int initialCapacity, - final float loadFactor, - final boolean shouldAvoidAllocation) + final int initialCapacity, final float loadFactor, final boolean shouldAvoidAllocation) { super(initialCapacity, loadFactor, shouldAvoidAllocation); } - @Override protected Object mapNullValue(final Object value) { return value == null ? NullReference.INSTANCE : value; } - @Override + @SuppressWarnings("unchecked") protected V unmapNullValue(final Object value) { return value == NullReference.INSTANCE ? null : (V)value; diff --git a/agrona/src/main/java/org/agrona/collections/Object2ObjectHashMap.java b/agrona/src/main/java/org/agrona/collections/Object2ObjectHashMap.java index 3049d5f29..8293b0063 100644 --- a/agrona/src/main/java/org/agrona/collections/Object2ObjectHashMap.java +++ b/agrona/src/main/java/org/agrona/collections/Object2ObjectHashMap.java @@ -474,6 +474,7 @@ protected Object mapNullValue(final Object value) return value; } + @SuppressWarnings("unchecked") protected V unmapNullValue(final Object value) { return (V)value; diff --git a/agrona/src/test/java/org/agrona/collections/Int2ObjectHashMapTest.java b/agrona/src/test/java/org/agrona/collections/Int2ObjectHashMapTest.java index 1b6c76ea9..e26514a71 100644 --- a/agrona/src/test/java/org/agrona/collections/Int2ObjectHashMapTest.java +++ b/agrona/src/test/java/org/agrona/collections/Int2ObjectHashMapTest.java @@ -223,6 +223,7 @@ public void shouldIterateValues() for (final String s : intToObjectMap.values()) { + //noinspection UseBulkOperation copyToSet.add(s); } @@ -273,6 +274,7 @@ private void assertIterateKeys(final Collection initialSet) final Collection copyToSet = new HashSet<>(); for (final Integer aInteger : intToObjectMap.keySet()) { + //noinspection UseBulkOperation copyToSet.add(aInteger); } @@ -385,13 +387,11 @@ public void shouldAllowNullValuesWithNullMapping() { private final Object nullRef = new Object(); - @Override protected Object mapNullValue(final Object value) { return value == null ? nullRef : value; } - @Override protected String unmapNullValue(final Object value) { return value == nullRef ? null : (String)value;