You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2006/06/08 05:39:20 UTC
svn commit: r412640 -
/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java
Author: ndbeyer
Date: Wed Jun 7 20:39:20 2006
New Revision: 412640
URL: http://svn.apache.org/viewvc?rev=412640&view=rev
Log:
Generification of methods.
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java?rev=412640&r1=412639&r2=412640&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java Wed Jun 7 20:39:20 2006
@@ -1437,15 +1437,16 @@
* the Collection to enumerate
* @return an Enumeration
*/
- public static Enumeration enumeration(final Collection collection) {
- return new Enumeration() {
- Iterator it = collection.iterator();
+ public static <T> Enumeration<T> enumeration(Collection<T> collection) {
+ final Collection<T> c = collection;
+ return new Enumeration<T>() {
+ Iterator<T> it = c.iterator();
public boolean hasMoreElements() {
return it.hasNext();
}
- public Object nextElement() {
+ public T nextElement() {
return it.next();
}
};
@@ -1462,8 +1463,8 @@
* @exception UnsupportedOperationException
* when replacing an element in the List is not supported
*/
- public static void fill(List list, Object object) {
- ListIterator it = list.listIterator();
+ public static <T> void fill(List<? super T> list, T object) {
+ ListIterator it = list.listIterator();
while (it.hasNext()) {
it.next();
it.set(object);
@@ -1481,15 +1482,15 @@
* when an element in the Collection does not implement
* Comparable or elements cannot be compared to each other
*/
- public static Object max(Collection collection) {
- Iterator it = collection.iterator();
- Comparable max = (Comparable) it.next();
+ public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> collection) {
+ Iterator<? extends T> it = collection.iterator();
+ T max = it.next();
while (it.hasNext()) {
- Object next = it.next();
+ T next = it.next();
if (max.compareTo(next) < 0)
- max = (Comparable) next;
+ max = next;
}
- return max;
+ return (T)max;
}
/**
@@ -1506,11 +1507,11 @@
* when elements in the Collection cannot be compared to each
* other using the Comparator
*/
- public static Object max(Collection collection, Comparator comparator) {
- Iterator it = collection.iterator();
- Object max = it.next();
+ public static <T> T max(Collection<? extends T> collection, Comparator<? super T> comparator) {
+ Iterator<? extends T> it = collection.iterator();
+ T max = it.next();
while (it.hasNext()) {
- Object next = it.next();
+ T next = it.next();
if (comparator.compare(max, next) < 0)
max = next;
}
@@ -2358,7 +2359,7 @@
* contains one or more null elements and c doesn't support null
* elements
*/
- public static boolean addAll(Collection c, Object[] a) {
+ public static <T> boolean addAll(Collection<? super T> c, T... a) {
boolean modified = false;
for (int i = 0; i < a.length; i++) {
modified |= c.add(a[i]);