Suppressed generics/rawtypes/etc warnings, since these aren't my files, I shouldn't change them too much (as they work, as-is)

This commit is contained in:
nathan 2020-08-18 22:01:47 +02:00
parent 9adfc35908
commit 6270168430
17 changed files with 221 additions and 85 deletions

View File

@ -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<T> implements Iterable<T> {
/** 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<T> implements Iterable<T> {
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<T> implements Iterable<T> {
/** 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<T> iterator () {
@Override
public Iterator<T> iterator () {
if (iterable == null) iterable = new ArrayIterable(this);
return iterable.iterator();
}
@ -492,7 +494,8 @@ public class Array<T> implements Iterable<T> {
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<T> implements Iterable<T> {
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<T> implements Iterable<T> {
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<T> implements Iterable<T> {
return new Array(array);
}
static public class ArrayIterator<T> implements Iterator<T>, Iterable<T> {
@SuppressWarnings("NullableProblems")
static public class ArrayIterator<T> implements Iterator<T>, Iterable<T> {
private final Array<T> array;
private final boolean allowRemove;
int index;
@ -580,7 +586,8 @@ public class Array<T> implements Iterable<T> {
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<T> implements Iterable<T> {
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<T> implements Iterable<T> {
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<T> implements Iterable<T> {
index = 0;
}
public Iterator<T> iterator () {
@Override
public Iterator<T> iterator () {
return this;
}
}
static public class ArrayIterable<T> implements Iterable<T> {
@SuppressWarnings({"unchecked", "NullableProblems"})
static public class ArrayIterable<T> implements Iterable<T> {
private final Array<T> array;
private final boolean allowRemove;
private ArrayIterator iterator1, iterator2;
@ -628,7 +639,8 @@ public class Array<T> implements Iterable<T> {
this.allowRemove = allowRemove;
}
public Iterator<T> iterator () {
@Override
public Iterator<T> iterator () {
// lastAcquire.getBuffer().setLength(0);
// new Throwable().printStackTrace(new java.io.PrintWriter(lastAcquire));
if (iterator1 == null) {

View File

@ -26,6 +26,7 @@ import dorkbox.util.Property;
/**
* @author dorkbox, llc
*/
@SuppressWarnings("unchecked")
public
class ConcurrentIterator<T> {
/**

View File

@ -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<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
private static final int PRIME1 = 0xbe1f14b1;
private static final int PRIME2 = 0xb4b82e39;
@ -510,7 +511,8 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
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<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
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<K, V> other = (IdentityMap) obj;
@ -553,7 +556,8 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
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<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
return buffer.toString();
}
public Iterator<Entry<K, V>> iterator () {
@Override
public Iterator<Entry<K, V>> iterator () {
return entries();
}
@ -645,12 +650,14 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
public K key;
public V value;
public String toString () {
@Override
public String toString () {
return key + "=" + value;
}
}
static private abstract class MapIterator<K, V, I> implements Iterable<I>, Iterator<I> {
@SuppressWarnings("DuplicatedCode")
static private abstract class MapIterator<K, V, I> implements Iterable<I>, Iterator<I> {
public boolean hasNext;
final IdentityMap<K, V> map;
@ -679,7 +686,8 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
}
}
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<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
}
}
static public class Entries<K, V> extends MapIterator<K, V, Entry<K, V>> {
@SuppressWarnings({"NullableProblems", "DuplicatedCode", "unchecked", "FieldMayBeFinal"})
static public class Entries<K, V> extends MapIterator<K, V, Entry<K, V>> {
private Entry<K, V> entry = new Entry();
public Entries (IdentityMap<K, V> map) {
@ -702,7 +711,8 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
}
/** Note the same entry instance is returned each time this method is called. */
public Entry<K, V> next () {
@Override
public Entry<K, V> 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<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
return entry;
}
public boolean hasNext () {
@Override
public boolean hasNext () {
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
return hasNext;
}
public Iterator<Entry<K, V>> iterator () {
@Override
public Iterator<Entry<K, V>> iterator () {
return this;
}
}
static public class Values<V> extends MapIterator<Object, V, V> {
@SuppressWarnings({"rawtypes", "NullableProblems"})
static public class Values<V> extends MapIterator<Object, V, V> {
public Values (IdentityMap<?, V> map) {
super((IdentityMap<Object, V>)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<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
return value;
}
public Iterator<V> iterator () {
@Override
public Iterator<V> iterator () {
return this;
}
@ -761,17 +777,20 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
}
}
static public class Keys<K> extends MapIterator<K, Object, K> {
@SuppressWarnings("unchecked")
static public class Keys<K> extends MapIterator<K, Object, K> {
public Keys (IdentityMap<K, ?> map) {
super((IdentityMap<K, Object>)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<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
return key;
}
public Iterator<K> iterator () {
@Override
public Iterator<K> iterator () {
return this;
}

View File

@ -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<V> implements Iterable<IntMap.Entry<V>> {
private static final int PRIME1 = 0xbe1f14b1;
private static final int PRIME2 = 0xb4b82e39;
@ -556,6 +557,7 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
return (h ^ h >>> hashShift) & mask;
}
@Override
public int hashCode () {
int h = 0;
if (hasZeroValue && zeroValue != null) {
@ -577,6 +579,7 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
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<V> implements Iterable<IntMap.Entry<V>> {
return true;
}
@Override
public String toString () {
if (size == 0) return "[]";
StringBuilder buffer = new StringBuilder(32);
@ -638,6 +642,7 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
return buffer.toString();
}
@Override
public Iterator<Entry<V>> iterator () {
return entries();
}
@ -703,6 +708,7 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
public int key;
public V value;
@Override
public String toString () {
return key + "=" + value;
}
@ -762,6 +768,7 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
}
}
@SuppressWarnings("rawtypes")
static public class Entries<V> extends MapIterator<V> implements Iterable<Entry<V>>, Iterator<Entry<V>> {
private Entry<V> entry = new Entry();
@ -770,6 +777,7 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
}
/** Note the same entry instance is returned each time this method is called. */
@Override
public Entry<V> next () {
if (!hasNext) throw new NoSuchElementException();
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
@ -786,30 +794,36 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
return entry;
}
@Override
public boolean hasNext () {
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
return hasNext;
}
@Override
public Iterator<Entry<V>> iterator () {
return this;
}
@Override
public void remove () {
super.remove();
}
}
@SuppressWarnings("unchecked")
static public class Values<V> extends MapIterator<V> implements Iterable<V>, Iterator<V> {
public Values (IntMap<V> 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<V> implements Iterable<IntMap.Entry<V>> {
return value;
}
@Override
public Iterator<V> iterator () {
return this;
}
@ -835,12 +850,15 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
return array;
}
@Override
public void remove () {
super.remove();
}
}
@SuppressWarnings("unchecked")
static public class Keys extends MapIterator {
@SuppressWarnings("rawtypes")
public Keys (IntMap map) {
super(map);
}

View File

@ -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<K, V> implements Map<K, V>, Cloneable, Serializable {
.containsValue(value);
}
@SuppressWarnings("unchecked")
@Override
public
V get(final Object key) {

View File

@ -373,6 +373,7 @@ class LockFreeIntBiMap<V> {
* 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<V> values() {
return forwardREF.get(this)

View File

@ -37,6 +37,7 @@ import com.esotericsoftware.kryo.util.ObjectMap.Values;
* <p>
* This data structure is for many-read/few-write scenarios
*/
@SuppressWarnings("unchecked")
public final
class LockFreeObjectMap<K, V> implements Cloneable, Serializable {
// Recommended for best performance while adhering to the "single writer principle". Must be static-final

View File

@ -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;
* <p>
* This data structure is for many-read/few-write scenarios
*/
@SuppressWarnings("unchecked")
public final
class LockFreeSet<E> implements Set<E>, Cloneable, java.io.Serializable {
// Recommended for best performance while adhering to the "single writer principle". Must be static-final

View File

@ -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<V> implements Iterable<LongMap.Entry<V>> {
private static final int PRIME1 = 0xbe1f14b1;
private static final int PRIME2 = 0xb4b82e39;
@ -553,7 +554,8 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
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<V> implements Iterable<LongMap.Entry<V>> {
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<V> other = (LongMap)obj;
@ -603,7 +606,8 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
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<V> implements Iterable<LongMap.Entry<V>> {
return buffer.toString();
}
public Iterator<Entry<V>> iterator () {
@Override
public Iterator<Entry<V>> iterator () {
return entries();
}
@ -695,7 +700,8 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
public long key;
public V value;
public String toString () {
@Override
public String toString () {
return key + "=" + value;
}
}
@ -754,7 +760,8 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
}
}
static public class Entries<V> extends MapIterator<V> implements Iterable<Entry<V>>, Iterator<Entry<V>> {
@SuppressWarnings("NullableProblems")
static public class Entries<V> extends MapIterator<V> implements Iterable<Entry<V>>, Iterator<Entry<V>> {
private Entry<V> entry = new Entry();
public Entries (LongMap map) {
@ -762,7 +769,8 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
}
/** Note the same entry instance is returned each time this method is called. */
public Entry<V> next () {
@Override
public Entry<V> 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<V> implements Iterable<LongMap.Entry<V>> {
return entry;
}
public boolean hasNext () {
@Override
public boolean hasNext () {
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
return hasNext;
}
public Iterator<Entry<V>> iterator () {
@Override
public Iterator<Entry<V>> iterator () {
return this;
}
public void remove () {
@Override
public void remove () {
super.remove();
}
}
static public class Values<V> extends MapIterator<V> implements Iterable<V>, Iterator<V> {
@SuppressWarnings("rawtypes")
static public class Values<V> extends MapIterator<V> implements Iterable<V>, Iterator<V> {
public Values (LongMap<V> 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<V> implements Iterable<LongMap.Entry<V>> {
return value;
}
public Iterator<V> iterator () {
@Override
public Iterator<V> iterator () {
return this;
}
@ -827,12 +842,14 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
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);
}

View File

@ -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<K> implements Iterable<ObjectFloatMap.Entry<K>> {
private static final int PRIME1 = 0xbe1f14b1;
private static final int PRIME2 = 0xb4b82e39;
@ -66,7 +67,8 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
/** 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<K> implements Iterable<ObjectFloatMap.Entry<K>> {
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<K> implements Iterable<ObjectFloatMap.Entry<K>> {
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<K> other = (ObjectFloatMap) obj;
@ -535,7 +539,8 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
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<K> implements Iterable<ObjectFloatMap.Entry<K>> {
return buffer.toString();
}
public Entries<K> iterator () {
@Override
public Entries<K> iterator () {
return entries();
}
@ -627,7 +633,8 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
public K key;
public float value;
public String toString () {
@Override
public String toString () {
return key + "=" + value;
}
}
@ -683,7 +690,8 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
}
/** Note the same entry instance is returned each time this method is called. */
public Entry<K> next () {
@Override
public Entry<K> 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<K> implements Iterable<ObjectFloatMap.Entry<K>> {
return entry;
}
public boolean hasNext () {
@Override
public boolean hasNext () {
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
return hasNext;
}
public Entries<K> iterator () {
@Override
public Entries<K> iterator () {
return this;
}
public void remove () {
@Override
public void remove () {
super.remove();
}
}
@ -736,17 +747,20 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
}
}
static public class Keys<K> extends MapIterator<K> implements Iterable<K>, Iterator<K> {
@SuppressWarnings("unchecked")
static public class Keys<K> extends MapIterator<K> implements Iterable<K>, Iterator<K> {
public Keys (ObjectFloatMap<K> map) {
super((ObjectFloatMap<K>)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<K> implements Iterable<ObjectFloatMap.Entry<K>> {
return key;
}
public Keys<K> iterator () {
@Override
public Keys<K> iterator () {
return this;
}
@ -774,7 +789,8 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
return array;
}
public void remove () {
@Override
public void remove () {
super.remove();
}
}

View File

@ -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<K> implements Iterable<ObjectIntMap.Entry<K>> {
private static final int PRIME1 = 0xbe1f14b1;
private static final int PRIME2 = 0xb4b82e39;
@ -501,6 +502,7 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
return (h ^ h >>> hashShift) & mask;
}
@Override
public int hashCode () {
int h = 0;
K[] keyTable = this.keyTable;
@ -517,6 +519,7 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
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<K> implements Iterable<ObjectIntMap.Entry<K>> {
return true;
}
@Override
public String toString () {
if (size == 0) return "{}";
StringBuilder buffer = new StringBuilder(32);
@ -563,6 +567,7 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
return buffer.toString();
}
@Override
public Entries<K> iterator () {
return entries();
}
@ -628,6 +633,7 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
public K key;
public int value;
@Override
public String toString () {
return key + "=" + value;
}
@ -684,6 +690,7 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
}
/** Note the same entry instance is returned each time this method is called. */
@Override
public Entry<K> next () {
if (!hasNext) throw new NoSuchElementException();
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
@ -695,15 +702,18 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
return entry;
}
@Override
public boolean hasNext () {
if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
return hasNext;
}
@Override
public Entries<K> iterator () {
return this;
}
@Override
public void remove () {
super.remove();
}
@ -742,11 +752,13 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
super((ObjectIntMap<K>)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<K> implements Iterable<ObjectIntMap.Entry<K>> {
return key;
}
@Override
public Keys<K> iterator () {
return this;
}
@ -775,6 +788,7 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
return array;
}
@Override
public void remove () {
super.remove();
}

View File

@ -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<K, V> implements Iterable<ObjectMap.Entry<K, V>> {
private static final int PRIME1 = 0xbe1f14b1;
private static final int PRIME2 = 0xb4b82e39;
@ -722,7 +723,8 @@ public class ObjectMap<K, V> implements Iterable<ObjectMap.Entry<K, V>> {
}
}
static public class Entries<K, V> extends MapIterator<K, V, Entry<K, V>> {
@SuppressWarnings("NullableProblems")
static public class Entries<K, V> extends MapIterator<K, V, Entry<K, V>> {
Entry<K, V> entry = new Entry();
public Entries (ObjectMap<K, V> map) {
@ -754,7 +756,7 @@ public class ObjectMap<K, V> implements Iterable<ObjectMap.Entry<K, V>> {
}
}
@SuppressWarnings("NullableProblems")
@SuppressWarnings({"NullableProblems", "unchecked", "rawtypes"})
static public class Values<V> extends MapIterator<Object, V, V> {
public Values (ObjectMap<?, V> map) {
super((ObjectMap<Object, V>)map);
@ -794,7 +796,8 @@ public class ObjectMap<K, V> implements Iterable<ObjectMap.Entry<K, V>> {
}
}
static public class Keys<K> extends MapIterator<K, Object, K> {
@SuppressWarnings({"unchecked", "NullableProblems", "rawtypes"})
static public class Keys<K> extends MapIterator<K, Object, K> {
public Keys (ObjectMap<K, ?> map) {
super((ObjectMap<K, Object>)map);
}

View File

@ -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<T> implements Iterable<T> {
private static final int PRIME1 = 0xbe1f14b1;
private static final int PRIME2 = 0xb4b82e39;
@ -440,14 +441,16 @@ public class ObjectSet<T> implements Iterable<T> {
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<T> implements Iterable<T> {
return true;
}
public String toString () {
@Override
public String toString () {
return '{' + toString(", ") + '}';
}
@ -483,7 +487,8 @@ public class ObjectSet<T> implements Iterable<T> {
/** 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<T> iterator () {
@Override
public ObjectSetIterator<T> iterator () {
if (iterator1 == null) {
iterator1 = new ObjectSetIterator(this);
iterator2 = new ObjectSetIterator(this);
@ -535,7 +540,8 @@ public class ObjectSet<T> implements Iterable<T> {
}
}
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<T> implements Iterable<T> {
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<T> implements Iterable<T> {
return key;
}
public ObjectSetIterator<K> iterator () {
@Override
public ObjectSetIterator<K> iterator () {
return this;
}

View File

@ -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<T> extends ObjectSet<T> {
final Array<T> items;
OrderedSetIterator iterator1, iterator2;
@ -50,7 +51,8 @@ public class OrderedSet<T> extends ObjectSet<T> {
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<T> extends ObjectSet<T> {
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<T> extends ObjectSet<T> {
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<T> extends ObjectSet<T> {
return items;
}
public OrderedSetIterator<T> iterator () {
@Override
public OrderedSetIterator<T> iterator () {
if (iterator1 == null) {
iterator1 = new OrderedSetIterator(this);
iterator2 = new OrderedSetIterator(this);
@ -109,7 +115,8 @@ public class OrderedSet<T> extends ObjectSet<T> {
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<T> extends ObjectSet<T> {
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<T> extends ObjectSet<T> {
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<T> extends ObjectSet<T> {
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);

View File

@ -32,6 +32,7 @@ import java.util.Comparator;
* single-pass for k=min and k=max, and Hoare's quickselect for values in between.
* </p>
* @author Jon Renner */
@SuppressWarnings("unchecked")
public class Select {
private static Select instance;
private QuickSelect quickSelect;

View File

@ -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;

View File

@ -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<T> {
/** 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.