--- old/src/share/classes/java/util/Collections.java 2011-12-03 15:57:53.135389173 +0100 +++ new/src/share/classes/java/util/Collections.java 2011-12-03 15:57:52.989389188 +0100 @@ -150,6 +150,7 @@ * detects that the natural ordering of the list elements is * found to violate the {@link Comparable} contract */ + @SuppressWarnings("unchecked") public static > void sort(List list) { Object[] a = list.toArray(); Arrays.sort(a); @@ -212,13 +213,14 @@ * @throws IllegalArgumentException (optional) if the comparator is * found to violate the {@link Comparator} contract */ + @SuppressWarnings({ "unchecked", "rawtypes" }) public static void sort(List list, Comparator c) { Object[] a = list.toArray(); Arrays.sort(a, (Comparator)c); - ListIterator i = list.listIterator(); + ListIterator i = list.listIterator(); for (int j=0; j int binarySearch(List list, T key, Comparator c) { if (c==null) - return binarySearch((List) list, key); + return binarySearch((List>) list, key); if (list instanceof RandomAccess || list.size() {} - - /** * Reverses the order of the elements in the specified list.

* @@ -418,12 +418,16 @@ * @throws UnsupportedOperationException if the specified list or * its list-iterator does not support the set operation. */ + @SuppressWarnings({ "rawtypes", "unchecked" }) public static void reverse(List list) { int size = list.size(); if (size < REVERSE_THRESHOLD || list instanceof RandomAccess) { for (int i=0, mid=size>>1, j=size-1; i>1; iset operation. */ + @SuppressWarnings({ "rawtypes", "unchecked" }) public static void shuffle(List list, Random rnd) { int size = list.size(); if (size < SHUFFLE_THRESHOLD || list instanceof RandomAccess) { @@ -506,6 +511,9 @@ swap(arr, i-1, rnd.nextInt(i)); // Dump array back into list + // instead of using a raw type here, it's possible to capture + // the wildcard but it will require a call to a supplementary + // private method ListIterator it = list.listIterator(); for (int i=0; i list, int i, int j) { + // instead of using a raw type here, it's possible to capture + // the wildcard but it will require a call to a supplementary + // private method final List l = list; l.set(i, l.set(j, l.get(i))); } @@ -657,9 +669,10 @@ * @throws NoSuchElementException if the collection is empty. * @see Comparable */ + @SuppressWarnings({ "unchecked", "rawtypes" }) public static T min(Collection coll, Comparator comp) { if (comp==null) - return (T)min((Collection) (Collection) coll); + return (T)min((Collection) coll); Iterator i = coll.iterator(); T candidate = i.next(); @@ -727,9 +740,10 @@ * @throws NoSuchElementException if the collection is empty. * @see Comparable */ + @SuppressWarnings({ "unchecked", "rawtypes" }) public static T max(Collection coll, Comparator comp) { if (comp==null) - return (T)max((Collection) (Collection) coll); + return (T)max((Collection) coll); Iterator i = coll.iterator(); T candidate = i.next(); @@ -1389,6 +1403,7 @@ extends UnmodifiableSet> { private static final long serialVersionUID = 7854390611657943733L; + @SuppressWarnings({ "unchecked", "rawtypes" }) UnmodifiableEntrySet(Set> s) { super((Set)s); } @@ -1408,13 +1423,15 @@ }; } + @SuppressWarnings("unchecked") public Object[] toArray() { Object[] a = c.toArray(); for (int i=0; i((Map.Entry)a[i]); + a[i] = new UnmodifiableEntry<>((Map.Entry)a[i]); return a; } + @SuppressWarnings("unchecked") public T[] toArray(T[] a) { // We don't pass a to c.toArray, to avoid window of // vulnerability wherein an unscrupulous multithreaded client @@ -1422,7 +1439,7 @@ Object[] arr = c.toArray(a.length==0 ? a : Arrays.copyOf(a, 0)); for (int i=0; i((Map.Entry)arr[i]); + arr[i] = new UnmodifiableEntry<>((Map.Entry)arr[i]); if (arr.length > a.length) return (T[])arr; @@ -1464,7 +1481,7 @@ if (!(o instanceof Set)) return false; - Set s = (Set) o; + Set s = (Set) o; if (s.size() != c.size()) return false; return containsAll(s); // Invokes safe containsAll() above @@ -1491,7 +1508,7 @@ public boolean equals(Object o) { if (!(o instanceof Map.Entry)) return false; - Map.Entry t = (Map.Entry)o; + Map.Entry t = (Map.Entry)o; return eq(e.getKey(), t.getKey()) && eq(e.getValue(), t.getValue()); }