From 56ca7e603f44ae67f004685a2e089ba386c39fd7 Mon Sep 17 00:00:00 2001 From: Ark42 Date: Sat, 7 Dec 2013 23:29:48 -0500 Subject: [PATCH] Fixed warnings --- .classpath | 3 ++- .../physics/box2d/joints/PulleyJointDef.java | 4 +-- src/com/badlogic/gdx/utils/Array.java | 15 ++++++----- .../badlogic/gdx/utils/ComparableTimSort.java | 20 +++++++------- src/com/badlogic/gdx/utils/LongMap.java | 27 ++++++++++--------- src/com/badlogic/gdx/utils/Pool.java | 2 +- src/com/badlogic/gdx/utils/Sort.java | 15 ++++++----- src/com/badlogic/gdx/utils/TimSort.java | 17 ++++++------ 8 files changed, 54 insertions(+), 49 deletions(-) diff --git a/.classpath b/.classpath index 3f9691c..d57ec02 100644 --- a/.classpath +++ b/.classpath @@ -1,8 +1,9 @@ - + + diff --git a/src/com/badlogic/gdx/physics/box2d/joints/PulleyJointDef.java b/src/com/badlogic/gdx/physics/box2d/joints/PulleyJointDef.java index 8a8a4e0..108ca22 100644 --- a/src/com/badlogic/gdx/physics/box2d/joints/PulleyJointDef.java +++ b/src/com/badlogic/gdx/physics/box2d/joints/PulleyJointDef.java @@ -23,7 +23,7 @@ /** Pulley joint definition. This requires two ground anchors, two dynamic body anchor points, max lengths for each side, and a * pulley ratio. */ public class PulleyJointDef extends JointDef { - private final static float minPulleyLength = 2.0f; + //private final static float minPulleyLength = 2.0f; public PulleyJointDef () { type = JointType.PulleyJoint; @@ -42,7 +42,7 @@ public void initialize (Body bodyA, Body bodyB, Vector2 groundAnchorA, Vector2 g lengthA = anchorA.dst(groundAnchorA); lengthB = anchorB.dst(groundAnchorB); this.ratio = ratio; - float C = lengthA + ratio * lengthB; + //float C = lengthA + ratio * lengthB; } /** The first ground anchor in world coordinates. This point never moves. */ diff --git a/src/com/badlogic/gdx/utils/Array.java b/src/com/badlogic/gdx/utils/Array.java index e11ae9f..3f32027 100644 --- a/src/com/badlogic/gdx/utils/Array.java +++ b/src/com/badlogic/gdx/utils/Array.java @@ -25,6 +25,7 @@ /** 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") public class Array implements Iterable { /** Provides direct access to the underlying array. If the Array's generic type is not Object, this field may only be accessed * if the {@link Array#Array(boolean, int, Class)} constructor was used. */ @@ -33,7 +34,7 @@ public class Array implements Iterable { public int size; public boolean ordered; - private ArrayIterator iterator; + private ArrayIterator iterator; /** Creates an ordered array with a capacity of 16. */ public Array () { @@ -70,7 +71,7 @@ public Array (Class arrayType) { /** Creates a new array containing the elements in the specified array. The new array will have the same type of backing array * and will be ordered if the specified array is ordered. The capacity is set to the number of elements, so any subsequent * elements added will cause the backing array to be grown. */ - public Array (Array array) { + public Array (Array array) { this(array.ordered, array.size, (Class)array.items.getClass().getComponentType()); size = array.size; System.arraycopy(array.items, 0, items, 0, size); @@ -88,7 +89,7 @@ public Array (T[] array) { * @param ordered If false, methods that remove elements may change the order of other elements in the array, which avoids a * memory copy. */ public Array (boolean ordered, T[] array) { - this(ordered, array.length, (Class)array.getClass().getComponentType()); + this(ordered, array.length, (Class)array.getClass().getComponentType()); size = array.length; System.arraycopy(array, 0, items, 0, size); } @@ -99,11 +100,11 @@ public void add (T value) { items[size++] = value; } - public void addAll (Array array) { + public void addAll (Array array) { addAll(array, 0, array.size); } - public void addAll (Array array, int offset, int length) { + public void addAll (Array array, int offset, int length) { if (offset + length > array.size) throw new IllegalArgumentException("offset + length must be <= size: " + offset + " + " + length + " <= " + array.size); addAll((T[])array.items, offset, length); @@ -305,7 +306,7 @@ public void shuffle () { * time this method is called. Use the {@link ArrayIterator} constructor for nested or multithreaded iteration. */ public Iterator iterator () { if (iterator == null) - iterator = new ArrayIterator(this); + iterator = new ArrayIterator(this); else iterator.index = 0; return iterator; @@ -339,7 +340,7 @@ public V[] toArray (Class type) { public boolean equals (Object object) { if (object == this) return true; if (!(object instanceof Array)) return false; - Array array = (Array)object; + Array array = (Array)object; int n = size; if (n != array.size) return false; Object[] items1 = this.items; diff --git a/src/com/badlogic/gdx/utils/ComparableTimSort.java b/src/com/badlogic/gdx/utils/ComparableTimSort.java index 532a942..0f3f4a6 100644 --- a/src/com/badlogic/gdx/utils/ComparableTimSort.java +++ b/src/com/badlogic/gdx/utils/ComparableTimSort.java @@ -206,7 +206,7 @@ private static void binarySort (Object[] a, int lo, int hi, int start) { if (start == lo) start++; for (; start < hi; start++) { @SuppressWarnings("unchecked") - Comparable pivot = (Comparable)a[start]; + Comparable pivot = (Comparable)a[start]; // Set left (and right) to the index where a[start] (pivot) belongs int left = lo; @@ -269,12 +269,12 @@ private static int countRunAndMakeAscending (Object[] a, int lo, int hi) { if (runHi == hi) return 1; // Find end of run, and reverse range if descending - if (((Comparable)a[runHi++]).compareTo(a[lo]) < 0) { // Descending - while (runHi < hi && ((Comparable)a[runHi]).compareTo(a[runHi - 1]) < 0) + if (((Comparable)a[runHi++]).compareTo(a[lo]) < 0) { // Descending + while (runHi < hi && ((Comparable)a[runHi]).compareTo(a[runHi - 1]) < 0) runHi++; reverseRange(a, lo, runHi); } else { // Ascending - while (runHi < hi && ((Comparable)a[runHi]).compareTo(a[runHi - 1]) >= 0) + while (runHi < hi && ((Comparable)a[runHi]).compareTo(a[runHi - 1]) >= 0) runHi++; } @@ -587,7 +587,7 @@ private void mergeLo (int base1, int len1, int base2, int len2) { */ do { if (DEBUG) assert len1 > 1 && len2 > 0; - if (((Comparable)a[cursor2]).compareTo(tmp[cursor1]) < 0) { + if (((Comparable)a[cursor2]).compareTo(tmp[cursor1]) < 0) { a[dest++] = a[cursor2++]; count2++; count1 = 0; @@ -606,7 +606,7 @@ private void mergeLo (int base1, int len1, int base2, int len2) { */ do { if (DEBUG) assert len1 > 1 && len2 > 0; - count1 = gallopRight((Comparable)a[cursor2], tmp, cursor1, len1, 0); + count1 = gallopRight((Comparable)a[cursor2], tmp, cursor1, len1, 0); if (count1 != 0) { System.arraycopy(tmp, cursor1, a, dest, count1); dest += count1; @@ -618,7 +618,7 @@ private void mergeLo (int base1, int len1, int base2, int len2) { a[dest++] = a[cursor2++]; if (--len2 == 0) break outer; - count2 = gallopLeft((Comparable)tmp[cursor1], a, cursor2, len2, 0); + count2 = gallopLeft((Comparable)tmp[cursor1], a, cursor2, len2, 0); if (count2 != 0) { System.arraycopy(a, cursor2, a, dest, count2); dest += count2; @@ -693,7 +693,7 @@ private void mergeHi (int base1, int len1, int base2, int len2) { */ do { if (DEBUG) assert len1 > 0 && len2 > 1; - if (((Comparable)tmp[cursor2]).compareTo(a[cursor1]) < 0) { + if (((Comparable)tmp[cursor2]).compareTo(a[cursor1]) < 0) { a[dest--] = a[cursor1--]; count1++; count2 = 0; @@ -712,7 +712,7 @@ private void mergeHi (int base1, int len1, int base2, int len2) { */ do { if (DEBUG) assert len1 > 0 && len2 > 1; - count1 = len1 - gallopRight((Comparable)tmp[cursor2], a, base1, len1, len1 - 1); + count1 = len1 - gallopRight((Comparable)tmp[cursor2], a, base1, len1, len1 - 1); if (count1 != 0) { dest -= count1; cursor1 -= count1; @@ -723,7 +723,7 @@ private void mergeHi (int base1, int len1, int base2, int len2) { a[dest--] = tmp[cursor2--]; if (--len2 == 1) break outer; - count2 = len2 - gallopLeft((Comparable)a[cursor1], tmp, 0, len2, len2 - 1); + count2 = len2 - gallopLeft((Comparable)a[cursor1], tmp, 0, len2, len2 - 1); if (count2 != 0) { dest -= count2; cursor2 -= count2; diff --git a/src/com/badlogic/gdx/utils/LongMap.java b/src/com/badlogic/gdx/utils/LongMap.java index c5cbcac..5dec71c 100644 --- a/src/com/badlogic/gdx/utils/LongMap.java +++ b/src/com/badlogic/gdx/utils/LongMap.java @@ -28,8 +28,9 @@ * 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") public class LongMap { - private static final int PRIME1 = 0xbe1f14b1; + //private static final int PRIME1 = 0xbe1f14b1; private static final int PRIME2 = 0xb4b82e39; private static final int PRIME3 = 0xced1c241; private static final int EMPTY = 0; @@ -47,9 +48,9 @@ public class LongMap { private int stashCapacity; private int pushIterations; - private Entries entries; - private Values values; - private Keys keys; + private Entries entries; + private Values values; + private Keys keys; /** Creates a new map with an initial capacity of 32 and a load factor of 0.8. This map will hold 25 items before growing the * backing table. */ @@ -531,7 +532,7 @@ public String toString () { * time this method is called. Use the {@link Entries} constructor for nested or multithreaded iteration. */ public Entries entries () { if (entries == null) - entries = new Entries(this); + entries = new Entries(this); else entries.reset(); return entries; @@ -541,7 +542,7 @@ public Entries entries () { * time this method is called. Use the {@link Entries} constructor for nested or multithreaded iteration. */ public Values values () { if (values == null) - values = new Values(this); + values = new Values(this); else values.reset(); return values; @@ -549,9 +550,9 @@ public Values values () { /** 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 Entries} constructor for nested or multithreaded iteration. */ - public Keys keys () { + public Keys keys () { if (keys == null) - keys = new Keys(this); + keys = new Keys(this); else keys.reset(); return keys; @@ -618,9 +619,9 @@ public void remove () { } static public class Entries extends MapIterator implements Iterable>, Iterator> { - private Entry entry = new Entry(); + private Entry entry = new Entry(); - public Entries (LongMap map) { + public Entries (LongMap map) { super(map); } @@ -675,15 +676,15 @@ public Iterator iterator () { /** Returns a new array containing the remaining values. */ public Array toArray () { - Array array = new Array(true, map.size); + Array array = new Array(true, map.size); while (hasNext) array.add(next()); return array; } } - static public class Keys extends MapIterator { - public Keys (LongMap map) { + static public class Keys extends MapIterator { + public Keys (LongMap map) { super(map); } diff --git a/src/com/badlogic/gdx/utils/Pool.java b/src/com/badlogic/gdx/utils/Pool.java index 5da28f3..5a82677 100644 --- a/src/com/badlogic/gdx/utils/Pool.java +++ b/src/com/badlogic/gdx/utils/Pool.java @@ -35,7 +35,7 @@ public Pool (int initialCapacity) { /** @param max The maximum number of free objects to store in this pool. */ public Pool (int initialCapacity, int max) { - freeObjects = new Array(false, initialCapacity); + freeObjects = new Array(false, initialCapacity); this.max = max; } diff --git a/src/com/badlogic/gdx/utils/Sort.java b/src/com/badlogic/gdx/utils/Sort.java index a7b2123..b5900a2 100644 --- a/src/com/badlogic/gdx/utils/Sort.java +++ b/src/com/badlogic/gdx/utils/Sort.java @@ -21,10 +21,11 @@ * 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("unchecked") public class Sort { static private Sort instance; - private TimSort timSort; + private TimSort timSort; private ComparableTimSort comparableTimSort; public void sort (Array a) { @@ -43,18 +44,18 @@ public void sort (T[] a, int fromIndex, int toIndex) { } public void sort (Array a, Comparator c) { - if (timSort == null) timSort = new TimSort(); - timSort.doSort(a.items, c, 0, a.size); + if (timSort == null) timSort = new TimSort(); + timSort.doSort(a.items, (Comparator) c, 0, a.size); } public void sort (T[] a, Comparator c) { - if (timSort == null) timSort = new TimSort(); - timSort.doSort(a, c, 0, a.length); + if (timSort == null) timSort = new TimSort(); + timSort.doSort(a, (Comparator) c, 0, a.length); } public void sort (T[] a, Comparator c, int fromIndex, int toIndex) { - if (timSort == null) timSort = new TimSort(); - timSort.doSort(a, c, fromIndex, toIndex); + if (timSort == null) timSort = new TimSort(); + timSort.doSort(a, (Comparator) c, fromIndex, toIndex); } /** Returns a Sort instance for convenience. Multiple threads must not use this instance at the same time. */ diff --git a/src/com/badlogic/gdx/utils/TimSort.java b/src/com/badlogic/gdx/utils/TimSort.java index 03c63e6..fd98e49 100644 --- a/src/com/badlogic/gdx/utils/TimSort.java +++ b/src/com/badlogic/gdx/utils/TimSort.java @@ -37,6 +37,7 @@ * While the API to this class consists solely of static methods, it is (privately) instantiable; a TimSort instance holds the * state of an ongoing sort, assuming the input array is large enough to warrant the full-blown TimSort. Small arrays are sorted * in place, using a binary insertion sort. */ +@SuppressWarnings("unchecked") class TimSort { /** This is the minimum sized sequence that will be merged. Shorter sequences will be lengthened by calling binarySort. If the * entire array is less than this length, no merges will be performed. @@ -93,21 +94,21 @@ class TimSort { runLen = new int[40]; } - public void doSort (T[] a, Comparator c, int lo, int hi) { + public void doSort (T[] items, Comparator c2, int lo, int hi) { stackSize = 0; - rangeCheck(a.length, lo, hi); + rangeCheck(items.length, lo, hi); int nRemaining = hi - lo; if (nRemaining < 2) return; // Arrays of size 0 and 1 are always sorted // If array is small, do a "mini-TimSort" with no merges if (nRemaining < MIN_MERGE) { - int initRunLen = countRunAndMakeAscending(a, lo, hi, c); - binarySort(a, lo, hi, lo + initRunLen, c); + int initRunLen = countRunAndMakeAscending(items, lo, hi, c2); + binarySort(items, lo, hi, lo + initRunLen, c2); return; } - this.a = a; - this.c = c; + this.a = items; + this.c = c2; tmpCount = 0; /** March over the array once, left to right, finding natural runs, extending short natural runs to minRun elements, and @@ -115,12 +116,12 @@ public void doSort (T[] a, Comparator c, int lo, int hi) { int minRun = minRunLength(nRemaining); do { // Identify next run - int runLen = countRunAndMakeAscending(a, lo, hi, c); + int runLen = countRunAndMakeAscending(items, lo, hi, c2); // If run is short, extend to min(minRun, nRemaining) if (runLen < minRun) { int force = nRemaining <= minRun ? nRemaining : minRun; - binarySort(a, lo, lo + force, lo + runLen, c); + binarySort(items, lo, lo + force, lo + runLen, c2); runLen = force; }