+2001-02-15 Bryce McKinlay <bryce@albatross.co.nz>
+
+ * 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.
+
2001-02-14 Bryce McKinlay <bryce@albatross.co.nz>
* java/util/TreeMap.java: New file.
// Create a minimal implementation of List
return new AbstractList()
{
-
public int size()
{
return n;
}
}
+ 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;
}
/**
* 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
public Object clone()
{
TreeSet copy = new TreeSet();
- try
- {
- copy.map = (TreeMap) map.clone();
- }
- catch (CloneNotSupportedException ex)
- {
- }
-
+ copy.map = (SortedMap) ((TreeMap) map).clone();
return copy;
}