--- jsr166/src/main/java/util/Collections.java 2004/12/28 12:14:07 1.1 +++ jsr166/src/main/java/util/Collections.java 2005/08/11 08:52:39 1.13 @@ -1,11 +1,12 @@ /* * %W% %E% * - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package java.util; +import java.util.*; // for javadoc (till 6280605 is fixed) import java.io.Serializable; import java.io.ObjectOutputStream; import java.io.IOException; @@ -37,7 +38,7 @@ import java.lang.reflect.Array; * example, invoking the sort method on an unmodifiable list that is * already sorted may or may not throw UnsupportedOperationException. * - *
This class is a member of the + *
This class is a member of the * * Java Collections Framework. * @@ -63,7 +64,7 @@ public class Collections { * two implementations, one of which is appropriate for RandomAccess * lists, the other for "sequential." Often, the random access variant * yields better performance on small sequential access lists. The - * tuning parameters below determine the cutoff point for what constitutes + * tuning parameters below determine the cutoff point for what constitutes * a "small" sequential access list for each algorithm. The values below * were empirically determined to work well for LinkedList. Hopefully * they should be reasonable for other sequential access List @@ -97,7 +98,7 @@ public class Collections { * The sorting algorithm is a modified mergesort (in which the merge is * omitted if the highest element in the low sublist is less than the * lowest element in the high sublist). This algorithm offers guaranteed - * n log(n) performance. + * n log(n) performance. * * This implementation dumps the specified list into an array, sorts * the array, and iterates over the list resetting each element @@ -135,7 +136,7 @@ public class Collections { * The sorting algorithm is a modified mergesort (in which the merge is * omitted if the highest element in the low sublist is less than the * lowest element in the high sublist). This algorithm offers guaranteed - * n log(n) performance. + * n log(n) performance. * * The specified list must be modifiable, but need not be resizable. * This implementation dumps the specified list into an array, sorts @@ -182,7 +183,7 @@ public class Collections { * * @param list the list to be searched. * @param key the key to be searched for. - * @return index of the search key, if it is contained in the list; + * @return the index of the search key, if it is contained in the list; * otherwise, (-(insertion point) - 1). The * insertion point is defined as the point at which the * key would be inserted into the list: the index of the first @@ -287,7 +288,7 @@ public class Collections { * @param c the comparator by which the list is ordered. A * null value indicates that the elements' natural * ordering should be used. - * @return index of the search key, if it is contained in the list; + * @return the index of the search key, if it is contained in the list; * otherwise, (-(insertion point) - 1). The * insertion point is defined as the point at which the * key would be inserted into the list: the index of the first @@ -361,7 +362,7 @@ public class Collections { * * @param list the list whose elements are to be reversed. * @throws UnsupportedOperationException if the specified list or - * its list-iterator does not support the set method. + * its list-iterator does not support the set operation. */ public static void reverse(List> list) { int size = list.size(); @@ -405,12 +406,15 @@ public class Collections { * * @param list the list to be shuffled. * @throws UnsupportedOperationException if the specified list or - * its list-iterator does not support the set method. + * its list-iterator does not support the set operation. */ public static void shuffle(List> list) { + if (r == null) { + r = new Random(); + } shuffle(list, r); } - private static Random r = new Random(); + private static Random r; /** * Randomly permute the specified list using the specified source of @@ -569,7 +573,7 @@ public class Collections { Iterator extends T> i = coll.iterator(); T candidate = i.next(); - while(i.hasNext()) { + while (i.hasNext()) { T next = i.next(); if (next.compareTo(candidate) < 0) candidate = next; @@ -606,7 +610,7 @@ public class Collections { Iterator extends T> i = coll.iterator(); T candidate = i.next(); - while(i.hasNext()) { + while (i.hasNext()) { T next = i.next(); if (comp.compare(next, candidate) < 0) candidate = next; @@ -639,7 +643,7 @@ public class Collections { Iterator extends T> i = coll.iterator(); T candidate = i.next(); - while(i.hasNext()) { + while (i.hasNext()) { T next = i.next(); if (next.compareTo(candidate) > 0) candidate = next; @@ -676,7 +680,7 @@ public class Collections { Iterator extends T> i = coll.iterator(); T candidate = i.next(); - while(i.hasNext()) { + while (i.hasNext()) { T next = i.next(); if (comp.compare(next, candidate) > 0) candidate = next; @@ -712,7 +716,7 @@ public class Collections { * Collections.rotate(l.subList(1, 4), -1); * * The resulting list is [a, c, d, b, e]. - * + * *
To move more than one element forward, increase the absolute value
* of the rotation distance. To move elements backward, use a positive
* shift distance.
@@ -736,7 +740,7 @@ public class Collections {
* constraints on this value; it may be zero, negative, or
* greater than list.size().
* @throws UnsupportedOperationException if the specified list or
- * its list-iterator does not support the set method.
+ * its list-iterator does not support the set operation.
* @since 1.4
*/
public static void rotate(List> list, int distance) {
@@ -772,7 +776,7 @@ public class Collections {
private static void rotate2(List> list, int distance) {
int size = list.size();
if (size == 0)
- return;
+ return;
int mid = -distance % size;
if (mid < 0)
mid += size;
@@ -799,7 +803,7 @@ public class Collections {
* e such that
* (oldVal==null ? e==null : oldVal.equals(e)).
* @throws UnsupportedOperationException if the specified list or
- * its list-iterator does not support the set method.
+ * its list-iterator does not support the set operation.
* @since 1.4
*/
public static
*
* The returned collection will be serializable if the specified collection
- * is serializable.
+ * is serializable.
*
* @param c the collection for which an unmodifiable view is to be
* returned.
@@ -1014,7 +1018,7 @@ public class Collections {
};
}
- public boolean add(E o){
+ public boolean add(E e){
throw new UnsupportedOperationException();
}
public boolean remove(Object o) {
@@ -1046,12 +1050,11 @@ public class Collections {
* iterator, result in an UnsupportedOperationException.
*
* The returned set will be serializable if the specified set
- * is serializable.
+ * is serializable.
*
* @param s the set for which an unmodifiable view is to be returned.
* @return an unmodifiable view of the specified set.
*/
-
public static
*
* The returned sorted set will be serializable if the specified sorted set
- * is serializable.
+ * is serializable.
*
* @param s the sorted set for which an unmodifiable view is to be
- * returned.
+ * returned.
* @return an unmodifiable view of the specified sorted set.
*/
public static
*
* The returned map will be serializable if the specified map
- * is serializable.
+ * is serializable.
*
* @param m the map for which an unmodifiable view is to be returned.
* @return an unmodifiable view of the specified map.
@@ -1288,7 +1291,7 @@ public class Collections {
public V remove(Object key) {
throw new UnsupportedOperationException();
}
- public void putAll(Map extends K, ? extends V> t) {
+ public void putAll(Map extends K, ? extends V> m) {
throw new UnsupportedOperationException();
}
public void clear() {
@@ -1334,7 +1337,7 @@ public class Collections {
private static final long serialVersionUID = 7854390611657943733L;
UnmodifiableEntrySet(Set extends Map.Entry extends K, ? extends V>> s) {
- super((Set
*
* The returned sorted map will be serializable if the specified sorted map
- * is serializable.
+ * is serializable.
*
* @param m the sorted map for which an unmodifiable view is to be
- * returned.
+ * returned.
* @return an unmodifiable view of the specified sorted map.
*/
public static
*
* The returned collection will be serializable if the specified collection
- * is serializable.
+ * is serializable.
*
* @param c the collection to be "wrapped" in a synchronized collection.
* @return a synchronized view of the specified collection.
@@ -1577,8 +1577,8 @@ public class Collections {
return c.iterator(); // Must be manually synched by user!
}
- public boolean add(E o) {
- synchronized(mutex) {return c.add(o);}
+ public boolean add(E e) {
+ synchronized(mutex) {return c.add(e);}
}
public boolean remove(Object o) {
synchronized(mutex) {return c.remove(o);}
@@ -1673,7 +1673,7 @@ public class Collections {
* sorted set when iterating over it or any of its subSet,
* headSet, or tailSet views.
*
- * SortedSet s = Collections.synchronizedSortedSet(new HashSortedSet());
+ * SortedSet s = Collections.synchronizedSortedSet(new TreeSet());
* ...
* synchronized(s) {
* Iterator i = s.iterator(); // Must be in the synchronized block
@@ -1683,7 +1683,7 @@ public class Collections {
*
* or:
*
- * SortedSet s = Collections.synchronizedSortedSet(new HashSortedSet());
+ * SortedSet s = Collections.synchronizedSortedSet(new TreeSet());
* SortedSet s2 = s.headSet(foo);
* ...
* synchronized(s) { // Note: s, not s2!!!
@@ -2007,7 +2007,7 @@ public class Collections {
public Set
- * SortedMap m = Collections.synchronizedSortedMap(new HashSortedMap());
+ * SortedMap m = Collections.synchronizedSortedMap(new TreeMap());
* ...
* Set s = m.keySet(); // Needn't be in synchronized block
* ...
@@ -2057,7 +2057,7 @@ public class Collections {
*
* or:
*
- * SortedMap m = Collections.synchronizedSortedMap(new HashSortedMap());
+ * SortedMap m = Collections.synchronizedSortedMap(new TreeMap());
* SortedMap m2 = m.subMap(foo, bar);
* ...
* Set s2 = m2.keySet(); // Needn't be in synchronized block
@@ -2191,7 +2191,7 @@ public class Collections {
Class