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.1 by dl, Tue Dec 28 12:14:07 2004 UTC vs.
Revision 1.5 by dl, Tue Mar 22 16:48:32 2005 UTC

# Line 61 | Line 61 | package java.util;
61   * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
62   * Therefore, it would be wrong to write a program that depended on this
63   * exception for its correctness:   <i>the fail-fast behavior of iterators
64 < * should be used only to detect bugs.</i><p>
64 > * should be used only to detect bugs.</i>
65   *
66   * <p>All <tt>Map.Entry</tt> pairs returned by methods in this class
67   * and its views represent snapshots of mappings at the time they were
# Line 203 | Line 203 | public class TreeMap<K,V>
203       *            specified key.
204       * @throws ClassCastException if the key cannot be compared with the keys
205       *                  currently in the map.
206 <     * @throws NullPointerException key is <tt>null</tt> and this map uses
206 >     * @throws NullPointerException if key is <tt>null</tt> and this map uses
207       *                  natural ordering, or its comparator does not tolerate
208       *            <tt>null</tt> keys.
209       */
# Line 260 | Line 260 | public class TreeMap<K,V>
260       * @param key key whose associated value is to be returned.
261       * @return the value to which this map maps the specified key, or
262       *               <tt>null</tt> if the map contains no mapping for the key.
263 <     * @throws    ClassCastException key cannot be compared with the keys
263 >     * @throws    ClassCastException if key cannot be compared with the keys
264       *                  currently in the map.
265 <     * @throws NullPointerException key is <tt>null</tt> and this map uses
265 >     * @throws NullPointerException if key is <tt>null</tt> and this map uses
266       *                  natural ordering, or its comparator does not tolerate
267       *                  <tt>null</tt> keys.
268       *
# Line 343 | Line 343 | public class TreeMap<K,V>
343       *                does not contain an entry for the key.
344       * @throws ClassCastException if the key cannot be compared with the keys
345       *                  currently in the map.
346 <     * @throws NullPointerException key is <tt>null</tt> and this map uses
346 >     * @throws NullPointerException if key is <tt>null</tt> and this map uses
347       *                  natural order, or its comparator does not tolerate *
348       *                  <tt>null</tt> keys.
349       */
# Line 546 | Line 546 | public class TreeMap<K,V>
546       *         if there was no mapping for key.  A <tt>null</tt> return can
547       *         also indicate that the map previously associated <tt>null</tt>
548       *         with the specified key.
549 <     * @throws    ClassCastException key cannot be compared with the keys
549 >     * @throws    ClassCastException if key cannot be compared with the keys
550       *            currently in the map.
551 <     * @throws NullPointerException key is <tt>null</tt> and this map uses
551 >     * @throws NullPointerException if key is <tt>null</tt> and this map uses
552       *         natural order, or its comparator does not tolerate
553       *         <tt>null</tt> keys.
554       */
# Line 596 | Line 596 | public class TreeMap<K,V>
596       *         also indicate that the map previously associated
597       *         <tt>null</tt> with the specified key.
598       *
599 <     * @throws    ClassCastException key cannot be compared with the keys
599 >     * @throws    ClassCastException if key cannot be compared with the keys
600       *            currently in the map.
601 <     * @throws NullPointerException key is <tt>null</tt> and this map uses
601 >     * @throws NullPointerException if key is <tt>null</tt> and this map uses
602       *         natural order, or its comparator does not tolerate
603       *         <tt>null</tt> keys.
604       */
# Line 664 | Line 664 | public class TreeMap<K,V>
664       */
665      public Map.Entry<K,V> firstEntry() {
666          Entry<K,V> e = getFirstEntry();
667 <        return (e == null)? null : new SnapshotEntry(e);
667 >        return (e == null)? null : new AbstractMap.SimpleImmutableEntry(e);
668      }
669  
670      /**
# Line 678 | Line 678 | public class TreeMap<K,V>
678       */
679      public Map.Entry<K,V> lastEntry() {
680          Entry<K,V> e = getLastEntry();
681 <        return (e == null)? null : new SnapshotEntry(e);
681 >        return (e == null)? null : new AbstractMap.SimpleImmutableEntry(e);
682      }
683  
684      /**
# Line 692 | Line 692 | public class TreeMap<K,V>
692          Entry<K,V> p = getFirstEntry();
693          if (p == null)
694              return null;
695 <        Map.Entry result = new SnapshotEntry(p);
695 >        Map.Entry result = new AbstractMap.SimpleImmutableEntry(p);
696          deleteEntry(p);
697          return result;
698      }
# Line 708 | Line 708 | public class TreeMap<K,V>
708          Entry<K,V> p = getLastEntry();
709          if (p == null)
710              return null;
711 <        Map.Entry result = new SnapshotEntry(p);
711 >        Map.Entry result = new AbstractMap.SimpleImmutableEntry(p);
712          deleteEntry(p);
713          return result;
714      }
# Line 723 | Line 723 | public class TreeMap<K,V>
723       * <tt>null</tt> if there is no such Entry.
724       * @throws ClassCastException if key cannot be compared with the
725       * keys currently in the map.
726 <     * @throws NullPointerException key is <tt>null</tt> and this map uses
726 >     * @throws NullPointerException if key is <tt>null</tt> and this map uses
727       *         natural order, or its comparator does not tolerate
728       *         <tt>null</tt> keys.
729       */
730      public Map.Entry<K,V> ceilingEntry(K key) {
731          Entry<K,V> e = getCeilingEntry(key);
732 <        return (e == null)? null : new SnapshotEntry(e);
732 >        return (e == null)? null : new AbstractMap.SimpleImmutableEntry(e);
733      }
734  
735  
# Line 742 | Line 742 | public class TreeMap<K,V>
742       * if there is no such key.
743       * @throws ClassCastException if key cannot be compared with the keys
744       *            currently in the map.
745 <     * @throws NullPointerException key is <tt>null</tt> and this map uses
745 >     * @throws NullPointerException if key is <tt>null</tt> and this map uses
746       *         natural order, or its comparator does not tolerate
747       *         <tt>null</tt> keys.
748       */
# Line 763 | Line 763 | public class TreeMap<K,V>
763       * if there is no such Entry.
764       * @throws ClassCastException if key cannot be compared with the keys
765       *            currently in the map.
766 <     * @throws NullPointerException key is <tt>null</tt> and this map uses
766 >     * @throws NullPointerException if key is <tt>null</tt> and this map uses
767       *         natural order, or its comparator does not tolerate
768       *         <tt>null</tt> keys.
769       */
770      public Map.Entry<K,V> floorEntry(K key) {
771          Entry<K,V> e = getFloorEntry(key);
772 <        return (e == null)? null : new SnapshotEntry(e);
772 >        return (e == null)? null : new AbstractMap.SimpleImmutableEntry(e);
773      }
774  
775      /**
# Line 782 | Line 782 | public class TreeMap<K,V>
782       * such key.
783       * @throws ClassCastException if key cannot be compared with the keys
784       *            currently in the map.
785 <     * @throws NullPointerException key is <tt>null</tt> and this map uses
785 >     * @throws NullPointerException if key is <tt>null</tt> and this map uses
786       *         natural order, or its comparator does not tolerate
787       *         <tt>null</tt> keys.
788       */
# Line 801 | Line 801 | public class TreeMap<K,V>
801       * <tt>null</tt> if there is no such Entry.
802       * @throws ClassCastException if key cannot be compared with the keys
803       *            currently in the map.
804 <     * @throws NullPointerException key is <tt>null</tt> and this map uses
804 >     * @throws NullPointerException if key is <tt>null</tt> and this map uses
805       *         natural order, or its comparator does not tolerate
806       *         <tt>null</tt> keys.
807       */
808      public Map.Entry<K,V> higherEntry(K key) {
809          Entry<K,V> e = getHigherEntry(key);
810 <        return (e == null)? null : new SnapshotEntry(e);
810 >        return (e == null)? null : new AbstractMap.SimpleImmutableEntry(e);
811      }
812  
813      /**
# Line 819 | Line 819 | public class TreeMap<K,V>
819       * <tt>null</tt> if there is no such key.
820       * @throws ClassCastException if key cannot be compared with the keys
821       *            currently in the map.
822 <     * @throws NullPointerException key is <tt>null</tt> and this map uses
822 >     * @throws NullPointerException if key is <tt>null</tt> and this map uses
823       *         natural order, or its comparator does not tolerate
824       *         <tt>null</tt> keys.
825       */
# Line 838 | Line 838 | public class TreeMap<K,V>
838       * key, or <tt>null</tt> if there is no such Entry.
839       * @throws ClassCastException if key cannot be compared with the keys
840       *            currently in the map.
841 <     * @throws NullPointerException key is <tt>null</tt> and this map uses
841 >     * @throws NullPointerException if key is <tt>null</tt> and this map uses
842       *         natural order, or its comparator does not tolerate
843       *         <tt>null</tt> keys.
844       */
845      public Map.Entry<K,V> lowerEntry(K key) {
846          Entry<K,V> e =  getLowerEntry(key);
847 <        return (e == null)? null : new SnapshotEntry(e);
847 >        return (e == null)? null : new AbstractMap.SimpleImmutableEntry(e);
848      }
849  
850      /**
# Line 856 | Line 856 | public class TreeMap<K,V>
856       * key, or <tt>null</tt> if there is no such key.
857       * @throws ClassCastException if key cannot be compared with the keys
858       *            currently in the map.
859 <     * @throws NullPointerException key is <tt>null</tt> and this map uses
859 >     * @throws NullPointerException if key is <tt>null</tt> and this map uses
860       *         natural order, or its comparator does not tolerate
861       *         <tt>null</tt> keys.
862       */
# Line 1026 | Line 1026 | public class TreeMap<K,V>
1026  
1027      /**
1028       * Returns a set view of the mappings contained in this map.  The
1029 <     * set's iterator returns the mappings in descrending key order.
1029 >     * set's iterator returns the mappings in descending key order.
1030       * Each element in the returned set is a <tt>Map.Entry</tt>.  The
1031       * set is backed by this map, so changes to this map are reflected
1032       * in the set, and vice-versa.  The set supports element removal,
# Line 1078 | Line 1078 | public class TreeMap<K,V>
1078      /**
1079       * Returns a view of the portion of this map whose keys range from
1080       * <tt>fromKey</tt>, inclusive, to <tt>toKey</tt>, exclusive.  (If
1081 <     * <tt>fromKey</tt> and <tt>toKey</tt> are equal, the returned sorted map
1082 <     * is empty.)  The returned sorted map is backed by this map, so changes
1083 <     * in the returned sorted map are reflected in this map, and vice-versa.
1084 <     * The returned sorted map supports all optional map operations.<p>
1081 >     * <tt>fromKey</tt> and <tt>toKey</tt> are equal, the returned
1082 >     * navigable map is empty.)  The returned navigable map is backed
1083 >     * by this map, so changes in the returned navigable map are
1084 >     * reflected in this map, and vice-versa.  The returned navigable
1085 >     * map supports all optional map operations.<p>
1086       *
1087 <     * The sorted map returned by this method will throw an
1087 >     * The navigable map returned by this method will throw an
1088       * <tt>IllegalArgumentException</tt> if the user attempts to insert a key
1089       * less than <tt>fromKey</tt> or greater than or equal to
1090       * <tt>toKey</tt>.<p>
# Line 1091 | Line 1092 | public class TreeMap<K,V>
1092       * Note: this method always returns a <i>half-open range</i> (which
1093       * includes its low endpoint but not its high endpoint).  If you need a
1094       * <i>closed range</i> (which includes both endpoints), and the key type
1095 <     * allows for calculation of the successor a given key, merely request the
1095 >     * allows for calculation of the successor of a given key, merely request the
1096       * subrange from <tt>lowEndpoint</tt> to <tt>successor(highEndpoint)</tt>.
1097 <     * For example, suppose that <tt>m</tt> is a sorted map whose keys are
1097 >     * For example, suppose that <tt>m</tt> is a navigable map whose keys are
1098       * strings.  The following idiom obtains a view containing all of the
1099       * key-value mappings in <tt>m</tt> whose keys are between <tt>low</tt>
1100       * and <tt>high</tt>, inclusive:
1101 <     *             <pre>    NavigableMap sub = m.submap(low, high+"\0");</pre>
1101 >     * <pre>  NavigableMap sub = m.navigableSubMap(low, high+"\0");</pre>
1102       * A similar technique can be used to generate an <i>open range</i> (which
1103       * contains neither endpoint).  The following idiom obtains a view
1104       * containing all of the key-value mappings in <tt>m</tt> whose keys are
1105       * between <tt>low</tt> and <tt>high</tt>, exclusive:
1106 <     *             <pre>    NavigableMap sub = m.subMap(low+"\0", high);</pre>
1106 >     * <pre>  NavigableMap sub = m.navigableSubMap(low+"\0", high);</pre>
1107       *
1108       * @param fromKey low endpoint (inclusive) of the subMap.
1109       * @param toKey high endpoint (exclusive) of the subMap.
# Line 1119 | Line 1120 | public class TreeMap<K,V>
1120       *               <tt>null</tt> and this map uses natural order, or its
1121       *               comparator does not tolerate <tt>null</tt> keys.
1122       */
1123 <    public NavigableMap<K,V> subMap(K fromKey, K toKey) {
1123 >    public NavigableMap<K,V> navigableSubMap(K fromKey, K toKey) {
1124          return new SubMap(fromKey, toKey);
1125      }
1126  
1127 +
1128      /**
1129       * Returns a view of the portion of this map whose keys are strictly less
1130 <     * than <tt>toKey</tt>.  The returned sorted map is backed by this map, so
1131 <     * changes in the returned sorted map are reflected in this map, and
1132 <     * vice-versa.  The returned sorted map supports all optional map
1130 >     * than <tt>toKey</tt>.  The returned navigable map is backed by this map, so
1131 >     * changes in the returned navigable map are reflected in this map, and
1132 >     * vice-versa.  The returned navigable map supports all optional map
1133       * operations.<p>
1134       *
1135 <     * The sorted map returned by this method will throw an
1135 >     * The navigable map returned by this method will throw an
1136       * <tt>IllegalArgumentException</tt> if the user attempts to insert a key
1137       * greater than or equal to <tt>toKey</tt>.<p>
1138       *
1139       * Note: this method always returns a view that does not contain its
1140       * (high) endpoint.  If you need a view that does contain this endpoint,
1141 <     * and the key type allows for calculation of the successor a given key,
1141 >     * and the key type allows for calculation of the successor of a given key,
1142       * merely request a headMap bounded by <tt>successor(highEndpoint)</tt>.
1143 <     * For example, suppose that suppose that <tt>m</tt> is a sorted map whose
1143 >     * For example, suppose that suppose that <tt>m</tt> is a navigable map whose
1144       * keys are strings.  The following idiom obtains a view containing all of
1145       * the key-value mappings in <tt>m</tt> whose keys are less than or equal
1146       * to <tt>high</tt>:
# Line 1160 | Line 1162 | public class TreeMap<K,V>
1162       *               this map uses natural order, or its comparator does not
1163       *               tolerate <tt>null</tt> keys.
1164       */
1165 <    public NavigableMap<K,V> headMap(K toKey) {
1165 >    public NavigableMap<K,V> navigableHeadMap(K toKey) {
1166          return new SubMap(toKey, true);
1167      }
1168  
1169      /**
1170       * Returns a view of the portion of this map whose keys are greater than
1171 <     * or equal to <tt>fromKey</tt>.  The returned sorted map is backed by
1172 <     * this map, so changes in the returned sorted map are reflected in this
1173 <     * map, and vice-versa.  The returned sorted map supports all optional map
1171 >     * or equal to <tt>fromKey</tt>.  The returned navigable map is backed by
1172 >     * this map, so changes in the returned navigable map are reflected in this
1173 >     * map, and vice-versa.  The returned navigable map supports all optional map
1174       * operations.<p>
1175       *
1176 <     * The sorted map returned by this method will throw an
1176 >     * The navigable map returned by this method will throw an
1177       * <tt>IllegalArgumentException</tt> if the user attempts to insert a key
1178       * less than <tt>fromKey</tt>.<p>
1179       *
1180       * Note: this method always returns a view that contains its (low)
1181       * endpoint.  If you need a view that does not contain this endpoint, and
1182 <     * the element type allows for calculation of the successor a given value,
1182 >     * the element type allows for calculation of the successor of a given value,
1183       * merely request a tailMap bounded by <tt>successor(lowEndpoint)</tt>.
1184 <     * For example, suppose that <tt>m</tt> is a sorted map whose keys
1184 >     * For example, suppose that <tt>m</tt> is a navigable map whose keys
1185       * are strings.  The following idiom obtains a view containing
1186       * all of the key-value mappings in <tt>m</tt> whose keys are strictly
1187       * greater than <tt>low</tt>: <pre>
# Line 1199 | Line 1201 | public class TreeMap<K,V>
1201       *               this map uses natural order, or its comparator does not
1202       *               tolerate <tt>null</tt> keys.
1203       */
1204 <    public NavigableMap<K,V> tailMap(K fromKey) {
1204 >    public NavigableMap<K,V> navigableTailMap(K fromKey) {
1205 >        return new SubMap(fromKey, false);
1206 >    }
1207 >
1208 >    /**
1209 >     * Equivalent to <tt>navigableSubMap</tt> but with a return
1210 >     * type conforming to the <tt>SortedMap</tt> interface.
1211 >     * @param fromKey low endpoint (inclusive) of the subMap.
1212 >     * @param toKey high endpoint (exclusive) of the subMap.
1213 >     *
1214 >     * @return a view of the portion of this map whose keys range from
1215 >     *                <tt>fromKey</tt>, inclusive, to <tt>toKey</tt>, exclusive.
1216 >     *
1217 >     * @throws ClassCastException if <tt>fromKey</tt> and <tt>toKey</tt>
1218 >     *         cannot be compared to one another using this map's comparator
1219 >     *         (or, if the map has no comparator, using natural ordering).
1220 >     * @throws IllegalArgumentException if <tt>fromKey</tt> is greater than
1221 >     *         <tt>toKey</tt>.
1222 >     * @throws NullPointerException if <tt>fromKey</tt> or <tt>toKey</tt> is
1223 >     *               <tt>null</tt> and this map uses natural order, or its
1224 >     *               comparator does not tolerate <tt>null</tt> keys.
1225 >     */
1226 >    public SortedMap<K,V> subMap(K fromKey, K toKey) {
1227 >        return new SubMap(fromKey, toKey);
1228 >    }
1229 >
1230 >
1231 >    /**
1232 >     * Equivalent to <tt>navigableHeadMap</tt> but with a return
1233 >     * type conforming to the <tt>SortedMap</tt> interface.
1234 >     *
1235 >     * @param toKey high endpoint (exclusive) of the headMap.
1236 >     * @return a view of the portion of this map whose keys are strictly
1237 >     *                less than <tt>toKey</tt>.
1238 >     *
1239 >     * @throws ClassCastException if <tt>toKey</tt> is not compatible
1240 >     *         with this map's comparator (or, if the map has no comparator,
1241 >     *         if <tt>toKey</tt> does not implement <tt>Comparable</tt>).
1242 >     * @throws IllegalArgumentException if this map is itself a subMap,
1243 >     *         headMap, or tailMap, and <tt>toKey</tt> is not within the
1244 >     *         specified range of the subMap, headMap, or tailMap.
1245 >     * @throws NullPointerException if <tt>toKey</tt> is <tt>null</tt> and
1246 >     *               this map uses natural order, or its comparator does not
1247 >     *               tolerate <tt>null</tt> keys.
1248 >     */
1249 >    public SortedMap<K,V> headMap(K toKey) {
1250 >        return new SubMap(toKey, true);
1251 >    }
1252 >
1253 >    /**
1254 >     * Equivalent to <tt>navigableTailMap</tt> but with a return
1255 >     * type conforming to the <tt>SortedMap</tt> interface.
1256 >     *
1257 >     * @param fromKey low endpoint (inclusive) of the tailMap.
1258 >     * @return a view of the portion of this map whose keys are greater
1259 >     *                than or equal to <tt>fromKey</tt>.
1260 >     * @throws ClassCastException if <tt>fromKey</tt> is not compatible
1261 >     *         with this map's comparator (or, if the map has no comparator,
1262 >     *         if <tt>fromKey</tt> does not implement <tt>Comparable</tt>).
1263 >     * @throws IllegalArgumentException if this map is itself a subMap,
1264 >     *         headMap, or tailMap, and <tt>fromKey</tt> is not within the
1265 >     *         specified range of the subMap, headMap, or tailMap.
1266 >     * @throws NullPointerException if <tt>fromKey</tt> is <tt>null</tt> and
1267 >     *               this map uses natural order, or its comparator does not
1268 >     *               tolerate <tt>null</tt> keys.
1269 >     */
1270 >    public SortedMap<K,V> tailMap(K fromKey) {
1271          return new SubMap(fromKey, false);
1272      }
1273  
# Line 1308 | Line 1376 | public class TreeMap<K,V>
1376                  getFirstEntry() : getCeilingEntry(fromKey);
1377              if (e == null || (!fromStart && compare(e.key, fromKey) < 0))
1378                  return null;
1379 <            Map.Entry result = new SnapshotEntry(e);
1379 >            Map.Entry result = new AbstractMap.SimpleImmutableEntry(e);
1380              deleteEntry(e);
1381              return result;
1382          }
# Line 1318 | Line 1386 | public class TreeMap<K,V>
1386                  getLastEntry() : getLowerEntry(toKey);
1387              if (e == null || (!toEnd && compare(e.key, toKey) >= 0))
1388                  return null;
1389 <            Map.Entry result = new SnapshotEntry(e);
1389 >            Map.Entry result = new AbstractMap.SimpleImmutableEntry(e);
1390              deleteEntry(e);
1391              return result;
1392          }
# Line 1333 | Line 1401 | public class TreeMap<K,V>
1401  
1402          public Map.Entry<K,V> ceilingEntry(K key) {
1403              TreeMap.Entry<K,V> e = subceiling(key);
1404 <            return e == null? null : new SnapshotEntry(e);
1404 >            return e == null? null : new AbstractMap.SimpleImmutableEntry(e);
1405          }
1406  
1407          public K ceilingKey(K key) {
# Line 1352 | Line 1420 | public class TreeMap<K,V>
1420  
1421          public Map.Entry<K,V> higherEntry(K key) {
1422              TreeMap.Entry<K,V> e = subhigher(key);
1423 <            return e == null? null : new SnapshotEntry(e);
1423 >            return e == null? null : new AbstractMap.SimpleImmutableEntry(e);
1424          }
1425  
1426          public K higherKey(K key) {
# Line 1370 | Line 1438 | public class TreeMap<K,V>
1438  
1439          public Map.Entry<K,V> floorEntry(K key) {
1440              TreeMap.Entry<K,V> e = subfloor(key);
1441 <            return e == null? null : new SnapshotEntry(e);
1441 >            return e == null? null : new AbstractMap.SimpleImmutableEntry(e);
1442          }
1443  
1444          public K floorKey(K key) {
# Line 1388 | Line 1456 | public class TreeMap<K,V>
1456  
1457          public Map.Entry<K,V> lowerEntry(K key) {
1458              TreeMap.Entry<K,V> e = sublower(key);
1459 <            return e == null? null : new SnapshotEntry(e);
1459 >            return e == null? null : new AbstractMap.SimpleImmutableEntry(e);
1460          }
1461  
1462          public K lowerKey(K key) {
# Line 1497 | Line 1565 | public class TreeMap<K,V>
1565          }
1566  
1567  
1568 <        public NavigableMap<K,V> subMap(K fromKey, K toKey) {
1568 >        public NavigableMap<K,V> navigableSubMap(K fromKey, K toKey) {
1569              if (!inRange2(fromKey))
1570                  throw new IllegalArgumentException("fromKey out of range");
1571              if (!inRange2(toKey))
# Line 1505 | Line 1573 | public class TreeMap<K,V>
1573              return new SubMap(fromKey, toKey);
1574          }
1575  
1576 <        public NavigableMap<K,V> headMap(K toKey) {
1576 >        public NavigableMap<K,V> navigableHeadMap(K toKey) {
1577              if (!inRange2(toKey))
1578                  throw new IllegalArgumentException("toKey out of range");
1579              return new SubMap(fromStart, fromKey, false, toKey);
1580          }
1581  
1582 <        public NavigableMap<K,V> tailMap(K fromKey) {
1582 >        public NavigableMap<K,V> navigableTailMap(K fromKey) {
1583              if (!inRange2(fromKey))
1584                  throw new IllegalArgumentException("fromKey out of range");
1585              return new SubMap(false, fromKey, toEnd, toKey);
1586          }
1587  
1588 +
1589 +        public SortedMap<K,V> subMap(K fromKey, K toKey) {
1590 +            return navigableSubMap(fromKey, toKey);
1591 +        }
1592 +
1593 +        public SortedMap<K,V> headMap(K toKey) {
1594 +            return navigableHeadMap(toKey);
1595 +        }
1596 +
1597 +        public SortedMap<K,V> tailMap(K fromKey) {
1598 +            return navigableTailMap(fromKey);
1599 +        }
1600 +
1601          private boolean inRange(K key) {
1602              return (fromStart || compare(key, fromKey) >= 0) &&
1603                     (toEnd     || compare(key, toKey)   <  0);
# Line 2260 | Line 2341 | public class TreeMap<K,V>
2341          return level;
2342      }
2343  
2263
2264    /**
2265     * Entry holding a snapshot of a key-value pair
2266     */
2267    static class SnapshotEntry<K,V> implements Map.Entry<K,V> {
2268        final K key;
2269        final V value;
2270
2271        public SnapshotEntry(Entry<K,V> e) {
2272            this.key   = e.getKey();
2273            this.value = e.getValue();
2274        }
2275
2276        public K getKey() {
2277            return key;
2278        }
2279
2280        public V getValue() {
2281            return value;
2282        }
2283
2284        /**
2285         * Always fails, throwing <tt>UnsupportedOperationException</tt>.
2286         * @throws UnsupportedOperationException always.
2287         */
2288        public V setValue(V value) {
2289            throw new UnsupportedOperationException();
2290        }
2291
2292        public boolean equals(Object o) {
2293            if (!(o instanceof Map.Entry))
2294                return false;
2295            Map.Entry e = (Map.Entry)o;
2296            return eq(key, e.getKey()) && eq(value, e.getValue());
2297        }
2298
2299        public int hashCode() {
2300            return ((key   == null)   ? 0 :   key.hashCode()) ^
2301                   ((value == null)   ? 0 : value.hashCode());
2302        }
2303
2304        public String toString() {
2305            return key + "=" + value;
2306        }
2307
2308        private static boolean eq(Object o1, Object o2) {
2309            return (o1 == null ? o2 == null : o1.equals(o2));
2310        }
2311    }
2312
2344   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines