src/share/classes/java/util/Collections.java

Print this page

        

@@ -211,11 +211,11 @@
      * @throws UnsupportedOperationException if the specified list's
      *         list-iterator does not support the {@code set} operation.
      * @throws IllegalArgumentException (optional) if the comparator is
      *         found to violate the {@link Comparator} contract
      */
-    @SuppressWarnings({ "unchecked", "rawtypes" })
+    @SuppressWarnings({"unchecked", "rawtypes"})
     public static <T> void sort(List<T> list, Comparator<? super T> c) {
         Object[] a = list.toArray();
         Arrays.sort(a, (Comparator)c);
         ListIterator<T> i = list.listIterator();
         for (int j=0; j<a.length; j++) {

@@ -416,11 +416,11 @@
      *
      * @param  list the list whose elements are to be reversed.
      * @throws UnsupportedOperationException if the specified list or
      *         its list-iterator does not support the <tt>set</tt> operation.
      */
-    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @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<mid; i++, j--)
                 swap(list, i, j);

@@ -495,11 +495,11 @@
      * @param  list the list to be shuffled.
      * @param  rnd the source of randomness to use to shuffle the list.
      * @throws UnsupportedOperationException if the specified list or its
      *         list-iterator does not support the <tt>set</tt> operation.
      */
-    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @SuppressWarnings({"rawtypes", "unchecked"})
     public static void shuffle(List<?> list, Random rnd) {
         int size = list.size();
         if (size < SHUFFLE_THRESHOLD || list instanceof RandomAccess) {
             for (int i=size; i>1; i--)
                 swap(list, i-1, rnd.nextInt(i));

@@ -533,11 +533,11 @@
      * @throws IndexOutOfBoundsException if either <tt>i</tt> or <tt>j</tt>
      *         is out of range (i &lt; 0 || i &gt;= list.size()
      *         || j &lt; 0 || j &gt;= list.size()).
      * @since 1.4
      */
-    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @SuppressWarnings({"rawtypes", "unchecked"})
     public static void swap(List<?> 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;

@@ -667,11 +667,11 @@
      * @throws ClassCastException if the collection contains elements that are
      *         not <i>mutually comparable</i> using the specified comparator.
      * @throws NoSuchElementException if the collection is empty.
      * @see Comparable
      */
-    @SuppressWarnings({ "unchecked", "rawtypes" })
+    @SuppressWarnings({"unchecked", "rawtypes"})
     public static <T> T min(Collection<? extends T> coll, Comparator<? super T> comp) {
         if (comp==null)
             return (T)min((Collection) coll);
 
         Iterator<? extends T> i = coll.iterator();

@@ -738,11 +738,11 @@
      * @throws ClassCastException if the collection contains elements that are
      *         not <i>mutually comparable</i> using the specified comparator.
      * @throws NoSuchElementException if the collection is empty.
      * @see Comparable
      */
-    @SuppressWarnings({ "unchecked", "rawtypes" })
+    @SuppressWarnings({"unchecked", "rawtypes"})
     public static <T> T max(Collection<? extends T> coll, Comparator<? super T> comp) {
         if (comp==null)
             return (T)max((Collection) coll);
 
         Iterator<? extends T> i = coll.iterator();

@@ -1401,11 +1401,11 @@
          */
         static class UnmodifiableEntrySet<K,V>
             extends UnmodifiableSet<Map.Entry<K,V>> {
             private static final long serialVersionUID = 7854390611657943733L;
 
-            @SuppressWarnings({ "unchecked", "rawtypes" })
+            @SuppressWarnings({"unchecked", "rawtypes"})
             UnmodifiableEntrySet(Set<? extends Map.Entry<? extends K, ? extends V>> s) {
                 // Need to cast to raw in order to work around a limitation in the type system
                 super((Set)s);
             }
             public Iterator<Map.Entry<K,V>> iterator() {

@@ -3170,11 +3170,11 @@
     /**
      * The empty set (immutable).  This set is serializable.
      *
      * @see #emptySet()
      */
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings("rawtypes")
     public static final Set EMPTY_SET = new EmptySet<>();
 
     /**
      * Returns the empty set (immutable).  This set is serializable.
      * Unlike the like-named field, this method is parameterized.

@@ -3269,14 +3269,17 @@
         // Preserves singleton property
         private Object readResolve() {
             return new EmptySortedSet<>();
         }
 
-        public Comparator comparator() {
+        @Override
+        public Comparator<? super E> comparator() {
             return null;
         }
 
+        @Override
+        @SuppressWarnings("unchecked")
         public SortedSet<E> subSet(Object fromElement, Object toElement) {
             Objects.requireNonNull(fromElement);
             Objects.requireNonNull(toElement);
 
             if (!(fromElement instanceof Comparable) ||

@@ -3292,45 +3295,49 @@
             }
 
             return emptySortedSet();
         }
 
+        @Override
         public SortedSet<E> headSet(Object toElement) {
             Objects.requireNonNull(toElement);
 
             if (!(toElement instanceof Comparable)) {
                 throw new ClassCastException();
             }
 
             return emptySortedSet();
         }
 
+        @Override
         public SortedSet<E> tailSet(Object fromElement) {
             Objects.requireNonNull(fromElement);
 
             if (!(fromElement instanceof Comparable)) {
                 throw new ClassCastException();
             }
 
             return emptySortedSet();
         }
 
+        @Override
         public E first() {
             throw new NoSuchElementException();
         }
 
+        @Override
         public E last() {
             throw new NoSuchElementException();
         }
     }
 
     /**
      * The empty list (immutable).  This list is serializable.
      *
      * @see #emptyList()
      */
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings("rawtypes")
     public static final List EMPTY_LIST = new EmptyList<>();
 
     /**
      * Returns the empty list (immutable).  This list is serializable.
      *

@@ -3400,11 +3407,11 @@
      * The empty map (immutable).  This map is serializable.
      *
      * @see #emptyMap()
      * @since 1.3
      */
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings("rawtypes")
     public static final Map EMPTY_MAP = new EmptyMap<>();
 
     /**
      * Returns the empty map (immutable).  This map is serializable.
      *

@@ -3683,10 +3690,11 @@
             if (element != null)
                 Arrays.fill(a, 0, n, element);
             return a;
         }
 
+        @SuppressWarnings("unchecked")
         public <T> T[] toArray(T[] a) {
             final int n = this.n;
             if (a.length < n) {
                 a = (T[])java.lang.reflect.Array
                     .newInstance(a.getClass().getComponentType(), n);

@@ -3729,10 +3737,11 @@
      * @return A comparator that imposes the reverse of the <i>natural
      *         ordering</i> on a collection of objects that implement
      *         the <tt>Comparable</tt> interface.
      * @see Comparable
      */
+    @SuppressWarnings("unchecked")
     public static <T> Comparator<T> reverseOrder() {
         return (Comparator<T>) ReverseComparator.REVERSE_ORDER;
     }
 
     /**