API additions for compatibility with harmony's java.util package

This commit is contained in:
Zsombor Gegesy
2010-08-15 14:01:33 +02:00
parent fc2c6d5100
commit 5dadac2cb8
9 changed files with 93 additions and 4 deletions

View File

@ -11,6 +11,7 @@
package java.util;
public class Collections {
private Collections() { }
public static void shuffle(List list, Random random) {
@ -84,6 +85,10 @@ public class Collections {
return new IteratorEnumeration<T> (c.iterator());
}
public static <T> Comparator<T> reverseOrder(Comparator<T> cmp) {
return new ReverseComparator<T>(cmp);
}
static class IteratorEnumeration<T> implements Enumeration<T> {
private final Iterator<T> it;
@ -379,4 +384,20 @@ public class Collections {
it.remove();
}
}
private static final class ReverseComparator<T> implements Comparator<T> {
Comparator<T> cmp;
public ReverseComparator(Comparator<T> cmp) {
this.cmp = cmp;
}
@Override
public int compare(T o1, T o2) {
return - cmp.compare(o1, o2);
}
}
}