diff --git a/src/dorkbox/util/collections/ArrayMap.java b/src/dorkbox/util/collections/ArrayMap.java index 75bd0cf..175d4f5 100644 --- a/src/dorkbox/util/collections/ArrayMap.java +++ b/src/dorkbox/util/collections/ArrayMap.java @@ -30,6 +30,7 @@ import dorkbox.util.collections.ObjectMap.Entry; * makes iteration fast. Like {@link Array}, if ordered is false, 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", "unused", "SuspiciousSystemArraycopy", "NullableProblems"}) public class ArrayMap implements Iterable> { public K[] keys; public V[] values; @@ -77,7 +78,8 @@ public class ArrayMap implements Iterable> { /** Creates a new map containing the elements in the specified map. The new map will have the same type of backing arrays and * will be ordered if the specified map is ordered. The capacity is set to the number of elements, so any subsequent elements * added will cause the backing arrays to be grown. */ - public ArrayMap (ArrayMap array) { + @SuppressWarnings("CopyConstructorMissesField") + public ArrayMap (ArrayMap array) { this(array.ordered, array.size, array.keys.getClass().getComponentType(), array.values.getClass().getComponentType()); size = array.size; System.arraycopy(array.keys, 0, keys, 0, size); @@ -405,7 +407,8 @@ public class ArrayMap implements Iterable> { size = newSize; } - public int hashCode () { + @Override + public int hashCode () { K[] keys = this.keys; V[] values = this.values; int h = 0; @@ -418,7 +421,8 @@ public class ArrayMap implements Iterable> { return h; } - public boolean equals (Object obj) { + @Override + public boolean equals (Object obj) { if (obj == this) return true; if (!(obj instanceof ArrayMap)) return false; ArrayMap other = (ArrayMap)obj; @@ -437,7 +441,8 @@ public class ArrayMap implements Iterable> { return true; } - public String toString () { + @Override + public String toString () { if (size == 0) return "{}"; K[] keys = this.keys; V[] values = this.values; @@ -456,7 +461,8 @@ public class ArrayMap implements Iterable> { return buffer.toString(); } - public Iterator> iterator () { + @Override + public Iterator> iterator () { return entries(); } @@ -527,17 +533,20 @@ public class ArrayMap implements Iterable> { this.map = map; } - public boolean hasNext () { + @Override + public boolean hasNext () { if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); return index < map.size; } - public Iterator> iterator () { + @Override + public Iterator> iterator () { return this; } /** Note the same entry instance is returned each time this method is called. */ - public Entry next () { + @Override + public Entry next () { if (index >= map.size) throw new NoSuchElementException(String.valueOf(index)); if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); entry.key = map.keys[index]; @@ -545,7 +554,8 @@ public class ArrayMap implements Iterable> { return entry; } - public void remove () { + @Override + public void remove () { index--; map.removeIndex(index); } @@ -564,22 +574,26 @@ public class ArrayMap implements Iterable> { this.map = map; } - public boolean hasNext () { + @Override + public boolean hasNext () { if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); return index < map.size; } - public Iterator iterator () { + @Override + public Iterator iterator () { return this; } - public V next () { + @Override + public V next () { if (index >= map.size) throw new NoSuchElementException(String.valueOf(index)); if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); return map.values[index++]; } - public void remove () { + @Override + public void remove () { index--; map.removeIndex(index); } @@ -607,22 +621,26 @@ public class ArrayMap implements Iterable> { this.map = map; } - public boolean hasNext () { + @Override + public boolean hasNext () { if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); return index < map.size; } - public Iterator iterator () { + @Override + public Iterator iterator () { return this; } - public K next () { + @Override + public K next () { if (index >= map.size) throw new NoSuchElementException(String.valueOf(index)); if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); return map.keys[index++]; } - public void remove () { + @Override + public void remove () { index--; map.removeIndex(index); } diff --git a/src/dorkbox/util/collections/ObjectMap.java b/src/dorkbox/util/collections/ObjectMap.java index 4b2b4d9..829c06e 100644 --- a/src/dorkbox/util/collections/ObjectMap.java +++ b/src/dorkbox/util/collections/ObjectMap.java @@ -528,7 +528,8 @@ public class ObjectMap 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; @@ -546,7 +547,8 @@ public class ObjectMap implements Iterable> { return h; } - public boolean equals (Object obj) { + @Override + public boolean equals (Object obj) { if (obj == this) return true; if (!(obj instanceof ObjectMap)) return false; ObjectMap other = (ObjectMap)obj; @@ -571,7 +573,8 @@ public class ObjectMap implements Iterable> { return toString(separator, false); } - public String toString () { + @Override + public String toString () { return toString(", ", true); } @@ -602,7 +605,8 @@ public class ObjectMap implements Iterable> { return buffer.toString(); } - public Entries iterator () { + @Override + public Entries iterator () { return entries(); } @@ -667,7 +671,8 @@ public class ObjectMap implements Iterable> { public K key; public V value; - public String toString () { + @Override + public String toString () { return key + "=" + value; } } @@ -701,7 +706,8 @@ public class ObjectMap 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); @@ -724,7 +730,8 @@ public class ObjectMap 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; @@ -735,27 +742,32 @@ public class ObjectMap 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; } } - static public class Values extends MapIterator { + @SuppressWarnings("NullableProblems") + static public class Values extends MapIterator { public Values (ObjectMap map) { super((ObjectMap)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]; @@ -764,7 +776,8 @@ public class ObjectMap implements Iterable> { return value; } - public Values iterator () { + @Override + public Values iterator () { return this; } @@ -786,12 +799,14 @@ public class ObjectMap implements Iterable> { super((ObjectMap)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]; @@ -800,7 +815,8 @@ public class ObjectMap implements Iterable> { return key; } - public Keys iterator () { + @Override + public Keys iterator () { return this; } diff --git a/src/dorkbox/util/collections/OrderedMap.java b/src/dorkbox/util/collections/OrderedMap.java index 518dba5..09a659b 100644 --- a/src/dorkbox/util/collections/OrderedMap.java +++ b/src/dorkbox/util/collections/OrderedMap.java @@ -26,6 +26,7 @@ import java.util.NoSuchElementException; * for faster iteration versus ObjectMap and the order does not actually matter, copying during remove can be greatly reduced by * setting {@link Array#ordered} to false for {@link OrderedMap#orderedKeys()}. * @author Nathan Sweet */ +@SuppressWarnings({"unchecked", "NullableProblems"}) public class OrderedMap extends ObjectMap { final Array keys; @@ -52,12 +53,14 @@ public class OrderedMap extends ObjectMap { keys = new Array(map.keys); } - public V put (K key, V value) { + @Override + public V put (K key, V value) { if (!containsKey(key)) keys.add(key); return super.put(key, value); } - public V remove (K key) { + @Override + public V remove (K key) { keys.removeValue(key, false); return super.remove(key); } @@ -66,12 +69,14 @@ public class OrderedMap extends ObjectMap { return super.remove(keys.removeIndex(index)); } - public void clear (int maximumCapacity) { + @Override + public void clear (int maximumCapacity) { keys.clear(); super.clear(maximumCapacity); } - public void clear () { + @Override + public void clear () { keys.clear(); super.clear(); } @@ -80,13 +85,15 @@ public class OrderedMap extends ObjectMap { return keys; } - public Entries iterator () { + @Override + public Entries iterator () { return entries(); } /** Returns an iterator for the entries in the map. Remove is supported. Note that the same iterator instance is returned each * time this method is called. Use the {@link OrderedMapEntries} constructor for nested or multithreaded iteration. */ - public Entries entries () { + @Override + public Entries entries () { if (entries1 == null) { entries1 = new OrderedMapEntries(this); entries2 = new OrderedMapEntries(this); @@ -105,7 +112,8 @@ public class OrderedMap extends ObjectMap { /** 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 OrderedMapValues} constructor for nested or multithreaded iteration. */ - public Values values () { + @Override + public Values values () { if (values1 == null) { values1 = new OrderedMapValues(this); values2 = new OrderedMapValues(this); @@ -124,7 +132,8 @@ public class OrderedMap extends ObjectMap { /** Returns an iterator for the keys in the map. Remove is supported. Note that the same iterator instance is returned each * time this method is called. Use the {@link OrderedMapKeys} constructor for nested or multithreaded iteration. */ - public Keys keys () { + @Override + public Keys keys () { if (keys1 == null) { keys1 = new OrderedMapKeys(this); keys2 = new OrderedMapKeys(this); @@ -141,7 +150,8 @@ public class OrderedMap extends ObjectMap { return keys2; } - public String toString () { + @Override + public String toString () { if (size == 0) return "{}"; StringBuilder buffer = new StringBuilder(32); buffer.append('{'); @@ -157,20 +167,23 @@ public class OrderedMap extends ObjectMap { return buffer.toString(); } - static public class OrderedMapEntries extends Entries { - private Array keys; + @SuppressWarnings("rawtypes") + static public class OrderedMapEntries extends Entries { + private final Array keys; public OrderedMapEntries (OrderedMap map) { super(map); keys = map.keys; } - public void reset () { + @Override + public void reset () { nextIndex = 0; hasNext = map.size > 0; } - public Entry next () { + @Override + public Entry next () { if (!hasNext) throw new NoSuchElementException(); if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); entry.key = keys.get(nextIndex); @@ -180,7 +193,8 @@ public class OrderedMap extends ObjectMap { return entry; } - public void remove () { + @Override + public void remove () { if (currentIndex < 0) throw new IllegalStateException("next must be called before remove."); map.remove(entry.key); nextIndex--; @@ -188,19 +202,21 @@ public class OrderedMap extends ObjectMap { } static public class OrderedMapKeys extends Keys { - private Array keys; + private final Array keys; public OrderedMapKeys (OrderedMap map) { super(map); keys = map.keys; } - public void reset () { + @Override + public void reset () { nextIndex = 0; hasNext = map.size > 0; } - public K next () { + @Override + public K next () { if (!hasNext) throw new NoSuchElementException(); if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); K key = keys.get(nextIndex); @@ -210,7 +226,8 @@ public class OrderedMap extends ObjectMap { return key; } - public void remove () { + @Override + public void remove () { if (currentIndex < 0) throw new IllegalStateException("next must be called before remove."); ((OrderedMap)map).removeIndex(nextIndex - 1); nextIndex = currentIndex; @@ -219,19 +236,21 @@ public class OrderedMap extends ObjectMap { } static public class OrderedMapValues extends Values { - private Array keys; + private final Array keys; public OrderedMapValues (OrderedMap map) { super(map); keys = map.keys; } - public void reset () { + @Override + public void reset () { nextIndex = 0; hasNext = map.size > 0; } - public V next () { + @Override + public V next () { if (!hasNext) throw new NoSuchElementException(); if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); V value = (V)map.get(keys.get(nextIndex)); @@ -241,7 +260,8 @@ public class OrderedMap extends ObjectMap { return value; } - public void remove () { + @Override + public void remove () { if (currentIndex < 0) throw new IllegalStateException("next must be called before remove."); ((OrderedMap)map).removeIndex(currentIndex); nextIndex = currentIndex;