diff options
author | Bryce McKinlay <bryce@albatross.co.nz> | 2001-02-15 03:59:57 +0000 |
---|---|---|
committer | Bryce McKinlay <bryce@gcc.gnu.org> | 2001-02-15 03:59:57 +0000 |
commit | 505ce70d3ff1a66b476ec41109deb68ac0d44fde (patch) | |
tree | a50576b5ec7a46b8047189b60ad1a2b5cbaafc1a /libjava/java/util | |
parent | 78e3e6aca36855e1726a9d41b7dbd7c7f419dc4b (diff) | |
download | gcc-505ce70d3ff1a66b476ec41109deb68ac0d44fde.zip gcc-505ce70d3ff1a66b476ec41109deb68ac0d44fde.tar.gz gcc-505ce70d3ff1a66b476ec41109deb68ac0d44fde.tar.bz2 |
TreeSet.java (clone): Call TreeMap.clone(), not Object.clone().
* java/util/TreeSet.java (clone): Call TreeMap.clone(), not
Object.clone().
* java/util/Collections.java (ReverseComparator): New static class.
(reverseOrder): Return static instance of ReverseComparator.
From-SVN: r39705
Diffstat (limited to 'libjava/java/util')
-rw-r--r-- | libjava/java/util/Collections.java | 20 | ||||
-rw-r--r-- | libjava/java/util/TreeSet.java | 13 |
2 files changed, 14 insertions, 19 deletions
diff --git a/libjava/java/util/Collections.java b/libjava/java/util/Collections.java index 9035e670..74efdec 100644 --- a/libjava/java/util/Collections.java +++ b/libjava/java/util/Collections.java @@ -447,7 +447,6 @@ public class Collections // Create a minimal implementation of List return new AbstractList() { - public int size() { return n; @@ -487,22 +486,25 @@ public class Collections } } + static class ReverseComparator implements Comparator, Serializable + { + public int compare(Object a, Object b) + { + return -((Comparable) a).compareTo(b); + } + } + + static ReverseComparator rcInstance = new ReverseComparator(); + /** * Get a comparator that implements the reverse of natural ordering. This is * intended to make it easy to sort into reverse order, by simply passing * Collections.reverseOrder() to the sort method. The return value of this * method is Serializable. */ - // The return value isn't Serializable, because the spec is broken. public static Comparator reverseOrder() { - return new Comparator() - { - public int compare(Object a, Object b) - { - return -((Comparable) a).compareTo(b); - } - }; + return rcInstance; } /** diff --git a/libjava/java/util/TreeSet.java b/libjava/java/util/TreeSet.java index 36224aa..070ca26 100644 --- a/libjava/java/util/TreeSet.java +++ b/libjava/java/util/TreeSet.java @@ -44,8 +44,8 @@ import java.io.ObjectOutputStream; * TreeSet is a part of the JDK1.2 Collections API. * * @author Jon Zeppieri - * @version $Revision: 1.7 $ - * @modified $Id: TreeSet.java,v 1.7 2000/10/26 10:19:01 bryce Exp $ + * @version $Revision: 1.1 $ + * @modified $Id: TreeSet.java,v 1.1 2001/02/14 04:44:21 bryce Exp $ */ public class TreeSet extends AbstractSet @@ -158,14 +158,7 @@ public class TreeSet extends AbstractSet public Object clone() { TreeSet copy = new TreeSet(); - try - { - copy.map = (TreeMap) map.clone(); - } - catch (CloneNotSupportedException ex) - { - } - + copy.map = (SortedMap) ((TreeMap) map).clone(); return copy; } |