ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/TreeMap.java
(Generate patch)

Comparing jsr166/src/main/java/util/TreeMap.java (file contents):
Revision 1.8 by dl, Sat Apr 2 11:29:42 2005 UTC vs.
Revision 1.13 by dl, Wed May 11 11:16:08 2005 UTC

# Line 1 | Line 1
1   /*
2   * %W% %E%
3   *
4 < * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
4 > * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
5   * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6   */
7  
# Line 351 | Line 351 | public class TreeMap<K,V>
351          // Offload comparator-based version for sake of performance
352          if (comparator != null)
353              return getEntryUsingComparator(key);
354 <        Comparable<K> k = (Comparable<K>) key;
354 >        Comparable<? super K> k = (Comparable<? super K>) key;
355          Entry<K,V> p = root;
356          while (p != null) {
357              int cmp = k.compareTo(p.key);
# Line 556 | Line 556 | public class TreeMap<K,V>
556          Entry<K,V> t = root;
557  
558          if (t == null) {
559 +            if (key == null) {
560 +                if (comparator == null)
561 +                    throw new NullPointerException();
562 +                comparator.compare(key, key);
563 +            }
564              incrementSize();
565              root = new Entry<K,V>(key, value, null);
566              return null;
# Line 874 | Line 879 | public class TreeMap<K,V>
879      private transient Set<Map.Entry<K,V>> descendingEntrySet = null;
880      private transient Set<K> descendingKeySet = null;
881  
877    transient Set<K> keySet = null;        // XXX remove when integrated
878    transient Collection<V> values = null; // XXX remove when integrated
879
882      /**
883       * Returns a Set view of the keys contained in this map.  The set's
884       * iterator will return the keys in ascending order.  The set is backed by
# Line 1341 | Line 1343 | public class TreeMap<K,V>
1343              TreeMap.Entry<K,V> e = fromStart ? getFirstEntry() : getCeilingEntry(fromKey);
1344              K first = key(e);
1345              if (!toEnd && compare(first, toKey) >= 0)
1346 <                throw(new NoSuchElementException());
1346 >                throw new NoSuchElementException();
1347              return first;
1348          }
1349  
# Line 1349 | Line 1351 | public class TreeMap<K,V>
1351              TreeMap.Entry<K,V> e = toEnd ? getLastEntry() : getLowerEntry(toKey);
1352              K last = key(e);
1353              if (!fromStart && compare(last, fromKey) < 0)
1354 <                throw(new NoSuchElementException());
1354 >                throw new NoSuchElementException();
1355              return last;
1356          }
1357  
# Line 1763 | Line 1765 | public class TreeMap<K,V>
1765       * Compares two keys using the correct comparison method for this TreeMap.
1766       */
1767      private int compare(K k1, K k2) {
1768 <        return (comparator==null ? ((Comparable</*-*/K>)k1).compareTo(k2)
1769 <                                 : comparator.compare((K)k1, (K)k2));
1768 >        return comparator==null ? ((Comparable<? super K>)k1).compareTo(k2)
1769 >                                : comparator.compare(k1, k2);
1770      }
1771  
1772      /**
# Line 2196 | Line 2198 | public class TreeMap<K,V>
2198      }
2199  
2200      /** Intended to be called only from TreeSet.addAll **/
2201 <    void addAllForTreeSet(SortedSet<Map.Entry<K,V>> set, V defaultVal) {
2201 >    void addAllForTreeSet(SortedSet<? extends K> set, V defaultVal) {
2202          try {
2203              buildFromSorted(set.size(), set.iterator(), null, defaultVal);
2204          } catch (java.io.IOException cannotHappen) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines