diff --git a/src/dorkbox/util/collections/Array.java b/src/dorkbox/util/collections/Array.java index d5dfa82..56291bf 100644 --- a/src/dorkbox/util/collections/Array.java +++ b/src/dorkbox/util/collections/Array.java @@ -28,6 +28,7 @@ import dorkbox.util.RandomUtil; /** A resizable, ordered or unordered array of objects. If unordered, this class avoids a memory copy when removing elements (the * last element is moved to the removed element's position). * @author Nathan Sweet */ +@SuppressWarnings({"unchecked", "rawtypes", "SuspiciousSystemArraycopy", "unused", "NullableProblems", "DuplicatedCode"}) public class Array implements Iterable { /** Provides direct access to the underlying array. If the Array's generic type is not Object, this field may only be accessed * if the {@link Array#Array(boolean, int, Class)} constructor was used. */ @@ -261,7 +262,7 @@ public class Array implements Iterable { public T removeIndex (int index) { if (index >= size) throw new IndexOutOfBoundsException("index can't be >= size: " + index + " >= " + size); T[] items = this.items; - T value = (T)items[index]; + T value = items[index]; size--; if (ordered) System.arraycopy(items, index + 1, items, index, size - index); @@ -448,7 +449,8 @@ public class Array implements Iterable { /** Returns an iterator for the items in the array. Remove is supported. Note that the same iterator instance is returned each * time this method is called. Use the {@link ArrayIterator} constructor for nested or multithreaded iteration. */ - public Iterator iterator () { + @Override + public Iterator iterator () { if (iterable == null) iterable = new ArrayIterable(this); return iterable.iterator(); } @@ -492,7 +494,8 @@ public class Array implements Iterable { return result; } - public int hashCode () { + @Override + public int hashCode () { if (!ordered) return super.hashCode(); Object[] items = this.items; int h = 1; @@ -504,7 +507,8 @@ public class Array implements Iterable { return h; } - public boolean equals (Object object) { + @Override + public boolean equals (Object object) { if (object == this) return true; if (!ordered) return false; if (!(object instanceof Array)) return false; @@ -522,7 +526,8 @@ public class Array implements Iterable { return true; } - public String toString () { + @Override + public String toString () { if (size == 0) return "[]"; T[] items = this.items; StringBuilder buffer = new StringBuilder(32); @@ -563,7 +568,8 @@ public class Array implements Iterable { return new Array(array); } - static public class ArrayIterator implements Iterator, Iterable { + @SuppressWarnings("NullableProblems") + static public class ArrayIterator implements Iterator, Iterable { private final Array array; private final boolean allowRemove; int index; @@ -580,7 +586,8 @@ public class Array implements Iterable { this.allowRemove = allowRemove; } - public boolean hasNext () { + @Override + public boolean hasNext () { if (!valid) { // System.out.println(iterable.lastAcquire); throw new RuntimeException("#iterator() cannot be used nested."); @@ -588,7 +595,8 @@ public class Array implements Iterable { return index < array.size; } - public T next () { + @Override + public T next () { if (index >= array.size) throw new NoSuchElementException(String.valueOf(index)); if (!valid) { // System.out.println(iterable.lastAcquire); @@ -597,7 +605,8 @@ public class Array implements Iterable { return array.items[index++]; } - public void remove () { + @Override + public void remove () { if (!allowRemove) throw new RuntimeException("Remove not allowed."); index--; array.removeIndex(index); @@ -607,12 +616,14 @@ public class Array implements Iterable { index = 0; } - public Iterator iterator () { + @Override + public Iterator iterator () { return this; } } - static public class ArrayIterable implements Iterable { + @SuppressWarnings({"unchecked", "NullableProblems"}) + static public class ArrayIterable implements Iterable { private final Array array; private final boolean allowRemove; private ArrayIterator iterator1, iterator2; @@ -628,7 +639,8 @@ public class Array implements Iterable { this.allowRemove = allowRemove; } - public Iterator iterator () { + @Override + public Iterator iterator () { // lastAcquire.getBuffer().setLength(0); // new Throwable().printStackTrace(new java.io.PrintWriter(lastAcquire)); if (iterator1 == null) { diff --git a/src/dorkbox/util/collections/ConcurrentIterator.java b/src/dorkbox/util/collections/ConcurrentIterator.java index 9a9c6da..124e962 100644 --- a/src/dorkbox/util/collections/ConcurrentIterator.java +++ b/src/dorkbox/util/collections/ConcurrentIterator.java @@ -26,6 +26,7 @@ import dorkbox.util.Property; /** * @author dorkbox, llc */ +@SuppressWarnings("unchecked") public class ConcurrentIterator { /** diff --git a/src/dorkbox/util/collections/IdentityMap.java b/src/dorkbox/util/collections/IdentityMap.java index 99ee9c6..e12e865 100644 --- a/src/dorkbox/util/collections/IdentityMap.java +++ b/src/dorkbox/util/collections/IdentityMap.java @@ -32,6 +32,7 @@ import dorkbox.util.RandomUtil; * depending on hash collisions. Load factors greater than 0.91 greatly increase the chances the map will have to rehash to the * next higher POT size. * @author Nathan Sweet */ +@SuppressWarnings({"unchecked", "rawtypes", "NullableProblems"}) public class IdentityMap implements Iterable> { private static final int PRIME1 = 0xbe1f14b1; private static final int PRIME2 = 0xb4b82e39; @@ -510,7 +511,8 @@ public class IdentityMap implements Iterable> { return (h ^ h >>> hashShift) & mask; } - public int hashCode () { + @Override + public int hashCode () { int h = 0; K[] keyTable = this.keyTable; V[] valueTable = this.valueTable; @@ -528,7 +530,8 @@ public class IdentityMap implements Iterable> { return h; } - public boolean equals (Object obj) { + @Override + public boolean equals (Object obj) { if (obj == this) return true; if (!(obj instanceof IdentityMap)) return false; IdentityMap other = (IdentityMap) obj; @@ -553,7 +556,8 @@ public class IdentityMap implements Iterable> { return true; } - public String toString () { + @Override + public String toString () { if (size == 0) return "[]"; StringBuilder buffer = new StringBuilder(32); buffer.append('['); @@ -580,7 +584,8 @@ public class IdentityMap implements Iterable> { return buffer.toString(); } - public Iterator> iterator () { + @Override + public Iterator> iterator () { return entries(); } @@ -645,12 +650,14 @@ public class IdentityMap implements Iterable> { public K key; public V value; - public String toString () { + @Override + public String toString () { return key + "=" + value; } } - static private abstract class MapIterator implements Iterable, Iterator { + @SuppressWarnings("DuplicatedCode") + static private abstract class MapIterator implements Iterable, Iterator { public boolean hasNext; final IdentityMap map; @@ -679,7 +686,8 @@ public class IdentityMap implements Iterable> { } } - public void remove () { + @Override + public void remove () { if (currentIndex < 0) throw new IllegalStateException("next must be called before remove."); if (currentIndex >= map.capacity) { map.removeStashIndex(currentIndex); @@ -694,7 +702,8 @@ public class IdentityMap implements Iterable> { } } - static public class Entries extends MapIterator> { + @SuppressWarnings({"NullableProblems", "DuplicatedCode", "unchecked", "FieldMayBeFinal"}) + static public class Entries extends MapIterator> { private Entry entry = new Entry(); public Entries (IdentityMap map) { @@ -702,7 +711,8 @@ public class IdentityMap implements Iterable> { } /** Note the same entry instance is returned each time this method is called. */ - public Entry next () { + @Override + public Entry next () { if (!hasNext) throw new NoSuchElementException(); if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); K[] keyTable = map.keyTable; @@ -713,27 +723,32 @@ public class IdentityMap implements Iterable> { return entry; } - public boolean hasNext () { + @Override + public boolean hasNext () { if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); return hasNext; } - public Iterator> iterator () { + @Override + public Iterator> iterator () { return this; } } - static public class Values extends MapIterator { + @SuppressWarnings({"rawtypes", "NullableProblems"}) + static public class Values extends MapIterator { public Values (IdentityMap map) { super((IdentityMap)map); } - public boolean hasNext () { + @Override + public boolean hasNext () { if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); return hasNext; } - public V next () { + @Override + public V next () { if (!hasNext) throw new NoSuchElementException(); if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); V value = map.valueTable[nextIndex]; @@ -742,7 +757,8 @@ public class IdentityMap implements Iterable> { return value; } - public Iterator iterator () { + @Override + public Iterator iterator () { return this; } @@ -761,17 +777,20 @@ public class IdentityMap implements Iterable> { } } - static public class Keys extends MapIterator { + @SuppressWarnings("unchecked") + static public class Keys extends MapIterator { public Keys (IdentityMap map) { super((IdentityMap)map); } - public boolean hasNext () { + @Override + public boolean hasNext () { if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); return hasNext; } - public K next () { + @Override + public K next () { if (!hasNext) throw new NoSuchElementException(); if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); K key = map.keyTable[nextIndex]; @@ -780,7 +799,8 @@ public class IdentityMap implements Iterable> { return key; } - public Iterator iterator () { + @Override + public Iterator iterator () { return this; } diff --git a/src/dorkbox/util/collections/IntMap.java b/src/dorkbox/util/collections/IntMap.java index f1e7ff7..f52b8b8 100644 --- a/src/dorkbox/util/collections/IntMap.java +++ b/src/dorkbox/util/collections/IntMap.java @@ -31,6 +31,7 @@ import dorkbox.util.RandomUtil; * depending on hash collisions. Load factors greater than 0.91 greatly increase the chances the map will have to rehash to the * next higher POT size. * @author Nathan Sweet */ +@SuppressWarnings({"unchecked", "rawtypes"}) public class IntMap implements Iterable> { private static final int PRIME1 = 0xbe1f14b1; private static final int PRIME2 = 0xb4b82e39; @@ -556,6 +557,7 @@ public class IntMap implements Iterable> { return (h ^ h >>> hashShift) & mask; } + @Override public int hashCode () { int h = 0; if (hasZeroValue && zeroValue != null) { @@ -577,6 +579,7 @@ public class IntMap implements Iterable> { return h; } + @Override public boolean equals (Object obj) { if (obj == this) return true; if (!(obj instanceof IntMap)) return false; @@ -606,6 +609,7 @@ public class IntMap implements Iterable> { return true; } + @Override public String toString () { if (size == 0) return "[]"; StringBuilder buffer = new StringBuilder(32); @@ -638,6 +642,7 @@ public class IntMap implements Iterable> { return buffer.toString(); } + @Override public Iterator> iterator () { return entries(); } @@ -703,6 +708,7 @@ public class IntMap implements Iterable> { public int key; public V value; + @Override public String toString () { return key + "=" + value; } @@ -762,6 +768,7 @@ public class IntMap implements Iterable> { } } + @SuppressWarnings("rawtypes") static public class Entries extends MapIterator implements Iterable>, Iterator> { private Entry entry = new Entry(); @@ -770,6 +777,7 @@ public class IntMap implements Iterable> { } /** Note the same entry instance is returned each time this method is called. */ + @Override public Entry next () { if (!hasNext) throw new NoSuchElementException(); if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); @@ -786,30 +794,36 @@ public class IntMap implements Iterable> { return entry; } + @Override public boolean hasNext () { if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); return hasNext; } + @Override public Iterator> iterator () { return this; } + @Override public void remove () { super.remove(); } } + @SuppressWarnings("unchecked") static public class Values extends MapIterator implements Iterable, Iterator { public Values (IntMap map) { super(map); } + @Override public boolean hasNext () { if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); return hasNext; } + @Override public V next () { if (!hasNext) throw new NoSuchElementException(); if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); @@ -823,6 +837,7 @@ public class IntMap implements Iterable> { return value; } + @Override public Iterator iterator () { return this; } @@ -835,12 +850,15 @@ public class IntMap implements Iterable> { return array; } + @Override public void remove () { super.remove(); } } + @SuppressWarnings("unchecked") static public class Keys extends MapIterator { + @SuppressWarnings("rawtypes") public Keys (IntMap map) { super(map); } diff --git a/src/dorkbox/util/collections/LockFreeHashMap.java b/src/dorkbox/util/collections/LockFreeHashMap.java index 53f5679..4b8abd0 100644 --- a/src/dorkbox/util/collections/LockFreeHashMap.java +++ b/src/dorkbox/util/collections/LockFreeHashMap.java @@ -16,7 +16,11 @@ package dorkbox.util.collections; import java.io.Serializable; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; /** @@ -137,6 +141,7 @@ class LockFreeHashMap implements Map, Cloneable, Serializable { .containsValue(value); } + @SuppressWarnings("unchecked") @Override public V get(final Object key) { diff --git a/src/dorkbox/util/collections/LockFreeIntBiMap.java b/src/dorkbox/util/collections/LockFreeIntBiMap.java index c39a37c..07475f0 100644 --- a/src/dorkbox/util/collections/LockFreeIntBiMap.java +++ b/src/dorkbox/util/collections/LockFreeIntBiMap.java @@ -373,6 +373,7 @@ class LockFreeIntBiMap { * Returns an iterator for the values in the map. Remove is supported. Note that the same iterator instance is returned each * time this method is called. Use the {@link Entries} constructor for nested or multithreaded iteration. */ + @SuppressWarnings("unchecked") public Values values() { return forwardREF.get(this) diff --git a/src/dorkbox/util/collections/LockFreeObjectMap.java b/src/dorkbox/util/collections/LockFreeObjectMap.java index 4b76bd2..aa557a9 100644 --- a/src/dorkbox/util/collections/LockFreeObjectMap.java +++ b/src/dorkbox/util/collections/LockFreeObjectMap.java @@ -37,6 +37,7 @@ import com.esotericsoftware.kryo.util.ObjectMap.Values; *

* This data structure is for many-read/few-write scenarios */ +@SuppressWarnings("unchecked") public final class LockFreeObjectMap implements Cloneable, Serializable { // Recommended for best performance while adhering to the "single writer principle". Must be static-final diff --git a/src/dorkbox/util/collections/LockFreeSet.java b/src/dorkbox/util/collections/LockFreeSet.java index 319810a..783e097 100644 --- a/src/dorkbox/util/collections/LockFreeSet.java +++ b/src/dorkbox/util/collections/LockFreeSet.java @@ -15,7 +15,11 @@ */ package dorkbox.util.collections; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; /** @@ -31,6 +35,7 @@ import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; *

* This data structure is for many-read/few-write scenarios */ +@SuppressWarnings("unchecked") public final class LockFreeSet implements Set, Cloneable, java.io.Serializable { // Recommended for best performance while adhering to the "single writer principle". Must be static-final diff --git a/src/dorkbox/util/collections/LongMap.java b/src/dorkbox/util/collections/LongMap.java index c538eee..634a879 100644 --- a/src/dorkbox/util/collections/LongMap.java +++ b/src/dorkbox/util/collections/LongMap.java @@ -31,6 +31,7 @@ import dorkbox.util.RandomUtil; * depending on hash collisions. Load factors greater than 0.91 greatly increase the chances the map will have to rehash to the * next higher POT size. * @author Nathan Sweet */ +@SuppressWarnings({"NullableProblems", "rawtypes", "unchecked"}) public class LongMap implements Iterable> { private static final int PRIME1 = 0xbe1f14b1; private static final int PRIME2 = 0xb4b82e39; @@ -553,7 +554,8 @@ public class LongMap implements Iterable> { return (int)((h ^ h >>> hashShift) & mask); } - public int hashCode () { + @Override + public int hashCode () { int h = 0; if (hasZeroValue && zeroValue != null) { h += zeroValue.hashCode(); @@ -574,7 +576,8 @@ public class LongMap implements Iterable> { return h; } - public boolean equals (Object obj) { + @Override + public boolean equals (Object obj) { if (obj == this) return true; if (!(obj instanceof LongMap)) return false; LongMap other = (LongMap)obj; @@ -603,7 +606,8 @@ public class LongMap implements Iterable> { return true; } - public String toString () { + @Override + public String toString () { if (size == 0) return "[]"; StringBuilder buffer = new StringBuilder(32); buffer.append('['); @@ -630,7 +634,8 @@ public class LongMap implements Iterable> { return buffer.toString(); } - public Iterator> iterator () { + @Override + public Iterator> iterator () { return entries(); } @@ -695,7 +700,8 @@ public class LongMap implements Iterable> { public long key; public V value; - public String toString () { + @Override + public String toString () { return key + "=" + value; } } @@ -754,7 +760,8 @@ public class LongMap implements Iterable> { } } - static public class Entries extends MapIterator implements Iterable>, Iterator> { + @SuppressWarnings("NullableProblems") + static public class Entries extends MapIterator implements Iterable>, Iterator> { private Entry entry = new Entry(); public Entries (LongMap map) { @@ -762,7 +769,8 @@ public class LongMap implements Iterable> { } /** Note the same entry instance is returned each time this method is called. */ - public Entry next () { + @Override + public Entry next () { if (!hasNext) throw new NoSuchElementException(); if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); long[] keyTable = map.keyTable; @@ -778,31 +786,37 @@ public class LongMap implements Iterable> { return entry; } - public boolean hasNext () { + @Override + public boolean hasNext () { if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); return hasNext; } - public Iterator> iterator () { + @Override + public Iterator> iterator () { return this; } - public void remove () { + @Override + public void remove () { super.remove(); } } - static public class Values extends MapIterator implements Iterable, Iterator { + @SuppressWarnings("rawtypes") + static public class Values extends MapIterator implements Iterable, Iterator { public Values (LongMap map) { super(map); } - public boolean hasNext () { + @Override + public boolean hasNext () { if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); return hasNext; } - public V next () { + @Override + public V next () { if (!hasNext) throw new NoSuchElementException(); if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); V value; @@ -815,7 +829,8 @@ public class LongMap implements Iterable> { return value; } - public Iterator iterator () { + @Override + public Iterator iterator () { return this; } @@ -827,12 +842,14 @@ public class LongMap implements Iterable> { return array; } - public void remove () { + @Override + public void remove () { super.remove(); } } - static public class Keys extends MapIterator { + @SuppressWarnings("rawtypes") + static public class Keys extends MapIterator { public Keys (LongMap map) { super(map); } diff --git a/src/dorkbox/util/collections/ObjectFloatMap.java b/src/dorkbox/util/collections/ObjectFloatMap.java index f1275c1..294e333 100644 --- a/src/dorkbox/util/collections/ObjectFloatMap.java +++ b/src/dorkbox/util/collections/ObjectFloatMap.java @@ -32,6 +32,7 @@ import dorkbox.util.RandomUtil; * depending on hash collisions. Load factors greater than 0.91 greatly increase the chances the map will have to rehash to the * next higher POT size. * @author Nathan Sweet */ +@SuppressWarnings({"unchecked", "NullableProblems", "rawtypes"}) public class ObjectFloatMap implements Iterable> { private static final int PRIME1 = 0xbe1f14b1; private static final int PRIME2 = 0xb4b82e39; @@ -66,7 +67,8 @@ public class ObjectFloatMap implements Iterable> { /** Creates a new map with the specified initial capacity and load factor. This map will hold initialCapacity items before * growing the backing table. * @param initialCapacity If not a power of two, it is increased to the next nearest power of two. */ - public ObjectFloatMap (int initialCapacity, float loadFactor) { + @SuppressWarnings("unchecked") + public ObjectFloatMap (int initialCapacity, float loadFactor) { if (initialCapacity < 0) throw new IllegalArgumentException("initialCapacity must be >= 0: " + initialCapacity); initialCapacity = MathUtil.nextPowerOfTwo((int)Math.ceil(initialCapacity / loadFactor)); if (initialCapacity > 1 << 30) throw new IllegalArgumentException("initialCapacity is too large: " + initialCapacity); @@ -500,7 +502,8 @@ public class ObjectFloatMap implements Iterable> { return (h ^ h >>> hashShift) & mask; } - public int hashCode () { + @Override + public int hashCode () { int h = 0; K[] keyTable = this.keyTable; float[] valueTable = this.valueTable; @@ -516,7 +519,8 @@ public class ObjectFloatMap implements Iterable> { return h; } - public boolean equals (Object obj) { + @Override + public boolean equals (Object obj) { if (obj == this) return true; if (!(obj instanceof ObjectFloatMap)) return false; ObjectFloatMap other = (ObjectFloatMap) obj; @@ -535,7 +539,8 @@ public class ObjectFloatMap implements Iterable> { return true; } - public String toString () { + @Override + public String toString () { if (size == 0) return "{}"; StringBuilder buffer = new StringBuilder(32); buffer.append('{'); @@ -562,7 +567,8 @@ public class ObjectFloatMap implements Iterable> { return buffer.toString(); } - public Entries iterator () { + @Override + public Entries iterator () { return entries(); } @@ -627,7 +633,8 @@ public class ObjectFloatMap implements Iterable> { public K key; public float value; - public String toString () { + @Override + public String toString () { return key + "=" + value; } } @@ -683,7 +690,8 @@ public class ObjectFloatMap implements Iterable> { } /** Note the same entry instance is returned each time this method is called. */ - public Entry next () { + @Override + public Entry next () { if (!hasNext) throw new NoSuchElementException(); if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); K[] keyTable = map.keyTable; @@ -694,16 +702,19 @@ public class ObjectFloatMap implements Iterable> { return entry; } - public boolean hasNext () { + @Override + public boolean hasNext () { if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); return hasNext; } - public Entries iterator () { + @Override + public Entries iterator () { return this; } - public void remove () { + @Override + public void remove () { super.remove(); } } @@ -736,17 +747,20 @@ public class ObjectFloatMap implements Iterable> { } } - static public class Keys extends MapIterator implements Iterable, Iterator { + @SuppressWarnings("unchecked") + static public class Keys extends MapIterator implements Iterable, Iterator { public Keys (ObjectFloatMap map) { super((ObjectFloatMap)map); } - public boolean hasNext () { + @Override + public boolean hasNext () { if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); return hasNext; } - public K next () { + @Override + public K next () { if (!hasNext) throw new NoSuchElementException(); if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); K key = map.keyTable[nextIndex]; @@ -755,7 +769,8 @@ public class ObjectFloatMap implements Iterable> { return key; } - public Keys iterator () { + @Override + public Keys iterator () { return this; } @@ -774,7 +789,8 @@ public class ObjectFloatMap implements Iterable> { return array; } - public void remove () { + @Override + public void remove () { super.remove(); } } diff --git a/src/dorkbox/util/collections/ObjectIntMap.java b/src/dorkbox/util/collections/ObjectIntMap.java index 2352a09..c2b81a0 100644 --- a/src/dorkbox/util/collections/ObjectIntMap.java +++ b/src/dorkbox/util/collections/ObjectIntMap.java @@ -32,6 +32,7 @@ import dorkbox.util.RandomUtil; * depending on hash collisions. Load factors greater than 0.91 greatly increase the chances the map will have to rehash to the * next higher POT size. * @author Nathan Sweet */ +@SuppressWarnings({"unchecked", "NullableProblems"}) public class ObjectIntMap implements Iterable> { private static final int PRIME1 = 0xbe1f14b1; private static final int PRIME2 = 0xb4b82e39; @@ -501,6 +502,7 @@ public class ObjectIntMap implements Iterable> { return (h ^ h >>> hashShift) & mask; } + @Override public int hashCode () { int h = 0; K[] keyTable = this.keyTable; @@ -517,6 +519,7 @@ public class ObjectIntMap implements Iterable> { return h; } + @Override public boolean equals (Object obj) { if (obj == this) return true; if (!(obj instanceof ObjectIntMap)) return false; @@ -536,6 +539,7 @@ public class ObjectIntMap implements Iterable> { return true; } + @Override public String toString () { if (size == 0) return "{}"; StringBuilder buffer = new StringBuilder(32); @@ -563,6 +567,7 @@ public class ObjectIntMap implements Iterable> { return buffer.toString(); } + @Override public Entries iterator () { return entries(); } @@ -628,6 +633,7 @@ public class ObjectIntMap implements Iterable> { public K key; public int value; + @Override public String toString () { return key + "=" + value; } @@ -684,6 +690,7 @@ public class ObjectIntMap implements Iterable> { } /** Note the same entry instance is returned each time this method is called. */ + @Override public Entry next () { if (!hasNext) throw new NoSuchElementException(); if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); @@ -695,15 +702,18 @@ public class ObjectIntMap implements Iterable> { return entry; } + @Override public boolean hasNext () { if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); return hasNext; } + @Override public Entries iterator () { return this; } + @Override public void remove () { super.remove(); } @@ -742,11 +752,13 @@ public class ObjectIntMap implements Iterable> { super((ObjectIntMap)map); } + @Override public boolean hasNext () { if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); return hasNext; } + @Override public K next () { if (!hasNext) throw new NoSuchElementException(); if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); @@ -756,6 +768,7 @@ public class ObjectIntMap implements Iterable> { return key; } + @Override public Keys iterator () { return this; } @@ -775,6 +788,7 @@ public class ObjectIntMap implements Iterable> { return array; } + @Override public void remove () { super.remove(); } diff --git a/src/dorkbox/util/collections/ObjectMap.java b/src/dorkbox/util/collections/ObjectMap.java index 829c06e..d100fe3 100644 --- a/src/dorkbox/util/collections/ObjectMap.java +++ b/src/dorkbox/util/collections/ObjectMap.java @@ -34,6 +34,7 @@ import dorkbox.util.RandomUtil; * Iteration can be very slow for a map with a large capacity. {@link #clear(int)} and {@link #shrink(int)} can be used to reduce * the capacity. {@link OrderedMap} provides much faster iteration. * @author Nathan Sweet */ +@SuppressWarnings("unchecked") public class ObjectMap implements Iterable> { private static final int PRIME1 = 0xbe1f14b1; private static final int PRIME2 = 0xb4b82e39; @@ -722,7 +723,8 @@ public class ObjectMap implements Iterable> { } } - static public class Entries extends MapIterator> { + @SuppressWarnings("NullableProblems") + static public class Entries extends MapIterator> { Entry entry = new Entry(); public Entries (ObjectMap map) { @@ -754,7 +756,7 @@ public class ObjectMap implements Iterable> { } } - @SuppressWarnings("NullableProblems") + @SuppressWarnings({"NullableProblems", "unchecked", "rawtypes"}) static public class Values extends MapIterator { public Values (ObjectMap map) { super((ObjectMap)map); @@ -794,7 +796,8 @@ public class ObjectMap implements Iterable> { } } - static public class Keys extends MapIterator { + @SuppressWarnings({"unchecked", "NullableProblems", "rawtypes"}) + static public class Keys extends MapIterator { public Keys (ObjectMap map) { super((ObjectMap)map); } diff --git a/src/dorkbox/util/collections/ObjectSet.java b/src/dorkbox/util/collections/ObjectSet.java index 89e22c4..5de896f 100644 --- a/src/dorkbox/util/collections/ObjectSet.java +++ b/src/dorkbox/util/collections/ObjectSet.java @@ -34,6 +34,7 @@ import dorkbox.util.RandomUtil; * Iteration can be very slow for a set with a large capacity. {@link #clear(int)} and {@link #shrink(int)} can be used to reduce * the capacity. {@link OrderedSet} provides much faster iteration. * @author Nathan Sweet */ +@SuppressWarnings({"unchecked", "rawtypes", "NullableProblems", "SuspiciousSystemArraycopy"}) public class ObjectSet implements Iterable { private static final int PRIME1 = 0xbe1f14b1; private static final int PRIME2 = 0xb4b82e39; @@ -440,14 +441,16 @@ public class ObjectSet implements Iterable { return (h ^ h >>> hashShift) & mask; } - public int hashCode () { + @Override + public int hashCode () { int h = 0; for (int i = 0, n = capacity + stashSize; i < n; i++) if (keyTable[i] != null) h += keyTable[i].hashCode(); return h; } - public boolean equals (Object obj) { + @Override + public boolean equals (Object obj) { if (!(obj instanceof ObjectSet)) return false; ObjectSet other = (ObjectSet)obj; if (other.size != size) return false; @@ -457,7 +460,8 @@ public class ObjectSet implements Iterable { return true; } - public String toString () { + @Override + public String toString () { return '{' + toString(", ") + '}'; } @@ -483,7 +487,8 @@ public class ObjectSet implements Iterable { /** Returns an iterator for the keys in the set. Remove is supported. Note that the same iterator instance is returned each * time this method is called. Use the {@link ObjectSetIterator} constructor for nested or multithreaded iteration. */ - public ObjectSetIterator iterator () { + @Override + public ObjectSetIterator iterator () { if (iterator1 == null) { iterator1 = new ObjectSetIterator(this); iterator2 = new ObjectSetIterator(this); @@ -535,7 +540,8 @@ public class ObjectSet implements Iterable { } } - public void remove () { + @Override + public void remove () { if (currentIndex < 0) throw new IllegalStateException("next must be called before remove."); if (currentIndex >= set.capacity) { set.removeStashIndex(currentIndex); @@ -548,12 +554,14 @@ public class ObjectSet implements Iterable { set.size--; } - public boolean hasNext () { + @Override + public boolean hasNext () { if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); return hasNext; } - public K next () { + @Override + public K next () { if (!hasNext) throw new NoSuchElementException(); if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); K key = set.keyTable[nextIndex]; @@ -562,7 +570,8 @@ public class ObjectSet implements Iterable { return key; } - public ObjectSetIterator iterator () { + @Override + public ObjectSetIterator iterator () { return this; } diff --git a/src/dorkbox/util/collections/OrderedSet.java b/src/dorkbox/util/collections/OrderedSet.java index 5629b37..e817ce3 100644 --- a/src/dorkbox/util/collections/OrderedSet.java +++ b/src/dorkbox/util/collections/OrderedSet.java @@ -26,6 +26,7 @@ import java.util.NoSuchElementException; * matter, copying during remove can be greatly reduced by setting {@link Array#ordered} to false for * {@link OrderedSet#orderedItems()}. * @author Nathan Sweet */ +@SuppressWarnings({"unchecked", "rawtypes"}) public class OrderedSet extends ObjectSet { final Array items; OrderedSetIterator iterator1, iterator2; @@ -50,7 +51,8 @@ public class OrderedSet extends ObjectSet { items.addAll(set.items); } - public boolean add (T key) { + @Override + public boolean add (T key) { if (!super.add(key)) return false; items.add(key); return true; @@ -66,7 +68,8 @@ public class OrderedSet extends ObjectSet { return true; } - public boolean remove (T key) { + @Override + public boolean remove (T key) { if (!super.remove(key)) return false; items.removeValue(key, false); return true; @@ -78,12 +81,14 @@ public class OrderedSet extends ObjectSet { return key; } - public void clear (int maximumCapacity) { + @Override + public void clear (int maximumCapacity) { items.clear(); super.clear(maximumCapacity); } - public void clear () { + @Override + public void clear () { items.clear(); super.clear(); } @@ -92,7 +97,8 @@ public class OrderedSet extends ObjectSet { return items; } - public OrderedSetIterator iterator () { + @Override + public OrderedSetIterator iterator () { if (iterator1 == null) { iterator1 = new OrderedSetIterator(this); iterator2 = new OrderedSetIterator(this); @@ -109,7 +115,8 @@ public class OrderedSet extends ObjectSet { return iterator2; } - public String toString () { + @Override + public String toString () { if (size == 0) return "{}"; T[] items = this.items.items; StringBuilder buffer = new StringBuilder(32); @@ -123,7 +130,8 @@ public class OrderedSet extends ObjectSet { return buffer.toString(); } - public String toString (String separator) { + @Override + public String toString (String separator) { return items.toString(separator); } @@ -135,12 +143,14 @@ public class OrderedSet extends ObjectSet { items = set.items; } - public void reset () { + @Override + public void reset () { nextIndex = 0; hasNext = set.size > 0; } - public T next () { + @Override + public T next () { if (!hasNext) throw new NoSuchElementException(); if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); T key = items.get(nextIndex); @@ -149,7 +159,8 @@ public class OrderedSet extends ObjectSet { return key; } - public void remove () { + @Override + public void remove () { if (nextIndex < 0) throw new IllegalStateException("next must be called before remove."); nextIndex--; ((OrderedSet)set).removeIndex(nextIndex); diff --git a/src/dorkbox/util/collections/Select.java b/src/dorkbox/util/collections/Select.java index 6b1076c..81350b2 100644 --- a/src/dorkbox/util/collections/Select.java +++ b/src/dorkbox/util/collections/Select.java @@ -32,6 +32,7 @@ import java.util.Comparator; * single-pass for k=min and k=max, and Hoare's quickselect for values in between. *

* @author Jon Renner */ +@SuppressWarnings("unchecked") public class Select { private static Select instance; private QuickSelect quickSelect; diff --git a/src/dorkbox/util/collections/Sort.java b/src/dorkbox/util/collections/Sort.java index dc47a02..88ec925 100644 --- a/src/dorkbox/util/collections/Sort.java +++ b/src/dorkbox/util/collections/Sort.java @@ -21,6 +21,7 @@ import java.util.Comparator; * Note that sorting primitive arrays with the Arrays.sort methods does not allocate memory (unless sorting large arrays of char, * short, or byte). * @author Nathan Sweet */ +@SuppressWarnings({"RedundantCast", "unchecked", "rawtypes"}) public class Sort { static private Sort instance; diff --git a/src/dorkbox/util/collections/TimSort.java b/src/dorkbox/util/collections/TimSort.java index 6813bad..1927033 100644 --- a/src/dorkbox/util/collections/TimSort.java +++ b/src/dorkbox/util/collections/TimSort.java @@ -37,6 +37,7 @@ import java.util.Comparator; * While the API to this class consists solely of static methods, it is (privately) instantiable; a TimSort instance holds the * state of an ongoing sort, assuming the input array is large enough to warrant the full-blown TimSort. Small arrays are sorted * in place, using a binary insertion sort. */ +@SuppressWarnings("unchecked") class TimSort { /** This is the minimum sized sequence that will be merged. Shorter sequences will be lengthened by calling binarySort. If the * entire array is less than this length, no merges will be performed.