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 /** 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). * last element is moved to the removed element's position).
* @author Nathan Sweet */ * @author Nathan Sweet */
@SuppressWarnings({"unchecked", "rawtypes", "SuspiciousSystemArraycopy", "unused", "NullableProblems", "DuplicatedCode"})
public class Array<T> implements Iterable<T> { 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 /** 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. */ * 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) { public T removeIndex (int index) {
if (index >= size) throw new IndexOutOfBoundsException("index can't be >= size: " + index + " >= " + size); if (index >= size) throw new IndexOutOfBoundsException("index can't be >= size: " + index + " >= " + size);
T[] items = this.items; T[] items = this.items;
T value = (T)items[index]; T value = items[index];
size--; size--;
if (ordered) if (ordered)
System.arraycopy(items, index + 1, items, index, size - index); 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 /** 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. */ * 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); if (iterable == null) iterable = new ArrayIterable(this);
return iterable.iterator(); return iterable.iterator();
} }
@ -492,7 +494,8 @@ public class Array<T> implements Iterable<T> {
return result; return result;
} }
public int hashCode () { @Override
public int hashCode () {
if (!ordered) return super.hashCode(); if (!ordered) return super.hashCode();
Object[] items = this.items; Object[] items = this.items;
int h = 1; int h = 1;
@ -504,7 +507,8 @@ public class Array<T> implements Iterable<T> {
return h; return h;
} }
public boolean equals (Object object) { @Override
public boolean equals (Object object) {
if (object == this) return true; if (object == this) return true;
if (!ordered) return false; if (!ordered) return false;
if (!(object instanceof Array)) return false; if (!(object instanceof Array)) return false;
@ -522,7 +526,8 @@ public class Array<T> implements Iterable<T> {
return true; return true;
} }
public String toString () { @Override
public String toString () {
if (size == 0) return "[]"; if (size == 0) return "[]";
T[] items = this.items; T[] items = this.items;
StringBuilder buffer = new StringBuilder(32); StringBuilder buffer = new StringBuilder(32);
@ -563,7 +568,8 @@ public class Array<T> implements Iterable<T> {
return new Array(array); 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 Array<T> array;
private final boolean allowRemove; private final boolean allowRemove;
int index; int index;
@ -580,7 +586,8 @@ public class Array<T> implements Iterable<T> {
this.allowRemove = allowRemove; this.allowRemove = allowRemove;
} }
public boolean hasNext () { @Override
public boolean hasNext () {
if (!valid) { if (!valid) {
// System.out.println(iterable.lastAcquire); // System.out.println(iterable.lastAcquire);
throw new RuntimeException("#iterator() cannot be used nested."); throw new RuntimeException("#iterator() cannot be used nested.");
@ -588,7 +595,8 @@ public class Array<T> implements Iterable<T> {
return index < array.size; return index < array.size;
} }
public T next () { @Override
public T next () {
if (index >= array.size) throw new NoSuchElementException(String.valueOf(index)); if (index >= array.size) throw new NoSuchElementException(String.valueOf(index));
if (!valid) { if (!valid) {
// System.out.println(iterable.lastAcquire); // System.out.println(iterable.lastAcquire);
@ -597,7 +605,8 @@ public class Array<T> implements Iterable<T> {
return array.items[index++]; return array.items[index++];
} }
public void remove () { @Override
public void remove () {
if (!allowRemove) throw new RuntimeException("Remove not allowed."); if (!allowRemove) throw new RuntimeException("Remove not allowed.");
index--; index--;
array.removeIndex(index); array.removeIndex(index);
@ -607,12 +616,14 @@ public class Array<T> implements Iterable<T> {
index = 0; index = 0;
} }
public Iterator<T> iterator () { @Override
public Iterator<T> iterator () {
return this; 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 Array<T> array;
private final boolean allowRemove; private final boolean allowRemove;
private ArrayIterator iterator1, iterator2; private ArrayIterator iterator1, iterator2;
@ -628,7 +639,8 @@ public class Array<T> implements Iterable<T> {
this.allowRemove = allowRemove; this.allowRemove = allowRemove;
} }
public Iterator<T> iterator () { @Override
public Iterator<T> iterator () {
// lastAcquire.getBuffer().setLength(0); // lastAcquire.getBuffer().setLength(0);
// new Throwable().printStackTrace(new java.io.PrintWriter(lastAcquire)); // new Throwable().printStackTrace(new java.io.PrintWriter(lastAcquire));
if (iterator1 == null) { if (iterator1 == null) {

View File

@ -26,6 +26,7 @@ import dorkbox.util.Property;
/** /**
* @author dorkbox, llc * @author dorkbox, llc
*/ */
@SuppressWarnings("unchecked")
public public
class ConcurrentIterator<T> { 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 * 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. * next higher POT size.
* @author Nathan Sweet */ * @author Nathan Sweet */
@SuppressWarnings({"unchecked", "rawtypes", "NullableProblems"})
public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> { public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
private static final int PRIME1 = 0xbe1f14b1; private static final int PRIME1 = 0xbe1f14b1;
private static final int PRIME2 = 0xb4b82e39; 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; return (h ^ h >>> hashShift) & mask;
} }
public int hashCode () { @Override
public int hashCode () {
int h = 0; int h = 0;
K[] keyTable = this.keyTable; K[] keyTable = this.keyTable;
V[] valueTable = this.valueTable; V[] valueTable = this.valueTable;
@ -528,7 +530,8 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
return h; return h;
} }
public boolean equals (Object obj) { @Override
public boolean equals (Object obj) {
if (obj == this) return true; if (obj == this) return true;
if (!(obj instanceof IdentityMap)) return false; if (!(obj instanceof IdentityMap)) return false;
IdentityMap<K, V> other = (IdentityMap) obj; IdentityMap<K, V> other = (IdentityMap) obj;
@ -553,7 +556,8 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
return true; return true;
} }
public String toString () { @Override
public String toString () {
if (size == 0) return "[]"; if (size == 0) return "[]";
StringBuilder buffer = new StringBuilder(32); StringBuilder buffer = new StringBuilder(32);
buffer.append('['); buffer.append('[');
@ -580,7 +584,8 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
return buffer.toString(); return buffer.toString();
} }
public Iterator<Entry<K, V>> iterator () { @Override
public Iterator<Entry<K, V>> iterator () {
return entries(); return entries();
} }
@ -645,12 +650,14 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
public K key; public K key;
public V value; public V value;
public String toString () { @Override
public String toString () {
return key + "=" + value; 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; public boolean hasNext;
final IdentityMap<K, V> map; 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 < 0) throw new IllegalStateException("next must be called before remove.");
if (currentIndex >= map.capacity) { if (currentIndex >= map.capacity) {
map.removeStashIndex(currentIndex); 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(); private Entry<K, V> entry = new Entry();
public Entries (IdentityMap<K, V> map) { 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. */ /** 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 (!hasNext) throw new NoSuchElementException();
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
K[] keyTable = map.keyTable; K[] keyTable = map.keyTable;
@ -713,27 +723,32 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
return entry; return entry;
} }
public boolean hasNext () { @Override
public boolean hasNext () {
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
return hasNext; return hasNext;
} }
public Iterator<Entry<K, V>> iterator () { @Override
public Iterator<Entry<K, V>> iterator () {
return this; 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) { public Values (IdentityMap<?, V> map) {
super((IdentityMap<Object, V>)map); super((IdentityMap<Object, V>)map);
} }
public boolean hasNext () { @Override
public boolean hasNext () {
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
return hasNext; return hasNext;
} }
public V next () { @Override
public V next () {
if (!hasNext) throw new NoSuchElementException(); if (!hasNext) throw new NoSuchElementException();
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
V value = map.valueTable[nextIndex]; V value = map.valueTable[nextIndex];
@ -742,7 +757,8 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
return value; return value;
} }
public Iterator<V> iterator () { @Override
public Iterator<V> iterator () {
return this; 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) { public Keys (IdentityMap<K, ?> map) {
super((IdentityMap<K, Object>)map); super((IdentityMap<K, Object>)map);
} }
public boolean hasNext () { @Override
public boolean hasNext () {
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
return hasNext; return hasNext;
} }
public K next () { @Override
public K next () {
if (!hasNext) throw new NoSuchElementException(); if (!hasNext) throw new NoSuchElementException();
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
K key = map.keyTable[nextIndex]; K key = map.keyTable[nextIndex];
@ -780,7 +799,8 @@ public class IdentityMap<K, V> implements Iterable<IdentityMap.Entry<K, V>> {
return key; return key;
} }
public Iterator<K> iterator () { @Override
public Iterator<K> iterator () {
return this; 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 * 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. * next higher POT size.
* @author Nathan Sweet */ * @author Nathan Sweet */
@SuppressWarnings({"unchecked", "rawtypes"})
public class IntMap<V> implements Iterable<IntMap.Entry<V>> { public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
private static final int PRIME1 = 0xbe1f14b1; private static final int PRIME1 = 0xbe1f14b1;
private static final int PRIME2 = 0xb4b82e39; private static final int PRIME2 = 0xb4b82e39;
@ -556,6 +557,7 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
return (h ^ h >>> hashShift) & mask; return (h ^ h >>> hashShift) & mask;
} }
@Override
public int hashCode () { public int hashCode () {
int h = 0; int h = 0;
if (hasZeroValue && zeroValue != null) { if (hasZeroValue && zeroValue != null) {
@ -577,6 +579,7 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
return h; return h;
} }
@Override
public boolean equals (Object obj) { public boolean equals (Object obj) {
if (obj == this) return true; if (obj == this) return true;
if (!(obj instanceof IntMap)) return false; if (!(obj instanceof IntMap)) return false;
@ -606,6 +609,7 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
return true; return true;
} }
@Override
public String toString () { public String toString () {
if (size == 0) return "[]"; if (size == 0) return "[]";
StringBuilder buffer = new StringBuilder(32); StringBuilder buffer = new StringBuilder(32);
@ -638,6 +642,7 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
return buffer.toString(); return buffer.toString();
} }
@Override
public Iterator<Entry<V>> iterator () { public Iterator<Entry<V>> iterator () {
return entries(); return entries();
} }
@ -703,6 +708,7 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
public int key; public int key;
public V value; public V value;
@Override
public String toString () { public String toString () {
return key + "=" + value; 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>> { static public class Entries<V> extends MapIterator<V> implements Iterable<Entry<V>>, Iterator<Entry<V>> {
private Entry<V> entry = new Entry(); 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. */ /** Note the same entry instance is returned each time this method is called. */
@Override
public Entry<V> next () { public Entry<V> next () {
if (!hasNext) throw new NoSuchElementException(); if (!hasNext) throw new NoSuchElementException();
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); 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; return entry;
} }
@Override
public boolean hasNext () { public boolean hasNext () {
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
return hasNext; return hasNext;
} }
@Override
public Iterator<Entry<V>> iterator () { public Iterator<Entry<V>> iterator () {
return this; return this;
} }
@Override
public void remove () { public void remove () {
super.remove(); super.remove();
} }
} }
@SuppressWarnings("unchecked")
static public class Values<V> extends MapIterator<V> implements Iterable<V>, Iterator<V> { static public class Values<V> extends MapIterator<V> implements Iterable<V>, Iterator<V> {
public Values (IntMap<V> map) { public Values (IntMap<V> map) {
super(map); super(map);
} }
@Override
public boolean hasNext () { public boolean hasNext () {
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
return hasNext; return hasNext;
} }
@Override
public V next () { public V next () {
if (!hasNext) throw new NoSuchElementException(); if (!hasNext) throw new NoSuchElementException();
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); 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; return value;
} }
@Override
public Iterator<V> iterator () { public Iterator<V> iterator () {
return this; return this;
} }
@ -835,12 +850,15 @@ public class IntMap<V> implements Iterable<IntMap.Entry<V>> {
return array; return array;
} }
@Override
public void remove () { public void remove () {
super.remove(); super.remove();
} }
} }
@SuppressWarnings("unchecked")
static public class Keys extends MapIterator { static public class Keys extends MapIterator {
@SuppressWarnings("rawtypes")
public Keys (IntMap map) { public Keys (IntMap map) {
super(map); super(map);
} }

View File

@ -16,7 +16,11 @@
package dorkbox.util.collections; package dorkbox.util.collections;
import java.io.Serializable; 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; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
/** /**
@ -137,6 +141,7 @@ class LockFreeHashMap<K, V> implements Map<K, V>, Cloneable, Serializable {
.containsValue(value); .containsValue(value);
} }
@SuppressWarnings("unchecked")
@Override @Override
public public
V get(final Object key) { 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 * 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. * time this method is called. Use the {@link Entries} constructor for nested or multithreaded iteration.
*/ */
@SuppressWarnings("unchecked")
public public
Values<V> values() { Values<V> values() {
return forwardREF.get(this) return forwardREF.get(this)

View File

@ -37,6 +37,7 @@ import com.esotericsoftware.kryo.util.ObjectMap.Values;
* <p> * <p>
* This data structure is for many-read/few-write scenarios * This data structure is for many-read/few-write scenarios
*/ */
@SuppressWarnings("unchecked")
public final public final
class LockFreeObjectMap<K, V> implements Cloneable, Serializable { class LockFreeObjectMap<K, V> implements Cloneable, Serializable {
// Recommended for best performance while adhering to the "single writer principle". Must be static-final // 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; 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; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
/** /**
@ -31,6 +35,7 @@ import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
* <p> * <p>
* This data structure is for many-read/few-write scenarios * This data structure is for many-read/few-write scenarios
*/ */
@SuppressWarnings("unchecked")
public final public final
class LockFreeSet<E> implements Set<E>, Cloneable, java.io.Serializable { 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 // 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 * 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. * next higher POT size.
* @author Nathan Sweet */ * @author Nathan Sweet */
@SuppressWarnings({"NullableProblems", "rawtypes", "unchecked"})
public class LongMap<V> implements Iterable<LongMap.Entry<V>> { public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
private static final int PRIME1 = 0xbe1f14b1; private static final int PRIME1 = 0xbe1f14b1;
private static final int PRIME2 = 0xb4b82e39; 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); return (int)((h ^ h >>> hashShift) & mask);
} }
public int hashCode () { @Override
public int hashCode () {
int h = 0; int h = 0;
if (hasZeroValue && zeroValue != null) { if (hasZeroValue && zeroValue != null) {
h += zeroValue.hashCode(); h += zeroValue.hashCode();
@ -574,7 +576,8 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
return h; return h;
} }
public boolean equals (Object obj) { @Override
public boolean equals (Object obj) {
if (obj == this) return true; if (obj == this) return true;
if (!(obj instanceof LongMap)) return false; if (!(obj instanceof LongMap)) return false;
LongMap<V> other = (LongMap)obj; LongMap<V> other = (LongMap)obj;
@ -603,7 +606,8 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
return true; return true;
} }
public String toString () { @Override
public String toString () {
if (size == 0) return "[]"; if (size == 0) return "[]";
StringBuilder buffer = new StringBuilder(32); StringBuilder buffer = new StringBuilder(32);
buffer.append('['); buffer.append('[');
@ -630,7 +634,8 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
return buffer.toString(); return buffer.toString();
} }
public Iterator<Entry<V>> iterator () { @Override
public Iterator<Entry<V>> iterator () {
return entries(); return entries();
} }
@ -695,7 +700,8 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
public long key; public long key;
public V value; public V value;
public String toString () { @Override
public String toString () {
return key + "=" + value; 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(); private Entry<V> entry = new Entry();
public Entries (LongMap map) { 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. */ /** 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 (!hasNext) throw new NoSuchElementException();
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
long[] keyTable = map.keyTable; long[] keyTable = map.keyTable;
@ -778,31 +786,37 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
return entry; return entry;
} }
public boolean hasNext () { @Override
public boolean hasNext () {
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
return hasNext; return hasNext;
} }
public Iterator<Entry<V>> iterator () { @Override
public Iterator<Entry<V>> iterator () {
return this; return this;
} }
public void remove () { @Override
public void remove () {
super.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) { public Values (LongMap<V> map) {
super(map); super(map);
} }
public boolean hasNext () { @Override
public boolean hasNext () {
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
return hasNext; return hasNext;
} }
public V next () { @Override
public V next () {
if (!hasNext) throw new NoSuchElementException(); if (!hasNext) throw new NoSuchElementException();
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
V value; V value;
@ -815,7 +829,8 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
return value; return value;
} }
public Iterator<V> iterator () { @Override
public Iterator<V> iterator () {
return this; return this;
} }
@ -827,12 +842,14 @@ public class LongMap<V> implements Iterable<LongMap.Entry<V>> {
return array; return array;
} }
public void remove () { @Override
public void remove () {
super.remove(); super.remove();
} }
} }
static public class Keys extends MapIterator { @SuppressWarnings("rawtypes")
static public class Keys extends MapIterator {
public Keys (LongMap map) { public Keys (LongMap map) {
super(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 * 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. * next higher POT size.
* @author Nathan Sweet */ * @author Nathan Sweet */
@SuppressWarnings({"unchecked", "NullableProblems", "rawtypes"})
public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> { public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
private static final int PRIME1 = 0xbe1f14b1; private static final int PRIME1 = 0xbe1f14b1;
private static final int PRIME2 = 0xb4b82e39; 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 /** Creates a new map with the specified initial capacity and load factor. This map will hold initialCapacity items before
* growing the backing table. * growing the backing table.
* @param initialCapacity If not a power of two, it is increased to the next nearest power of two. */ * @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); if (initialCapacity < 0) throw new IllegalArgumentException("initialCapacity must be >= 0: " + initialCapacity);
initialCapacity = MathUtil.nextPowerOfTwo((int)Math.ceil(initialCapacity / loadFactor)); initialCapacity = MathUtil.nextPowerOfTwo((int)Math.ceil(initialCapacity / loadFactor));
if (initialCapacity > 1 << 30) throw new IllegalArgumentException("initialCapacity is too large: " + initialCapacity); 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; return (h ^ h >>> hashShift) & mask;
} }
public int hashCode () { @Override
public int hashCode () {
int h = 0; int h = 0;
K[] keyTable = this.keyTable; K[] keyTable = this.keyTable;
float[] valueTable = this.valueTable; float[] valueTable = this.valueTable;
@ -516,7 +519,8 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
return h; return h;
} }
public boolean equals (Object obj) { @Override
public boolean equals (Object obj) {
if (obj == this) return true; if (obj == this) return true;
if (!(obj instanceof ObjectFloatMap)) return false; if (!(obj instanceof ObjectFloatMap)) return false;
ObjectFloatMap<K> other = (ObjectFloatMap) obj; ObjectFloatMap<K> other = (ObjectFloatMap) obj;
@ -535,7 +539,8 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
return true; return true;
} }
public String toString () { @Override
public String toString () {
if (size == 0) return "{}"; if (size == 0) return "{}";
StringBuilder buffer = new StringBuilder(32); StringBuilder buffer = new StringBuilder(32);
buffer.append('{'); buffer.append('{');
@ -562,7 +567,8 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
return buffer.toString(); return buffer.toString();
} }
public Entries<K> iterator () { @Override
public Entries<K> iterator () {
return entries(); return entries();
} }
@ -627,7 +633,8 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
public K key; public K key;
public float value; public float value;
public String toString () { @Override
public String toString () {
return key + "=" + value; 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. */ /** 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 (!hasNext) throw new NoSuchElementException();
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
K[] keyTable = map.keyTable; K[] keyTable = map.keyTable;
@ -694,16 +702,19 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
return entry; return entry;
} }
public boolean hasNext () { @Override
public boolean hasNext () {
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
return hasNext; return hasNext;
} }
public Entries<K> iterator () { @Override
public Entries<K> iterator () {
return this; return this;
} }
public void remove () { @Override
public void remove () {
super.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) { public Keys (ObjectFloatMap<K> map) {
super((ObjectFloatMap<K>)map); super((ObjectFloatMap<K>)map);
} }
public boolean hasNext () { @Override
public boolean hasNext () {
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
return hasNext; return hasNext;
} }
public K next () { @Override
public K next () {
if (!hasNext) throw new NoSuchElementException(); if (!hasNext) throw new NoSuchElementException();
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
K key = map.keyTable[nextIndex]; K key = map.keyTable[nextIndex];
@ -755,7 +769,8 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
return key; return key;
} }
public Keys<K> iterator () { @Override
public Keys<K> iterator () {
return this; return this;
} }
@ -774,7 +789,8 @@ public class ObjectFloatMap<K> implements Iterable<ObjectFloatMap.Entry<K>> {
return array; return array;
} }
public void remove () { @Override
public void remove () {
super.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 * 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. * next higher POT size.
* @author Nathan Sweet */ * @author Nathan Sweet */
@SuppressWarnings({"unchecked", "NullableProblems"})
public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> { public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
private static final int PRIME1 = 0xbe1f14b1; private static final int PRIME1 = 0xbe1f14b1;
private static final int PRIME2 = 0xb4b82e39; private static final int PRIME2 = 0xb4b82e39;
@ -501,6 +502,7 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
return (h ^ h >>> hashShift) & mask; return (h ^ h >>> hashShift) & mask;
} }
@Override
public int hashCode () { public int hashCode () {
int h = 0; int h = 0;
K[] keyTable = this.keyTable; K[] keyTable = this.keyTable;
@ -517,6 +519,7 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
return h; return h;
} }
@Override
public boolean equals (Object obj) { public boolean equals (Object obj) {
if (obj == this) return true; if (obj == this) return true;
if (!(obj instanceof ObjectIntMap)) return false; if (!(obj instanceof ObjectIntMap)) return false;
@ -536,6 +539,7 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
return true; return true;
} }
@Override
public String toString () { public String toString () {
if (size == 0) return "{}"; if (size == 0) return "{}";
StringBuilder buffer = new StringBuilder(32); StringBuilder buffer = new StringBuilder(32);
@ -563,6 +567,7 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
return buffer.toString(); return buffer.toString();
} }
@Override
public Entries<K> iterator () { public Entries<K> iterator () {
return entries(); return entries();
} }
@ -628,6 +633,7 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
public K key; public K key;
public int value; public int value;
@Override
public String toString () { public String toString () {
return key + "=" + value; 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. */ /** Note the same entry instance is returned each time this method is called. */
@Override
public Entry<K> next () { public Entry<K> next () {
if (!hasNext) throw new NoSuchElementException(); if (!hasNext) throw new NoSuchElementException();
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); 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; return entry;
} }
@Override
public boolean hasNext () { public boolean hasNext () {
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
return hasNext; return hasNext;
} }
@Override
public Entries<K> iterator () { public Entries<K> iterator () {
return this; return this;
} }
@Override
public void remove () { public void remove () {
super.remove(); super.remove();
} }
@ -742,11 +752,13 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
super((ObjectIntMap<K>)map); super((ObjectIntMap<K>)map);
} }
@Override
public boolean hasNext () { public boolean hasNext () {
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
return hasNext; return hasNext;
} }
@Override
public K next () { public K next () {
if (!hasNext) throw new NoSuchElementException(); if (!hasNext) throw new NoSuchElementException();
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); 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; return key;
} }
@Override
public Keys<K> iterator () { public Keys<K> iterator () {
return this; return this;
} }
@ -775,6 +788,7 @@ public class ObjectIntMap<K> implements Iterable<ObjectIntMap.Entry<K>> {
return array; return array;
} }
@Override
public void remove () { public void remove () {
super.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 * 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. * the capacity. {@link OrderedMap} provides much faster iteration.
* @author Nathan Sweet */ * @author Nathan Sweet */
@SuppressWarnings("unchecked")
public class ObjectMap<K, V> implements Iterable<ObjectMap.Entry<K, V>> { public class ObjectMap<K, V> implements Iterable<ObjectMap.Entry<K, V>> {
private static final int PRIME1 = 0xbe1f14b1; private static final int PRIME1 = 0xbe1f14b1;
private static final int PRIME2 = 0xb4b82e39; 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(); Entry<K, V> entry = new Entry();
public Entries (ObjectMap<K, V> map) { 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> { static public class Values<V> extends MapIterator<Object, V, V> {
public Values (ObjectMap<?, V> map) { public Values (ObjectMap<?, V> map) {
super((ObjectMap<Object, 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) { public Keys (ObjectMap<K, ?> map) {
super((ObjectMap<K, Object>)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 * 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. * the capacity. {@link OrderedSet} provides much faster iteration.
* @author Nathan Sweet */ * @author Nathan Sweet */
@SuppressWarnings({"unchecked", "rawtypes", "NullableProblems", "SuspiciousSystemArraycopy"})
public class ObjectSet<T> implements Iterable<T> { public class ObjectSet<T> implements Iterable<T> {
private static final int PRIME1 = 0xbe1f14b1; private static final int PRIME1 = 0xbe1f14b1;
private static final int PRIME2 = 0xb4b82e39; private static final int PRIME2 = 0xb4b82e39;
@ -440,14 +441,16 @@ public class ObjectSet<T> implements Iterable<T> {
return (h ^ h >>> hashShift) & mask; return (h ^ h >>> hashShift) & mask;
} }
public int hashCode () { @Override
public int hashCode () {
int h = 0; int h = 0;
for (int i = 0, n = capacity + stashSize; i < n; i++) for (int i = 0, n = capacity + stashSize; i < n; i++)
if (keyTable[i] != null) h += keyTable[i].hashCode(); if (keyTable[i] != null) h += keyTable[i].hashCode();
return h; return h;
} }
public boolean equals (Object obj) { @Override
public boolean equals (Object obj) {
if (!(obj instanceof ObjectSet)) return false; if (!(obj instanceof ObjectSet)) return false;
ObjectSet other = (ObjectSet)obj; ObjectSet other = (ObjectSet)obj;
if (other.size != size) return false; if (other.size != size) return false;
@ -457,7 +460,8 @@ public class ObjectSet<T> implements Iterable<T> {
return true; return true;
} }
public String toString () { @Override
public String toString () {
return '{' + 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 /** 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. */ * 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) { if (iterator1 == null) {
iterator1 = new ObjectSetIterator(this); iterator1 = new ObjectSetIterator(this);
iterator2 = 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 < 0) throw new IllegalStateException("next must be called before remove.");
if (currentIndex >= set.capacity) { if (currentIndex >= set.capacity) {
set.removeStashIndex(currentIndex); set.removeStashIndex(currentIndex);
@ -548,12 +554,14 @@ public class ObjectSet<T> implements Iterable<T> {
set.size--; set.size--;
} }
public boolean hasNext () { @Override
public boolean hasNext () {
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
return hasNext; return hasNext;
} }
public K next () { @Override
public K next () {
if (!hasNext) throw new NoSuchElementException(); if (!hasNext) throw new NoSuchElementException();
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
K key = set.keyTable[nextIndex]; K key = set.keyTable[nextIndex];
@ -562,7 +570,8 @@ public class ObjectSet<T> implements Iterable<T> {
return key; return key;
} }
public ObjectSetIterator<K> iterator () { @Override
public ObjectSetIterator<K> iterator () {
return this; 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 * matter, copying during remove can be greatly reduced by setting {@link Array#ordered} to false for
* {@link OrderedSet#orderedItems()}. * {@link OrderedSet#orderedItems()}.
* @author Nathan Sweet */ * @author Nathan Sweet */
@SuppressWarnings({"unchecked", "rawtypes"})
public class OrderedSet<T> extends ObjectSet<T> { public class OrderedSet<T> extends ObjectSet<T> {
final Array<T> items; final Array<T> items;
OrderedSetIterator iterator1, iterator2; OrderedSetIterator iterator1, iterator2;
@ -50,7 +51,8 @@ public class OrderedSet<T> extends ObjectSet<T> {
items.addAll(set.items); items.addAll(set.items);
} }
public boolean add (T key) { @Override
public boolean add (T key) {
if (!super.add(key)) return false; if (!super.add(key)) return false;
items.add(key); items.add(key);
return true; return true;
@ -66,7 +68,8 @@ public class OrderedSet<T> extends ObjectSet<T> {
return true; return true;
} }
public boolean remove (T key) { @Override
public boolean remove (T key) {
if (!super.remove(key)) return false; if (!super.remove(key)) return false;
items.removeValue(key, false); items.removeValue(key, false);
return true; return true;
@ -78,12 +81,14 @@ public class OrderedSet<T> extends ObjectSet<T> {
return key; return key;
} }
public void clear (int maximumCapacity) { @Override
public void clear (int maximumCapacity) {
items.clear(); items.clear();
super.clear(maximumCapacity); super.clear(maximumCapacity);
} }
public void clear () { @Override
public void clear () {
items.clear(); items.clear();
super.clear(); super.clear();
} }
@ -92,7 +97,8 @@ public class OrderedSet<T> extends ObjectSet<T> {
return items; return items;
} }
public OrderedSetIterator<T> iterator () { @Override
public OrderedSetIterator<T> iterator () {
if (iterator1 == null) { if (iterator1 == null) {
iterator1 = new OrderedSetIterator(this); iterator1 = new OrderedSetIterator(this);
iterator2 = new OrderedSetIterator(this); iterator2 = new OrderedSetIterator(this);
@ -109,7 +115,8 @@ public class OrderedSet<T> extends ObjectSet<T> {
return iterator2; return iterator2;
} }
public String toString () { @Override
public String toString () {
if (size == 0) return "{}"; if (size == 0) return "{}";
T[] items = this.items.items; T[] items = this.items.items;
StringBuilder buffer = new StringBuilder(32); StringBuilder buffer = new StringBuilder(32);
@ -123,7 +130,8 @@ public class OrderedSet<T> extends ObjectSet<T> {
return buffer.toString(); return buffer.toString();
} }
public String toString (String separator) { @Override
public String toString (String separator) {
return items.toString(separator); return items.toString(separator);
} }
@ -135,12 +143,14 @@ public class OrderedSet<T> extends ObjectSet<T> {
items = set.items; items = set.items;
} }
public void reset () { @Override
public void reset () {
nextIndex = 0; nextIndex = 0;
hasNext = set.size > 0; hasNext = set.size > 0;
} }
public T next () { @Override
public T next () {
if (!hasNext) throw new NoSuchElementException(); if (!hasNext) throw new NoSuchElementException();
if (!valid) throw new RuntimeException("#iterator() cannot be used nested."); if (!valid) throw new RuntimeException("#iterator() cannot be used nested.");
T key = items.get(nextIndex); T key = items.get(nextIndex);
@ -149,7 +159,8 @@ public class OrderedSet<T> extends ObjectSet<T> {
return key; return key;
} }
public void remove () { @Override
public void remove () {
if (nextIndex < 0) throw new IllegalStateException("next must be called before remove."); if (nextIndex < 0) throw new IllegalStateException("next must be called before remove.");
nextIndex--; nextIndex--;
((OrderedSet)set).removeIndex(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. * single-pass for k=min and k=max, and Hoare's quickselect for values in between.
* </p> * </p>
* @author Jon Renner */ * @author Jon Renner */
@SuppressWarnings("unchecked")
public class Select { public class Select {
private static Select instance; private static Select instance;
private QuickSelect quickSelect; 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, * Note that sorting primitive arrays with the Arrays.sort methods does not allocate memory (unless sorting large arrays of char,
* short, or byte). * short, or byte).
* @author Nathan Sweet */ * @author Nathan Sweet */
@SuppressWarnings({"RedundantCast", "unchecked", "rawtypes"})
public class Sort { public class Sort {
static private Sort instance; 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 * 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 * 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. */ * in place, using a binary insertion sort. */
@SuppressWarnings("unchecked")
class TimSort<T> { class TimSort<T> {
/** This is the minimum sized sequence that will be merged. Shorter sequences will be lengthened by calling binarySort. If the /** 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. * entire array is less than this length, no merges will be performed.