1 |
|
/* |
2 |
|
* %W% %E% |
3 |
|
* |
4 |
< |
* Copyright 2006 Sun Microsystems, Inc. All rights reserved. |
4 |
> |
* Copyright 2007 Sun Microsystems, Inc. All rights reserved. |
5 |
|
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. |
6 |
|
*/ |
7 |
|
|
68 |
|
* associated map using <tt>put</tt>.) |
69 |
|
* |
70 |
|
* <p>This class is a member of the |
71 |
< |
* <a href="{@docRoot}/../guide/collections/index.html"> |
71 |
> |
* <a href="{@docRoot}/../technotes/guides/collections/index.html"> |
72 |
|
* Java Collections Framework</a>. |
73 |
|
* |
74 |
|
* @param <K> the type of keys maintained by this map |
109 |
|
*/ |
110 |
|
private transient int modCount = 0; |
111 |
|
|
112 |
– |
private void incrementSize() { modCount++; size++; } |
113 |
– |
private void decrementSize() { modCount++; size--; } |
114 |
– |
|
112 |
|
/** |
113 |
|
* Constructs a new, empty tree map, using the natural ordering of its |
114 |
|
* keys. All keys inserted into the map must implement the {@link |
223 |
|
* @since 1.2 |
224 |
|
*/ |
225 |
|
public boolean containsValue(Object value) { |
226 |
< |
return (root==null ? false : |
227 |
< |
(value==null ? valueSearchNull(root) |
228 |
< |
: valueSearchNonNull(root, value))); |
229 |
< |
} |
233 |
< |
|
234 |
< |
private boolean valueSearchNull(Entry n) { |
235 |
< |
if (n.value == null) |
236 |
< |
return true; |
237 |
< |
|
238 |
< |
// Check left and right subtrees for value |
239 |
< |
return (n.left != null && valueSearchNull(n.left)) || |
240 |
< |
(n.right != null && valueSearchNull(n.right)); |
241 |
< |
} |
242 |
< |
|
243 |
< |
private boolean valueSearchNonNull(Entry n, Object value) { |
244 |
< |
// Check this node for the value |
245 |
< |
if (value.equals(n.value)) |
246 |
< |
return true; |
247 |
< |
|
248 |
< |
// Check left and right subtrees for value |
249 |
< |
return (n.left != null && valueSearchNonNull(n.left, value)) || |
250 |
< |
(n.right != null && valueSearchNonNull(n.right, value)); |
226 |
> |
for (Entry<K,V> e = getFirstEntry(); e != null; e = successor(e)) |
227 |
> |
if (valEquals(value, e.value)) |
228 |
> |
return true; |
229 |
> |
return false; |
230 |
|
} |
231 |
|
|
232 |
|
/** |
340 |
|
* Version of getEntry using comparator. Split off from getEntry |
341 |
|
* for performance. (This is not worth doing for most methods, |
342 |
|
* that are less dependent on comparator performance, but is |
343 |
< |
* worthwhile for get and put.) |
343 |
> |
* worthwhile here.) |
344 |
|
*/ |
345 |
|
final Entry<K,V> getEntryUsingComparator(Object key) { |
346 |
|
K k = (K) key; |
347 |
|
Comparator<? super K> cpr = comparator; |
348 |
< |
Entry<K,V> p = root; |
349 |
< |
while (p != null) { |
350 |
< |
int cmp = cpr.compare(k, p.key); |
351 |
< |
if (cmp < 0) |
352 |
< |
p = p.left; |
353 |
< |
else if (cmp > 0) |
354 |
< |
p = p.right; |
355 |
< |
else |
356 |
< |
return p; |
348 |
> |
if (cpr != null) { |
349 |
> |
Entry<K,V> p = root; |
350 |
> |
while (p != null) { |
351 |
> |
int cmp = cpr.compare(k, p.key); |
352 |
> |
if (cmp < 0) |
353 |
> |
p = p.left; |
354 |
> |
else if (cmp > 0) |
355 |
> |
p = p.right; |
356 |
> |
else |
357 |
> |
return p; |
358 |
> |
} |
359 |
|
} |
360 |
|
return null; |
361 |
|
} |
490 |
|
} |
491 |
|
|
492 |
|
/** |
512 |
– |
* Returns the key corresponding to the specified Entry. |
513 |
– |
* @throws NoSuchElementException if the Entry is null |
514 |
– |
*/ |
515 |
– |
static <K> K key(Entry<K,?> e) { |
516 |
– |
if (e==null) |
517 |
– |
throw new NoSuchElementException(); |
518 |
– |
return e.key; |
519 |
– |
} |
520 |
– |
|
521 |
– |
/** |
493 |
|
* Associates the specified value with the specified key in this map. |
494 |
|
* If the map previously contained a mapping for the key, the old |
495 |
|
* value is replaced. |
508 |
|
* does not permit null keys |
509 |
|
*/ |
510 |
|
public V put(K key, V value) { |
540 |
– |
// Offload comparator-based version for sake of performance |
541 |
– |
if (comparator != null) |
542 |
– |
return putUsingComparator(key, value); |
543 |
– |
if (key == null) |
544 |
– |
throw new NullPointerException(); |
545 |
– |
Comparable<? super K> k = (Comparable<? super K>) key; |
546 |
– |
|
511 |
|
Entry<K,V> t = root; |
512 |
< |
while (t != null) { |
513 |
< |
int cmp = k.compareTo(t.key); |
514 |
< |
if (cmp == 0) { |
515 |
< |
return t.setValue(value); |
516 |
< |
} else if (cmp < 0) { |
517 |
< |
if (t.left != null) { |
512 |
> |
if (t == null) { |
513 |
> |
// TBD: |
514 |
> |
// 5045147: (coll) Adding null to an empty TreeSet should |
515 |
> |
// throw NullPointerException |
516 |
> |
// |
517 |
> |
// compare(key, key); // type check |
518 |
> |
root = new Entry<K,V>(key, value, null); |
519 |
> |
size = 1; |
520 |
> |
modCount++; |
521 |
> |
return null; |
522 |
> |
} |
523 |
> |
int cmp; |
524 |
> |
Entry<K,V> parent; |
525 |
> |
// split comparator and comparable paths |
526 |
> |
Comparator<? super K> cpr = comparator; |
527 |
> |
if (cpr != null) { |
528 |
> |
do { |
529 |
> |
parent = t; |
530 |
> |
cmp = cpr.compare(key, t.key); |
531 |
> |
if (cmp < 0) |
532 |
|
t = t.left; |
533 |
< |
} else { |
556 |
< |
incrementSize(); |
557 |
< |
fixAfterInsertion(t.left = new Entry<K,V>(key, value, t)); |
558 |
< |
return null; |
559 |
< |
} |
560 |
< |
} else { // cmp > 0 |
561 |
< |
if (t.right != null) { |
533 |
> |
else if (cmp > 0) |
534 |
|
t = t.right; |
535 |
< |
} else { |
536 |
< |
incrementSize(); |
537 |
< |
fixAfterInsertion(t.right = new Entry<K,V>(key, value, t)); |
566 |
< |
return null; |
567 |
< |
} |
568 |
< |
} |
535 |
> |
else |
536 |
> |
return t.setValue(value); |
537 |
> |
} while (t != null); |
538 |
|
} |
539 |
< |
incrementSize(); |
540 |
< |
root = new Entry<K,V>(key, value, null); |
541 |
< |
return null; |
542 |
< |
} |
543 |
< |
|
544 |
< |
/** |
545 |
< |
* Version of put using comparator. Split off from put for |
546 |
< |
* performance. |
578 |
< |
*/ |
579 |
< |
final V putUsingComparator(K key, V value) { |
580 |
< |
Comparator<? super K> cpr = comparator; |
581 |
< |
Entry<K,V> t = root; |
582 |
< |
while (t != null) { |
583 |
< |
int cmp = cpr.compare(key, t.key); |
584 |
< |
if (cmp == 0) { |
585 |
< |
return t.setValue(value); |
586 |
< |
} else if (cmp < 0) { |
587 |
< |
if (t.left != null) { |
539 |
> |
else { |
540 |
> |
if (key == null) |
541 |
> |
throw new NullPointerException(); |
542 |
> |
Comparable<? super K> k = (Comparable<? super K>) key; |
543 |
> |
do { |
544 |
> |
parent = t; |
545 |
> |
cmp = k.compareTo(t.key); |
546 |
> |
if (cmp < 0) |
547 |
|
t = t.left; |
548 |
< |
} else { |
590 |
< |
incrementSize(); |
591 |
< |
fixAfterInsertion(t.left = new Entry<K,V>(key, value, t)); |
592 |
< |
return null; |
593 |
< |
} |
594 |
< |
} else { // cmp > 0 |
595 |
< |
if (t.right != null) { |
548 |
> |
else if (cmp > 0) |
549 |
|
t = t.right; |
550 |
< |
} else { |
551 |
< |
incrementSize(); |
552 |
< |
fixAfterInsertion(t.right = new Entry<K,V>(key, value, t)); |
600 |
< |
return null; |
601 |
< |
} |
602 |
< |
} |
550 |
> |
else |
551 |
> |
return t.setValue(value); |
552 |
> |
} while (t != null); |
553 |
|
} |
554 |
< |
cpr.compare(key, key); // type check |
555 |
< |
incrementSize(); |
556 |
< |
root = new Entry<K,V>(key, value, null); |
554 |
> |
Entry<K,V> e = new Entry<K,V>(key, value, parent); |
555 |
> |
if (cmp < 0) |
556 |
> |
parent.left = e; |
557 |
> |
else |
558 |
> |
parent.right = e; |
559 |
> |
fixAfterInsertion(e); |
560 |
> |
size++; |
561 |
> |
modCount++; |
562 |
|
return null; |
563 |
|
} |
564 |
|
|
634 |
|
* @since 1.6 |
635 |
|
*/ |
636 |
|
public Map.Entry<K,V> firstEntry() { |
637 |
< |
Entry<K,V> e = getFirstEntry(); |
683 |
< |
return (e == null)? null : new AbstractMap.SimpleImmutableEntry<K,V>(e); |
637 |
> |
return exportEntry(getFirstEntry()); |
638 |
|
} |
639 |
|
|
640 |
|
/** |
641 |
|
* @since 1.6 |
642 |
|
*/ |
643 |
|
public Map.Entry<K,V> lastEntry() { |
644 |
< |
Entry<K,V> e = getLastEntry(); |
691 |
< |
return (e == null)? null : new AbstractMap.SimpleImmutableEntry<K,V>(e); |
644 |
> |
return exportEntry(getLastEntry()); |
645 |
|
} |
646 |
|
|
647 |
|
/** |
649 |
|
*/ |
650 |
|
public Map.Entry<K,V> pollFirstEntry() { |
651 |
|
Entry<K,V> p = getFirstEntry(); |
652 |
< |
if (p == null) |
653 |
< |
return null; |
654 |
< |
Map.Entry<K,V> result = new AbstractMap.SimpleImmutableEntry<K,V>(p); |
702 |
< |
deleteEntry(p); |
652 |
> |
Map.Entry<K,V> result = exportEntry(p); |
653 |
> |
if (p != null) |
654 |
> |
deleteEntry(p); |
655 |
|
return result; |
656 |
|
} |
657 |
|
|
660 |
|
*/ |
661 |
|
public Map.Entry<K,V> pollLastEntry() { |
662 |
|
Entry<K,V> p = getLastEntry(); |
663 |
< |
if (p == null) |
664 |
< |
return null; |
665 |
< |
Map.Entry<K,V> result = new AbstractMap.SimpleImmutableEntry<K,V>(p); |
714 |
< |
deleteEntry(p); |
663 |
> |
Map.Entry<K,V> result = exportEntry(p); |
664 |
> |
if (p != null) |
665 |
> |
deleteEntry(p); |
666 |
|
return result; |
667 |
|
} |
668 |
|
|
674 |
|
* @since 1.6 |
675 |
|
*/ |
676 |
|
public Map.Entry<K,V> lowerEntry(K key) { |
677 |
< |
Entry<K,V> e = getLowerEntry(key); |
727 |
< |
return (e == null)? null : new AbstractMap.SimpleImmutableEntry<K,V>(e); |
677 |
> |
return exportEntry(getLowerEntry(key)); |
678 |
|
} |
679 |
|
|
680 |
|
/** |
685 |
|
* @since 1.6 |
686 |
|
*/ |
687 |
|
public K lowerKey(K key) { |
688 |
< |
Entry<K,V> e = getLowerEntry(key); |
739 |
< |
return (e == null)? null : e.key; |
688 |
> |
return keyOrNull(getLowerEntry(key)); |
689 |
|
} |
690 |
|
|
691 |
|
/** |
696 |
|
* @since 1.6 |
697 |
|
*/ |
698 |
|
public Map.Entry<K,V> floorEntry(K key) { |
699 |
< |
Entry<K,V> e = getFloorEntry(key); |
751 |
< |
return (e == null)? null : new AbstractMap.SimpleImmutableEntry<K,V>(e); |
699 |
> |
return exportEntry(getFloorEntry(key)); |
700 |
|
} |
701 |
|
|
702 |
|
/** |
707 |
|
* @since 1.6 |
708 |
|
*/ |
709 |
|
public K floorKey(K key) { |
710 |
< |
Entry<K,V> e = getFloorEntry(key); |
763 |
< |
return (e == null)? null : e.key; |
710 |
> |
return keyOrNull(getFloorEntry(key)); |
711 |
|
} |
712 |
|
|
713 |
|
/** |
718 |
|
* @since 1.6 |
719 |
|
*/ |
720 |
|
public Map.Entry<K,V> ceilingEntry(K key) { |
721 |
< |
Entry<K,V> e = getCeilingEntry(key); |
775 |
< |
return (e == null)? null : new AbstractMap.SimpleImmutableEntry<K,V>(e); |
721 |
> |
return exportEntry(getCeilingEntry(key)); |
722 |
|
} |
723 |
|
|
724 |
|
/** |
729 |
|
* @since 1.6 |
730 |
|
*/ |
731 |
|
public K ceilingKey(K key) { |
732 |
< |
Entry<K,V> e = getCeilingEntry(key); |
787 |
< |
return (e == null)? null : e.key; |
732 |
> |
return keyOrNull(getCeilingEntry(key)); |
733 |
|
} |
734 |
|
|
735 |
|
/** |
740 |
|
* @since 1.6 |
741 |
|
*/ |
742 |
|
public Map.Entry<K,V> higherEntry(K key) { |
743 |
< |
Entry<K,V> e = getHigherEntry(key); |
799 |
< |
return (e == null)? null : new AbstractMap.SimpleImmutableEntry<K,V>(e); |
743 |
> |
return exportEntry(getHigherEntry(key)); |
744 |
|
} |
745 |
|
|
746 |
|
/** |
751 |
|
* @since 1.6 |
752 |
|
*/ |
753 |
|
public K higherKey(K key) { |
754 |
< |
Entry<K,V> e = getHigherEntry(key); |
811 |
< |
return (e == null)? null : e.key; |
754 |
> |
return keyOrNull(getHigherEntry(key)); |
755 |
|
} |
756 |
|
|
757 |
|
// Views |
845 |
|
NavigableMap<K, V> km = descendingMap; |
846 |
|
return (km != null) ? km : |
847 |
|
(descendingMap = new DescendingSubMap(this, |
848 |
< |
true, null, 0, |
849 |
< |
true, null, 0)); |
848 |
> |
true, null, true, |
849 |
> |
true, null, true)); |
850 |
|
} |
851 |
|
|
852 |
|
/** |
860 |
|
public NavigableMap<K,V> subMap(K fromKey, boolean fromInclusive, |
861 |
|
K toKey, boolean toInclusive) { |
862 |
|
return new AscendingSubMap(this, |
863 |
< |
false, fromKey, excluded(fromInclusive), |
864 |
< |
false, toKey, excluded(toInclusive)); |
863 |
> |
false, fromKey, fromInclusive, |
864 |
> |
false, toKey, toInclusive); |
865 |
|
} |
866 |
|
|
867 |
|
/** |
874 |
|
*/ |
875 |
|
public NavigableMap<K,V> headMap(K toKey, boolean inclusive) { |
876 |
|
return new AscendingSubMap(this, |
877 |
< |
true, null, 0, |
878 |
< |
false, toKey, excluded(inclusive)); |
877 |
> |
true, null, true, |
878 |
> |
false, toKey, inclusive); |
879 |
|
} |
880 |
|
|
881 |
|
/** |
888 |
|
*/ |
889 |
|
public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) { |
890 |
|
return new AscendingSubMap(this, |
891 |
< |
false, fromKey, excluded(inclusive), |
892 |
< |
true, null, 0); |
950 |
< |
} |
951 |
< |
|
952 |
< |
/** |
953 |
< |
* Translates a boolean "inclusive" value to the correct int value |
954 |
< |
* for the loExcluded or hiExcluded field. |
955 |
< |
*/ |
956 |
< |
static int excluded(boolean inclusive) { |
957 |
< |
return inclusive ? 0 : 1; |
891 |
> |
false, fromKey, inclusive, |
892 |
> |
true, null, true); |
893 |
|
} |
894 |
|
|
895 |
|
/** |
937 |
|
} |
938 |
|
|
939 |
|
public boolean contains(Object o) { |
940 |
< |
for (Entry<K,V> e = getFirstEntry(); e != null; e = successor(e)) |
1006 |
< |
if (valEquals(e.getValue(), o)) |
1007 |
< |
return true; |
1008 |
< |
return false; |
940 |
> |
return TreeMap.this.containsValue(o); |
941 |
|
} |
942 |
|
|
943 |
|
public boolean remove(Object o) { |
1050 |
|
return size() != oldSize; |
1051 |
|
} |
1052 |
|
public NavigableSet<E> subSet(E fromElement, boolean fromInclusive, |
1053 |
< |
E toElement, boolean toInclusive) { |
1053 |
> |
E toElement, boolean toInclusive) { |
1054 |
|
return new TreeSet<E>(m.subMap(fromElement, fromInclusive, |
1055 |
|
toElement, toInclusive)); |
1056 |
|
} |
1117 |
|
throw new IllegalStateException(); |
1118 |
|
if (modCount != expectedModCount) |
1119 |
|
throw new ConcurrentModificationException(); |
1120 |
+ |
// deleted entries are replaced by their successors |
1121 |
|
if (lastReturned.left != null && lastReturned.right != null) |
1122 |
|
next = lastReturned; |
1123 |
|
deleteEntry(lastReturned); |
1124 |
< |
expectedModCount++; |
1124 |
> |
expectedModCount = modCount; |
1125 |
|
lastReturned = null; |
1126 |
|
} |
1127 |
|
} |
1162 |
|
} |
1163 |
|
} |
1164 |
|
|
1165 |
+ |
// Little utilities |
1166 |
+ |
|
1167 |
+ |
/** |
1168 |
+ |
* Compares two keys using the correct comparison method for this TreeMap. |
1169 |
+ |
*/ |
1170 |
+ |
final int compare(Object k1, Object k2) { |
1171 |
+ |
return comparator==null ? ((Comparable<? super K>)k1).compareTo((K)k2) |
1172 |
+ |
: comparator.compare((K)k1, (K)k2); |
1173 |
+ |
} |
1174 |
+ |
|
1175 |
+ |
/** |
1176 |
+ |
* Test two values for equality. Differs from o1.equals(o2) only in |
1177 |
+ |
* that it copes with <tt>null</tt> o1 properly. |
1178 |
+ |
*/ |
1179 |
+ |
final static boolean valEquals(Object o1, Object o2) { |
1180 |
+ |
return (o1==null ? o2==null : o1.equals(o2)); |
1181 |
+ |
} |
1182 |
+ |
|
1183 |
+ |
/** |
1184 |
+ |
* Return SimpleImmutableEntry for entry, or null if null |
1185 |
+ |
*/ |
1186 |
+ |
static <K,V> Map.Entry<K,V> exportEntry(TreeMap.Entry<K,V> e) { |
1187 |
+ |
return e == null? null : |
1188 |
+ |
new AbstractMap.SimpleImmutableEntry<K,V>(e); |
1189 |
+ |
} |
1190 |
+ |
|
1191 |
+ |
/** |
1192 |
+ |
* Return key for entry, or null if null |
1193 |
+ |
*/ |
1194 |
+ |
static <K,V> K keyOrNull(TreeMap.Entry<K,V> e) { |
1195 |
+ |
return e == null? null : e.key; |
1196 |
+ |
} |
1197 |
+ |
|
1198 |
+ |
/** |
1199 |
+ |
* Returns the key corresponding to the specified Entry. |
1200 |
+ |
* @throws NoSuchElementException if the Entry is null |
1201 |
+ |
*/ |
1202 |
+ |
static <K> K key(Entry<K,?> e) { |
1203 |
+ |
if (e==null) |
1204 |
+ |
throw new NoSuchElementException(); |
1205 |
+ |
return e.key; |
1206 |
+ |
} |
1207 |
+ |
|
1208 |
+ |
|
1209 |
|
// SubMaps |
1210 |
|
|
1211 |
+ |
/** |
1212 |
+ |
* Dummy value serving as unmatchable fence key for unbounded |
1213 |
+ |
* SubMapIterators |
1214 |
+ |
*/ |
1215 |
+ |
private static final Object UNBOUNDED = new Object(); |
1216 |
+ |
|
1217 |
+ |
/** |
1218 |
+ |
* @serial include |
1219 |
+ |
*/ |
1220 |
|
static abstract class NavigableSubMap<K,V> extends AbstractMap<K,V> |
1221 |
|
implements NavigableMap<K,V>, java.io.Serializable { |
1222 |
< |
|
1237 |
< |
/* |
1222 |
> |
/** |
1223 |
|
* The backing map. |
1224 |
|
*/ |
1225 |
|
final TreeMap<K,V> m; |
1226 |
|
|
1227 |
< |
/* |
1228 |
< |
* Endpoints are represented as triples (fromStart, lo, loExcluded) |
1229 |
< |
* and (toEnd, hi, hiExcluded). If fromStart is true, then |
1230 |
< |
* the low (absolute) bound is the start of the backing map, and the |
1231 |
< |
* other values are ignored. Otherwise, if loExcluded is |
1232 |
< |
* zero, lo is the inclusive bound, else loExcluded is one, |
1233 |
< |
* and lo is the exclusive bound. Similarly for the upper bound. |
1227 |
> |
/** |
1228 |
> |
* Endpoints are represented as triples (fromStart, lo, |
1229 |
> |
* loInclusive) and (toEnd, hi, hiInclusive). If fromStart is |
1230 |
> |
* true, then the low (absolute) bound is the start of the |
1231 |
> |
* backing map, and the other values are ignored. Otherwise, |
1232 |
> |
* if loInclusive is true, lo is the inclusive bound, else lo |
1233 |
> |
* is the exclusive bound. Similarly for the upper bound. |
1234 |
|
*/ |
1250 |
– |
|
1235 |
|
final K lo, hi; |
1236 |
|
final boolean fromStart, toEnd; |
1237 |
< |
final int loExcluded, hiExcluded; |
1237 |
> |
final boolean loInclusive, hiInclusive; |
1238 |
|
|
1239 |
|
NavigableSubMap(TreeMap<K,V> m, |
1240 |
< |
boolean fromStart, K lo, int loExcluded, |
1241 |
< |
boolean toEnd, K hi, int hiExcluded) { |
1240 |
> |
boolean fromStart, K lo, boolean loInclusive, |
1241 |
> |
boolean toEnd, K hi, boolean hiInclusive) { |
1242 |
|
if (!fromStart && !toEnd) { |
1243 |
|
if (m.compare(lo, hi) > 0) |
1244 |
|
throw new IllegalArgumentException("fromKey > toKey"); |
1245 |
+ |
} else { |
1246 |
+ |
if (!fromStart) // type check |
1247 |
+ |
m.compare(lo, lo); |
1248 |
+ |
if (!toEnd) |
1249 |
+ |
m.compare(hi, hi); |
1250 |
|
} |
1262 |
– |
else if (!fromStart) // type check |
1263 |
– |
m.compare(lo, lo); |
1264 |
– |
else if (!toEnd) |
1265 |
– |
m.compare(hi, hi); |
1251 |
|
|
1252 |
|
this.m = m; |
1253 |
|
this.fromStart = fromStart; |
1254 |
|
this.lo = lo; |
1255 |
< |
this.loExcluded = loExcluded; |
1255 |
> |
this.loInclusive = loInclusive; |
1256 |
|
this.toEnd = toEnd; |
1257 |
|
this.hi = hi; |
1258 |
< |
this.hiExcluded = hiExcluded; |
1258 |
> |
this.hiInclusive = hiInclusive; |
1259 |
|
} |
1260 |
|
|
1261 |
|
// internal utilities |
1262 |
|
|
1263 |
+ |
final boolean tooLow(Object key) { |
1264 |
+ |
if (!fromStart) { |
1265 |
+ |
int c = m.compare(key, lo); |
1266 |
+ |
if (c < 0 || (c == 0 && !loInclusive)) |
1267 |
+ |
return true; |
1268 |
+ |
} |
1269 |
+ |
return false; |
1270 |
+ |
} |
1271 |
+ |
|
1272 |
+ |
final boolean tooHigh(Object key) { |
1273 |
+ |
if (!toEnd) { |
1274 |
+ |
int c = m.compare(key, hi); |
1275 |
+ |
if (c > 0 || (c == 0 && !hiInclusive)) |
1276 |
+ |
return true; |
1277 |
+ |
} |
1278 |
+ |
return false; |
1279 |
+ |
} |
1280 |
+ |
|
1281 |
|
final boolean inRange(Object key) { |
1282 |
< |
return (fromStart || m.compare(key, lo) >= loExcluded) |
1280 |
< |
&& (toEnd || m.compare(hi, key) >= hiExcluded); |
1282 |
> |
return !tooLow(key) && !tooHigh(key); |
1283 |
|
} |
1284 |
|
|
1285 |
|
final boolean inClosedRange(Object key) { |
1291 |
|
return inclusive ? inRange(key) : inClosedRange(key); |
1292 |
|
} |
1293 |
|
|
1294 |
< |
final boolean tooLow(K key) { |
1295 |
< |
return !fromStart && m.compare(key, lo) < loExcluded; |
1296 |
< |
} |
1297 |
< |
|
1298 |
< |
final boolean tooHigh(K key) { |
1297 |
< |
return !toEnd && m.compare(hi, key) < hiExcluded; |
1298 |
< |
} |
1294 |
> |
/* |
1295 |
> |
* Absolute versions of relation operations. |
1296 |
> |
* Subclasses map to these using like-named "sub" |
1297 |
> |
* versions that invert senses for descending maps |
1298 |
> |
*/ |
1299 |
|
|
1300 |
< |
/** Returns the lowest entry in this submap (absolute ordering) */ |
1301 |
< |
final TreeMap.Entry<K,V> loEntry() { |
1302 |
< |
TreeMap.Entry<K,V> result = |
1300 |
> |
final TreeMap.Entry<K,V> absLowest() { |
1301 |
> |
TreeMap.Entry<K,V> e = |
1302 |
|
(fromStart ? m.getFirstEntry() : |
1303 |
< |
(loExcluded == 0 ? m.getCeilingEntry(lo) : |
1304 |
< |
m.getHigherEntry(lo))); |
1305 |
< |
return (result == null || tooHigh(result.key)) ? null : result; |
1303 |
> |
(loInclusive ? m.getCeilingEntry(lo) : |
1304 |
> |
m.getHigherEntry(lo))); |
1305 |
> |
return (e == null || tooHigh(e.key)) ? null : e; |
1306 |
|
} |
1307 |
|
|
1308 |
< |
/** Returns the highest key in this submap (absolute ordering) */ |
1309 |
< |
final TreeMap.Entry<K,V> hiEntry() { |
1311 |
< |
TreeMap.Entry<K,V> result = |
1308 |
> |
final TreeMap.Entry<K,V> absHighest() { |
1309 |
> |
TreeMap.Entry<K,V> e = |
1310 |
|
(toEnd ? m.getLastEntry() : |
1311 |
< |
(hiExcluded == 0 ? m.getFloorEntry(hi) : |
1312 |
< |
m.getLowerEntry(hi))); |
1313 |
< |
return (result == null || tooLow(result.key)) ? null : result; |
1311 |
> |
(hiInclusive ? m.getFloorEntry(hi) : |
1312 |
> |
m.getLowerEntry(hi))); |
1313 |
> |
return (e == null || tooLow(e.key)) ? null : e; |
1314 |
|
} |
1315 |
|
|
1316 |
< |
/** Polls the lowest entry in this submap (absolute ordering) */ |
1317 |
< |
final Map.Entry<K,V> pollLoEntry() { |
1318 |
< |
TreeMap.Entry<K,V> e = loEntry(); |
1319 |
< |
if (e == null) |
1320 |
< |
return null; |
1323 |
< |
Map.Entry<K,V> result = new AbstractMap.SimpleImmutableEntry<K,V>(e); |
1324 |
< |
m.deleteEntry(e); |
1325 |
< |
return result; |
1316 |
> |
final TreeMap.Entry<K,V> absCeiling(K key) { |
1317 |
> |
if (tooLow(key)) |
1318 |
> |
return absLowest(); |
1319 |
> |
TreeMap.Entry<K,V> e = m.getCeilingEntry(key); |
1320 |
> |
return (e == null || tooHigh(e.key)) ? null : e; |
1321 |
|
} |
1322 |
|
|
1323 |
< |
/** Polls the highest key in this submap (absolute ordering) */ |
1324 |
< |
final Map.Entry<K,V> pollHiEntry() { |
1325 |
< |
TreeMap.Entry<K,V> e = hiEntry(); |
1326 |
< |
if (e == null) |
1327 |
< |
return null; |
1333 |
< |
Map.Entry<K,V> result = new AbstractMap.SimpleImmutableEntry<K,V>(e); |
1334 |
< |
m.deleteEntry(e); |
1335 |
< |
return result; |
1323 |
> |
final TreeMap.Entry<K,V> absHigher(K key) { |
1324 |
> |
if (tooLow(key)) |
1325 |
> |
return absLowest(); |
1326 |
> |
TreeMap.Entry<K,V> e = m.getHigherEntry(key); |
1327 |
> |
return (e == null || tooHigh(e.key)) ? null : e; |
1328 |
|
} |
1329 |
|
|
1330 |
< |
/** |
1331 |
< |
* Return the absolute high fence for ascending traversal |
1332 |
< |
*/ |
1333 |
< |
final TreeMap.Entry<K,V> hiFence() { |
1334 |
< |
if (toEnd) |
1343 |
< |
return null; |
1344 |
< |
else if (hiExcluded == 0) |
1345 |
< |
return m.getHigherEntry(hi); |
1346 |
< |
else |
1347 |
< |
return m.getCeilingEntry(hi); |
1330 |
> |
final TreeMap.Entry<K,V> absFloor(K key) { |
1331 |
> |
if (tooHigh(key)) |
1332 |
> |
return absHighest(); |
1333 |
> |
TreeMap.Entry<K,V> e = m.getFloorEntry(key); |
1334 |
> |
return (e == null || tooLow(e.key)) ? null : e; |
1335 |
|
} |
1336 |
|
|
1337 |
< |
/** |
1338 |
< |
* Return the absolute low fence for descending traversal |
1339 |
< |
*/ |
1340 |
< |
final TreeMap.Entry<K,V> loFence() { |
1341 |
< |
if (fromStart) |
1355 |
< |
return null; |
1356 |
< |
else if (loExcluded == 0) |
1357 |
< |
return m.getLowerEntry(lo); |
1358 |
< |
else |
1359 |
< |
return m.getFloorEntry(lo); |
1337 |
> |
final TreeMap.Entry<K,V> absLower(K key) { |
1338 |
> |
if (tooHigh(key)) |
1339 |
> |
return absHighest(); |
1340 |
> |
TreeMap.Entry<K,V> e = m.getLowerEntry(key); |
1341 |
> |
return (e == null || tooLow(e.key)) ? null : e; |
1342 |
|
} |
1343 |
|
|
1344 |
+ |
/** Returns the absolute high fence for ascending traversal */ |
1345 |
+ |
final TreeMap.Entry<K,V> absHighFence() { |
1346 |
+ |
return (toEnd ? null : (hiInclusive ? |
1347 |
+ |
m.getHigherEntry(hi) : |
1348 |
+ |
m.getCeilingEntry(hi))); |
1349 |
+ |
} |
1350 |
+ |
|
1351 |
+ |
/** Return the absolute low fence for descending traversal */ |
1352 |
+ |
final TreeMap.Entry<K,V> absLowFence() { |
1353 |
+ |
return (fromStart ? null : (loInclusive ? |
1354 |
+ |
m.getLowerEntry(lo) : |
1355 |
+ |
m.getFloorEntry(lo))); |
1356 |
+ |
} |
1357 |
+ |
|
1358 |
+ |
// Abstract methods defined in ascending vs descending classes |
1359 |
+ |
// These relay to the appropriate absolute versions |
1360 |
+ |
|
1361 |
+ |
abstract TreeMap.Entry<K,V> subLowest(); |
1362 |
+ |
abstract TreeMap.Entry<K,V> subHighest(); |
1363 |
+ |
abstract TreeMap.Entry<K,V> subCeiling(K key); |
1364 |
+ |
abstract TreeMap.Entry<K,V> subHigher(K key); |
1365 |
+ |
abstract TreeMap.Entry<K,V> subFloor(K key); |
1366 |
+ |
abstract TreeMap.Entry<K,V> subLower(K key); |
1367 |
+ |
|
1368 |
+ |
/** Returns ascending iterator from the perspective of this submap */ |
1369 |
+ |
abstract Iterator<K> keyIterator(); |
1370 |
+ |
|
1371 |
+ |
/** Returns descending iterator from the perspective of this submap */ |
1372 |
+ |
abstract Iterator<K> descendingKeyIterator(); |
1373 |
+ |
|
1374 |
+ |
// public methods |
1375 |
|
|
1376 |
|
public boolean isEmpty() { |
1377 |
< |
return entrySet().isEmpty(); |
1377 |
> |
return (fromStart && toEnd) ? m.isEmpty() : entrySet().isEmpty(); |
1378 |
|
} |
1379 |
|
|
1380 |
< |
public boolean containsKey(Object key) { |
1381 |
< |
return inRange(key) && m.containsKey(key); |
1380 |
> |
public int size() { |
1381 |
> |
return (fromStart && toEnd) ? m.size() : entrySet().size(); |
1382 |
|
} |
1383 |
|
|
1384 |
< |
public V get(Object key) { |
1385 |
< |
if (!inRange(key)) |
1373 |
< |
return null; |
1374 |
< |
return m.get(key); |
1384 |
> |
public final boolean containsKey(Object key) { |
1385 |
> |
return inRange(key) && m.containsKey(key); |
1386 |
|
} |
1387 |
|
|
1388 |
< |
public V put(K key, V value) { |
1388 |
> |
public final V put(K key, V value) { |
1389 |
|
if (!inRange(key)) |
1390 |
|
throw new IllegalArgumentException("key out of range"); |
1391 |
|
return m.put(key, value); |
1392 |
|
} |
1393 |
|
|
1394 |
< |
public V remove(Object key) { |
1395 |
< |
if (!inRange(key)) |
1385 |
< |
return null; |
1386 |
< |
return m.remove(key); |
1394 |
> |
public final V get(Object key) { |
1395 |
> |
return !inRange(key)? null : m.get(key); |
1396 |
|
} |
1397 |
|
|
1398 |
< |
public Map.Entry<K,V> ceilingEntry(K key) { |
1399 |
< |
TreeMap.Entry<K,V> e = subCeiling(key); |
1391 |
< |
return e == null? null : new AbstractMap.SimpleImmutableEntry<K,V>(e); |
1398 |
> |
public final V remove(Object key) { |
1399 |
> |
return !inRange(key)? null : m.remove(key); |
1400 |
|
} |
1401 |
|
|
1402 |
< |
public K ceilingKey(K key) { |
1403 |
< |
TreeMap.Entry<K,V> e = subCeiling(key); |
1396 |
< |
return e == null? null : e.key; |
1402 |
> |
public final Map.Entry<K,V> ceilingEntry(K key) { |
1403 |
> |
return exportEntry(subCeiling(key)); |
1404 |
|
} |
1405 |
|
|
1406 |
< |
public Map.Entry<K,V> higherEntry(K key) { |
1407 |
< |
TreeMap.Entry<K,V> e = subHigher(key); |
1401 |
< |
return e == null? null : new AbstractMap.SimpleImmutableEntry<K,V>(e); |
1406 |
> |
public final K ceilingKey(K key) { |
1407 |
> |
return keyOrNull(subCeiling(key)); |
1408 |
|
} |
1409 |
|
|
1410 |
< |
public K higherKey(K key) { |
1411 |
< |
TreeMap.Entry<K,V> e = subHigher(key); |
1406 |
< |
return e == null? null : e.key; |
1410 |
> |
public final Map.Entry<K,V> higherEntry(K key) { |
1411 |
> |
return exportEntry(subHigher(key)); |
1412 |
|
} |
1413 |
|
|
1414 |
< |
public Map.Entry<K,V> floorEntry(K key) { |
1415 |
< |
TreeMap.Entry<K,V> e = subFloor(key); |
1411 |
< |
return e == null? null : new AbstractMap.SimpleImmutableEntry<K,V>(e); |
1414 |
> |
public final K higherKey(K key) { |
1415 |
> |
return keyOrNull(subHigher(key)); |
1416 |
|
} |
1417 |
|
|
1418 |
< |
public K floorKey(K key) { |
1419 |
< |
TreeMap.Entry<K,V> e = subFloor(key); |
1416 |
< |
return e == null? null : e.key; |
1418 |
> |
public final Map.Entry<K,V> floorEntry(K key) { |
1419 |
> |
return exportEntry(subFloor(key)); |
1420 |
|
} |
1421 |
|
|
1422 |
< |
public Map.Entry<K,V> lowerEntry(K key) { |
1423 |
< |
TreeMap.Entry<K,V> e = subLower(key); |
1421 |
< |
return e == null? null : new AbstractMap.SimpleImmutableEntry<K,V>(e); |
1422 |
> |
public final K floorKey(K key) { |
1423 |
> |
return keyOrNull(subFloor(key)); |
1424 |
|
} |
1425 |
|
|
1426 |
< |
public K lowerKey(K key) { |
1427 |
< |
TreeMap.Entry<K,V> e = subLower(key); |
1426 |
< |
return e == null? null : e.key; |
1426 |
> |
public final Map.Entry<K,V> lowerEntry(K key) { |
1427 |
> |
return exportEntry(subLower(key)); |
1428 |
|
} |
1429 |
|
|
1430 |
< |
abstract Iterator<K> keyIterator(); |
1431 |
< |
abstract Iterator<K> descendingKeyIterator(); |
1430 |
> |
public final K lowerKey(K key) { |
1431 |
> |
return keyOrNull(subLower(key)); |
1432 |
> |
} |
1433 |
|
|
1434 |
< |
public NavigableSet<K> descendingKeySet() { |
1435 |
< |
return descendingMap().navigableKeySet(); |
1434 |
> |
public final K firstKey() { |
1435 |
> |
return key(subLowest()); |
1436 |
> |
} |
1437 |
> |
|
1438 |
> |
public final K lastKey() { |
1439 |
> |
return key(subHighest()); |
1440 |
> |
} |
1441 |
> |
|
1442 |
> |
public final Map.Entry<K,V> firstEntry() { |
1443 |
> |
return exportEntry(subLowest()); |
1444 |
> |
} |
1445 |
> |
|
1446 |
> |
public final Map.Entry<K,V> lastEntry() { |
1447 |
> |
return exportEntry(subHighest()); |
1448 |
> |
} |
1449 |
> |
|
1450 |
> |
public final Map.Entry<K,V> pollFirstEntry() { |
1451 |
> |
TreeMap.Entry<K,V> e = subLowest(); |
1452 |
> |
Map.Entry<K,V> result = exportEntry(e); |
1453 |
> |
if (e != null) |
1454 |
> |
m.deleteEntry(e); |
1455 |
> |
return result; |
1456 |
> |
} |
1457 |
> |
|
1458 |
> |
public final Map.Entry<K,V> pollLastEntry() { |
1459 |
> |
TreeMap.Entry<K,V> e = subHighest(); |
1460 |
> |
Map.Entry<K,V> result = exportEntry(e); |
1461 |
> |
if (e != null) |
1462 |
> |
m.deleteEntry(e); |
1463 |
> |
return result; |
1464 |
|
} |
1465 |
|
|
1466 |
|
// Views |
1468 |
|
transient EntrySetView entrySetView = null; |
1469 |
|
transient KeySet<K> navigableKeySetView = null; |
1470 |
|
|
1471 |
+ |
public final NavigableSet<K> navigableKeySet() { |
1472 |
+ |
KeySet<K> nksv = navigableKeySetView; |
1473 |
+ |
return (nksv != null) ? nksv : |
1474 |
+ |
(navigableKeySetView = new TreeMap.KeySet(this)); |
1475 |
+ |
} |
1476 |
+ |
|
1477 |
+ |
public final Set<K> keySet() { |
1478 |
+ |
return navigableKeySet(); |
1479 |
+ |
} |
1480 |
+ |
|
1481 |
+ |
public NavigableSet<K> descendingKeySet() { |
1482 |
+ |
return descendingMap().navigableKeySet(); |
1483 |
+ |
} |
1484 |
+ |
|
1485 |
+ |
public final SortedMap<K,V> subMap(K fromKey, K toKey) { |
1486 |
+ |
return subMap(fromKey, true, toKey, false); |
1487 |
+ |
} |
1488 |
+ |
|
1489 |
+ |
public final SortedMap<K,V> headMap(K toKey) { |
1490 |
+ |
return headMap(toKey, false); |
1491 |
+ |
} |
1492 |
+ |
|
1493 |
+ |
public final SortedMap<K,V> tailMap(K fromKey) { |
1494 |
+ |
return tailMap(fromKey, true); |
1495 |
+ |
} |
1496 |
+ |
|
1497 |
+ |
// View classes |
1498 |
+ |
|
1499 |
|
abstract class EntrySetView extends AbstractSet<Map.Entry<K,V>> { |
1500 |
|
private transient int size = -1, sizeModCount; |
1501 |
|
|
1515 |
|
} |
1516 |
|
|
1517 |
|
public boolean isEmpty() { |
1518 |
< |
TreeMap.Entry<K,V> n = loEntry(); |
1518 |
> |
TreeMap.Entry<K,V> n = absLowest(); |
1519 |
|
return n == null || tooHigh(n.key); |
1520 |
|
} |
1521 |
|
|
1547 |
|
} |
1548 |
|
} |
1549 |
|
|
1492 |
– |
public NavigableSet<K> navigableKeySet() { |
1493 |
– |
KeySet<K> nksv = navigableKeySetView; |
1494 |
– |
return (nksv != null) ? nksv : |
1495 |
– |
(navigableKeySetView = new TreeMap.KeySet(this)); |
1496 |
– |
} |
1497 |
– |
|
1498 |
– |
public Set<K> keySet() { |
1499 |
– |
return navigableKeySet(); |
1500 |
– |
} |
1501 |
– |
|
1502 |
– |
public SortedMap<K,V> subMap(K fromKey, K toKey) { |
1503 |
– |
return subMap(fromKey, true, toKey, false); |
1504 |
– |
} |
1505 |
– |
|
1506 |
– |
public SortedMap<K,V> headMap(K toKey) { |
1507 |
– |
return headMap(toKey, false); |
1508 |
– |
} |
1509 |
– |
|
1510 |
– |
public SortedMap<K,V> tailMap(K fromKey) { |
1511 |
– |
return tailMap(fromKey, true); |
1512 |
– |
} |
1513 |
– |
|
1514 |
– |
// The following four definitions are correct only for |
1515 |
– |
// ascending submaps. They are overridden in DescendingSubMap. |
1516 |
– |
// They are defined in the base class because the definitions |
1517 |
– |
// in DescendingSubMap rely on those for AscendingSubMap. |
1518 |
– |
|
1519 |
– |
/** |
1520 |
– |
* Returns the entry corresponding to the ceiling of the specified |
1521 |
– |
* key from the perspective of this submap, or null if the submap |
1522 |
– |
* contains no such entry. |
1523 |
– |
*/ |
1524 |
– |
TreeMap.Entry<K,V> subCeiling(K key) { |
1525 |
– |
if (tooLow(key)) |
1526 |
– |
return loEntry(); |
1527 |
– |
TreeMap.Entry<K,V> e = m.getCeilingEntry(key); |
1528 |
– |
return (e == null || tooHigh(e.key)) ? null : e; |
1529 |
– |
} |
1530 |
– |
|
1531 |
– |
/** |
1532 |
– |
* Returns the entry corresponding to the higher of the specified |
1533 |
– |
* key from the perspective of this submap, or null if the submap |
1534 |
– |
* contains no such entry. |
1535 |
– |
*/ |
1536 |
– |
TreeMap.Entry<K,V> subHigher(K key) { |
1537 |
– |
if (tooLow(key)) |
1538 |
– |
return loEntry(); |
1539 |
– |
TreeMap.Entry<K,V> e = m.getHigherEntry(key); |
1540 |
– |
return (e == null || tooHigh(e.key)) ? null : e; |
1541 |
– |
} |
1542 |
– |
|
1543 |
– |
/** |
1544 |
– |
* Returns the entry corresponding to the floor of the specified |
1545 |
– |
* key from the perspective of this submap, or null if the submap |
1546 |
– |
* contains no such entry. |
1547 |
– |
*/ |
1548 |
– |
TreeMap.Entry<K,V> subFloor(K key) { |
1549 |
– |
if (tooHigh(key)) |
1550 |
– |
return hiEntry(); |
1551 |
– |
TreeMap.Entry<K,V> e = m.getFloorEntry(key); |
1552 |
– |
return (e == null || tooLow(e.key)) ? null : e; |
1553 |
– |
} |
1554 |
– |
|
1555 |
– |
/** |
1556 |
– |
* Returns the entry corresponding to the lower of the specified |
1557 |
– |
* key from the perspective of this submap, or null if the submap |
1558 |
– |
* contains no such entry. |
1559 |
– |
*/ |
1560 |
– |
TreeMap.Entry<K,V> subLower(K key) { |
1561 |
– |
if (tooHigh(key)) |
1562 |
– |
return hiEntry(); |
1563 |
– |
TreeMap.Entry<K,V> e = m.getLowerEntry(key); |
1564 |
– |
return (e == null || tooLow(e.key)) ? null : e; |
1565 |
– |
} |
1566 |
– |
|
1550 |
|
/** |
1551 |
|
* Iterators for SubMaps |
1552 |
|
*/ |
1553 |
|
abstract class SubMapIterator<T> implements Iterator<T> { |
1554 |
|
TreeMap.Entry<K,V> lastReturned; |
1555 |
|
TreeMap.Entry<K,V> next; |
1556 |
< |
final K fenceKey; |
1556 |
> |
final Object fenceKey; |
1557 |
|
int expectedModCount; |
1558 |
|
|
1559 |
|
SubMapIterator(TreeMap.Entry<K,V> first, |
1561 |
|
expectedModCount = m.modCount; |
1562 |
|
lastReturned = null; |
1563 |
|
next = first; |
1564 |
< |
fenceKey = fence == null ? null : fence.key; |
1564 |
> |
fenceKey = fence == null ? UNBOUNDED : fence.key; |
1565 |
|
} |
1566 |
|
|
1567 |
|
public final boolean hasNext() { |
1588 |
|
return e; |
1589 |
|
} |
1590 |
|
|
1591 |
< |
public void remove() { |
1591 |
> |
final void removeAscending() { |
1592 |
|
if (lastReturned == null) |
1593 |
|
throw new IllegalStateException(); |
1594 |
|
if (m.modCount != expectedModCount) |
1595 |
|
throw new ConcurrentModificationException(); |
1596 |
+ |
// deleted entries are replaced by their successors |
1597 |
|
if (lastReturned.left != null && lastReturned.right != null) |
1598 |
|
next = lastReturned; |
1599 |
|
m.deleteEntry(lastReturned); |
1616 |
– |
expectedModCount++; |
1600 |
|
lastReturned = null; |
1601 |
+ |
expectedModCount = m.modCount; |
1602 |
|
} |
1603 |
+ |
|
1604 |
+ |
final void removeDescending() { |
1605 |
+ |
if (lastReturned == null) |
1606 |
+ |
throw new IllegalStateException(); |
1607 |
+ |
if (m.modCount != expectedModCount) |
1608 |
+ |
throw new ConcurrentModificationException(); |
1609 |
+ |
m.deleteEntry(lastReturned); |
1610 |
+ |
lastReturned = null; |
1611 |
+ |
expectedModCount = m.modCount; |
1612 |
+ |
} |
1613 |
+ |
|
1614 |
|
} |
1615 |
|
|
1616 |
|
final class SubMapEntryIterator extends SubMapIterator<Map.Entry<K,V>> { |
1621 |
|
public Map.Entry<K,V> next() { |
1622 |
|
return nextEntry(); |
1623 |
|
} |
1624 |
+ |
public void remove() { |
1625 |
+ |
removeAscending(); |
1626 |
+ |
} |
1627 |
|
} |
1628 |
|
|
1629 |
|
final class SubMapKeyIterator extends SubMapIterator<K> { |
1634 |
|
public K next() { |
1635 |
|
return nextEntry().key; |
1636 |
|
} |
1637 |
+ |
public void remove() { |
1638 |
+ |
removeAscending(); |
1639 |
+ |
} |
1640 |
|
} |
1641 |
|
|
1642 |
|
final class DescendingSubMapEntryIterator extends SubMapIterator<Map.Entry<K,V>> { |
1643 |
|
DescendingSubMapEntryIterator(TreeMap.Entry<K,V> last, |
1644 |
< |
TreeMap.Entry<K,V> lastExcluded) { |
1645 |
< |
super(last, lastExcluded); |
1644 |
> |
TreeMap.Entry<K,V> fence) { |
1645 |
> |
super(last, fence); |
1646 |
|
} |
1647 |
|
|
1648 |
|
public Map.Entry<K,V> next() { |
1649 |
|
return prevEntry(); |
1650 |
|
} |
1651 |
+ |
public void remove() { |
1652 |
+ |
removeDescending(); |
1653 |
+ |
} |
1654 |
|
} |
1655 |
|
|
1656 |
|
final class DescendingSubMapKeyIterator extends SubMapIterator<K> { |
1657 |
|
DescendingSubMapKeyIterator(TreeMap.Entry<K,V> last, |
1658 |
< |
TreeMap.Entry<K,V> lastExcluded) { |
1659 |
< |
super(last, lastExcluded); |
1658 |
> |
TreeMap.Entry<K,V> fence) { |
1659 |
> |
super(last, fence); |
1660 |
|
} |
1661 |
|
public K next() { |
1662 |
|
return prevEntry().key; |
1663 |
|
} |
1664 |
+ |
public void remove() { |
1665 |
+ |
removeDescending(); |
1666 |
+ |
} |
1667 |
|
} |
1668 |
|
} |
1669 |
|
|
1670 |
< |
static class AscendingSubMap<K,V> extends NavigableSubMap<K,V> { |
1670 |
> |
/** |
1671 |
> |
* @serial include |
1672 |
> |
*/ |
1673 |
> |
static final class AscendingSubMap<K,V> extends NavigableSubMap<K,V> { |
1674 |
|
private static final long serialVersionUID = 912986545866124060L; |
1675 |
|
|
1676 |
|
AscendingSubMap(TreeMap<K,V> m, |
1677 |
< |
boolean fromStart, K lo, int loExcluded, |
1678 |
< |
boolean toEnd, K hi, int hiExcluded) { |
1679 |
< |
super(m, fromStart, lo, loExcluded, toEnd, hi, hiExcluded); |
1677 |
> |
boolean fromStart, K lo, boolean loInclusive, |
1678 |
> |
boolean toEnd, K hi, boolean hiInclusive) { |
1679 |
> |
super(m, fromStart, lo, loInclusive, toEnd, hi, hiInclusive); |
1680 |
|
} |
1681 |
|
|
1682 |
|
public Comparator<? super K> comparator() { |
1684 |
|
} |
1685 |
|
|
1686 |
|
public NavigableMap<K,V> subMap(K fromKey, boolean fromInclusive, |
1687 |
< |
K toKey, boolean toInclusive) { |
1687 |
> |
K toKey, boolean toInclusive) { |
1688 |
|
if (!inRange(fromKey, fromInclusive)) |
1689 |
|
throw new IllegalArgumentException("fromKey out of range"); |
1690 |
|
if (!inRange(toKey, toInclusive)) |
1691 |
|
throw new IllegalArgumentException("toKey out of range"); |
1692 |
|
return new AscendingSubMap(m, |
1693 |
< |
false, fromKey, excluded(fromInclusive), |
1694 |
< |
false, toKey, excluded(toInclusive)); |
1693 |
> |
false, fromKey, fromInclusive, |
1694 |
> |
false, toKey, toInclusive); |
1695 |
|
} |
1696 |
|
|
1697 |
|
public NavigableMap<K,V> headMap(K toKey, boolean inclusive) { |
1698 |
< |
if (!inClosedRange(toKey)) |
1698 |
> |
if (!inRange(toKey, inclusive)) |
1699 |
|
throw new IllegalArgumentException("toKey out of range"); |
1700 |
|
return new AscendingSubMap(m, |
1701 |
< |
fromStart, lo, loExcluded, |
1702 |
< |
false, toKey, excluded(inclusive)); |
1701 |
> |
fromStart, lo, loInclusive, |
1702 |
> |
false, toKey, inclusive); |
1703 |
|
} |
1704 |
|
|
1705 |
|
public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive){ |
1706 |
|
if (!inRange(fromKey, inclusive)) |
1707 |
|
throw new IllegalArgumentException("fromKey out of range"); |
1708 |
|
return new AscendingSubMap(m, |
1709 |
< |
false, fromKey, excluded(inclusive), |
1710 |
< |
toEnd, hi, hiExcluded); |
1709 |
> |
false, fromKey, inclusive, |
1710 |
> |
toEnd, hi, hiInclusive); |
1711 |
> |
} |
1712 |
> |
|
1713 |
> |
public NavigableMap<K,V> descendingMap() { |
1714 |
> |
NavigableMap<K,V> mv = descendingMapView; |
1715 |
> |
return (mv != null) ? mv : |
1716 |
> |
(descendingMapView = |
1717 |
> |
new DescendingSubMap(m, |
1718 |
> |
fromStart, lo, loInclusive, |
1719 |
> |
toEnd, hi, hiInclusive)); |
1720 |
|
} |
1721 |
|
|
1722 |
|
Iterator<K> keyIterator() { |
1723 |
< |
return new SubMapKeyIterator(loEntry(), hiFence()); |
1723 |
> |
return new SubMapKeyIterator(absLowest(), absHighFence()); |
1724 |
|
} |
1725 |
|
|
1726 |
|
Iterator<K> descendingKeyIterator() { |
1727 |
< |
return new DescendingSubMapKeyIterator(hiEntry(), loFence()); |
1727 |
> |
return new DescendingSubMapKeyIterator(absHighest(), absLowFence()); |
1728 |
|
} |
1729 |
|
|
1730 |
< |
class AscendingEntrySetView extends NavigableSubMap.EntrySetView { |
1730 |
> |
final class AscendingEntrySetView extends EntrySetView { |
1731 |
|
public Iterator<Map.Entry<K,V>> iterator() { |
1732 |
< |
return new SubMapEntryIterator(loEntry(), hiFence()); |
1732 |
> |
return new SubMapEntryIterator(absLowest(), absHighFence()); |
1733 |
|
} |
1734 |
|
} |
1735 |
|
|
1738 |
|
return (es != null) ? es : new AscendingEntrySetView(); |
1739 |
|
} |
1740 |
|
|
1741 |
< |
public K firstKey() { |
1742 |
< |
return key(loEntry()); |
1743 |
< |
} |
1744 |
< |
|
1745 |
< |
public K lastKey() { |
1746 |
< |
return key(hiEntry()); |
1728 |
< |
} |
1729 |
< |
|
1730 |
< |
public Map.Entry<K,V> firstEntry() { |
1731 |
< |
return loEntry(); |
1732 |
< |
} |
1733 |
< |
|
1734 |
< |
public Map.Entry<K,V> lastEntry() { |
1735 |
< |
return hiEntry(); |
1736 |
< |
} |
1737 |
< |
|
1738 |
< |
public Map.Entry<K,V> pollFirstEntry() { |
1739 |
< |
return pollLoEntry(); |
1740 |
< |
} |
1741 |
< |
|
1742 |
< |
public Map.Entry<K,V> pollLastEntry() { |
1743 |
< |
return pollHiEntry(); |
1744 |
< |
} |
1745 |
< |
|
1746 |
< |
public NavigableMap<K,V> descendingMap() { |
1747 |
< |
NavigableMap<K,V> mv = descendingMapView; |
1748 |
< |
return (mv != null) ? mv : |
1749 |
< |
(descendingMapView = |
1750 |
< |
new DescendingSubMap(m, |
1751 |
< |
fromStart, lo, loExcluded, |
1752 |
< |
toEnd, hi, hiExcluded)); |
1753 |
< |
} |
1741 |
> |
TreeMap.Entry<K,V> subLowest() { return absLowest(); } |
1742 |
> |
TreeMap.Entry<K,V> subHighest() { return absHighest(); } |
1743 |
> |
TreeMap.Entry<K,V> subCeiling(K key) { return absCeiling(key); } |
1744 |
> |
TreeMap.Entry<K,V> subHigher(K key) { return absHigher(key); } |
1745 |
> |
TreeMap.Entry<K,V> subFloor(K key) { return absFloor(key); } |
1746 |
> |
TreeMap.Entry<K,V> subLower(K key) { return absLower(key); } |
1747 |
|
} |
1748 |
|
|
1749 |
< |
static class DescendingSubMap<K,V> extends NavigableSubMap<K,V> { |
1749 |
> |
/** |
1750 |
> |
* @serial include |
1751 |
> |
*/ |
1752 |
> |
static final class DescendingSubMap<K,V> extends NavigableSubMap<K,V> { |
1753 |
|
private static final long serialVersionUID = 912986545866120460L; |
1754 |
|
DescendingSubMap(TreeMap<K,V> m, |
1755 |
< |
boolean fromStart, K lo, int loExcluded, |
1756 |
< |
boolean toEnd, K hi, int hiExcluded) { |
1757 |
< |
super(m, fromStart, lo, loExcluded, toEnd, hi, hiExcluded); |
1755 |
> |
boolean fromStart, K lo, boolean loInclusive, |
1756 |
> |
boolean toEnd, K hi, boolean hiInclusive) { |
1757 |
> |
super(m, fromStart, lo, loInclusive, toEnd, hi, hiInclusive); |
1758 |
|
} |
1759 |
|
|
1760 |
|
private final Comparator<? super K> reverseComparator = |
1765 |
|
} |
1766 |
|
|
1767 |
|
public NavigableMap<K,V> subMap(K fromKey, boolean fromInclusive, |
1768 |
< |
K toKey, boolean toInclusive) { |
1768 |
> |
K toKey, boolean toInclusive) { |
1769 |
|
if (!inRange(fromKey, fromInclusive)) |
1770 |
|
throw new IllegalArgumentException("fromKey out of range"); |
1771 |
|
if (!inRange(toKey, toInclusive)) |
1772 |
|
throw new IllegalArgumentException("toKey out of range"); |
1773 |
|
return new DescendingSubMap(m, |
1774 |
< |
false, toKey, excluded(toInclusive), |
1775 |
< |
false, fromKey, excluded(fromInclusive)); |
1774 |
> |
false, toKey, toInclusive, |
1775 |
> |
false, fromKey, fromInclusive); |
1776 |
|
} |
1777 |
|
|
1778 |
|
public NavigableMap<K,V> headMap(K toKey, boolean inclusive) { |
1779 |
|
if (!inRange(toKey, inclusive)) |
1780 |
|
throw new IllegalArgumentException("toKey out of range"); |
1781 |
|
return new DescendingSubMap(m, |
1782 |
< |
false, toKey, excluded(inclusive), |
1783 |
< |
toEnd, hi, hiExcluded); |
1782 |
> |
false, toKey, inclusive, |
1783 |
> |
toEnd, hi, hiInclusive); |
1784 |
|
} |
1785 |
|
|
1786 |
|
public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive){ |
1787 |
|
if (!inRange(fromKey, inclusive)) |
1788 |
|
throw new IllegalArgumentException("fromKey out of range"); |
1789 |
|
return new DescendingSubMap(m, |
1790 |
< |
fromStart, lo, loExcluded, |
1791 |
< |
false, fromKey, excluded(inclusive)); |
1796 |
< |
} |
1797 |
< |
|
1798 |
< |
Iterator<K> keyIterator() { |
1799 |
< |
return new DescendingSubMapKeyIterator(hiEntry(), loFence()); |
1800 |
< |
} |
1801 |
< |
|
1802 |
< |
Iterator<K> descendingKeyIterator() { |
1803 |
< |
return new SubMapKeyIterator(loEntry(), hiFence()); |
1804 |
< |
} |
1805 |
< |
|
1806 |
< |
class DescendingEntrySetView extends NavigableSubMap.EntrySetView { |
1807 |
< |
public Iterator<Map.Entry<K,V>> iterator() { |
1808 |
< |
return new DescendingSubMapEntryIterator(hiEntry(), loFence()); |
1809 |
< |
} |
1810 |
< |
} |
1811 |
< |
|
1812 |
< |
public Set<Map.Entry<K,V>> entrySet() { |
1813 |
< |
EntrySetView es = entrySetView; |
1814 |
< |
return (es != null) ? es : new DescendingEntrySetView(); |
1815 |
< |
} |
1816 |
< |
|
1817 |
< |
public K firstKey() { |
1818 |
< |
return key(hiEntry()); |
1819 |
< |
} |
1820 |
< |
|
1821 |
< |
public K lastKey() { |
1822 |
< |
return key(loEntry()); |
1823 |
< |
} |
1824 |
< |
|
1825 |
< |
public Map.Entry<K,V> firstEntry() { |
1826 |
< |
return hiEntry(); |
1827 |
< |
} |
1828 |
< |
|
1829 |
< |
public Map.Entry<K,V> lastEntry() { |
1830 |
< |
return loEntry(); |
1831 |
< |
} |
1832 |
< |
|
1833 |
< |
public Map.Entry<K,V> pollFirstEntry() { |
1834 |
< |
return pollHiEntry(); |
1835 |
< |
} |
1836 |
< |
|
1837 |
< |
public Map.Entry<K,V> pollLastEntry() { |
1838 |
< |
return pollLoEntry(); |
1790 |
> |
fromStart, lo, loInclusive, |
1791 |
> |
false, fromKey, inclusive); |
1792 |
|
} |
1793 |
|
|
1794 |
|
public NavigableMap<K,V> descendingMap() { |
1796 |
|
return (mv != null) ? mv : |
1797 |
|
(descendingMapView = |
1798 |
|
new AscendingSubMap(m, |
1799 |
< |
fromStart, lo, loExcluded, |
1800 |
< |
toEnd, hi, hiExcluded)); |
1799 |
> |
fromStart, lo, loInclusive, |
1800 |
> |
toEnd, hi, hiInclusive)); |
1801 |
|
} |
1802 |
|
|
1803 |
< |
@Override TreeMap.Entry<K,V> subCeiling(K key) { |
1804 |
< |
return super.subFloor(key); |
1803 |
> |
Iterator<K> keyIterator() { |
1804 |
> |
return new DescendingSubMapKeyIterator(absHighest(), absLowFence()); |
1805 |
|
} |
1806 |
|
|
1807 |
< |
@Override TreeMap.Entry<K,V> subHigher(K key) { |
1808 |
< |
return super.subLower(key); |
1807 |
> |
Iterator<K> descendingKeyIterator() { |
1808 |
> |
return new SubMapKeyIterator(absLowest(), absHighFence()); |
1809 |
|
} |
1810 |
|
|
1811 |
< |
@Override TreeMap.Entry<K,V> subFloor(K key) { |
1812 |
< |
return super.subCeiling(key); |
1811 |
> |
final class DescendingEntrySetView extends EntrySetView { |
1812 |
> |
public Iterator<Map.Entry<K,V>> iterator() { |
1813 |
> |
return new DescendingSubMapEntryIterator(absHighest(), absLowFence()); |
1814 |
> |
} |
1815 |
|
} |
1816 |
|
|
1817 |
< |
@Override TreeMap.Entry<K,V> subLower(K key) { |
1818 |
< |
return super.subHigher(key); |
1817 |
> |
public Set<Map.Entry<K,V>> entrySet() { |
1818 |
> |
EntrySetView es = entrySetView; |
1819 |
> |
return (es != null) ? es : new DescendingEntrySetView(); |
1820 |
|
} |
1865 |
– |
} |
1866 |
– |
|
1867 |
– |
/** |
1868 |
– |
* Compares two keys using the correct comparison method for this TreeMap. |
1869 |
– |
*/ |
1870 |
– |
final int compare(Object k1, Object k2) { |
1871 |
– |
return comparator==null ? ((Comparable<? super K>)k1).compareTo((K)k2) |
1872 |
– |
: comparator.compare((K)k1, (K)k2); |
1873 |
– |
} |
1821 |
|
|
1822 |
< |
/** |
1823 |
< |
* Test two values for equality. Differs from o1.equals(o2) only in |
1824 |
< |
* that it copes with <tt>null</tt> o1 properly. |
1825 |
< |
*/ |
1826 |
< |
final static boolean valEquals(Object o1, Object o2) { |
1827 |
< |
return (o1==null ? o2==null : o1.equals(o2)); |
1822 |
> |
TreeMap.Entry<K,V> subLowest() { return absHighest(); } |
1823 |
> |
TreeMap.Entry<K,V> subHighest() { return absLowest(); } |
1824 |
> |
TreeMap.Entry<K,V> subCeiling(K key) { return absFloor(key); } |
1825 |
> |
TreeMap.Entry<K,V> subHigher(K key) { return absLower(key); } |
1826 |
> |
TreeMap.Entry<K,V> subFloor(K key) { return absCeiling(key); } |
1827 |
> |
TreeMap.Entry<K,V> subLower(K key) { return absHigher(key); } |
1828 |
|
} |
1829 |
|
|
1830 |
|
/** |
1833 |
|
* support NavigableMap. It translates an old-version SubMap into |
1834 |
|
* a new-version AscendingSubMap. This class is never otherwise |
1835 |
|
* used. |
1836 |
+ |
* |
1837 |
+ |
* @serial include |
1838 |
|
*/ |
1839 |
|
private class SubMap extends AbstractMap<K,V> |
1840 |
|
implements SortedMap<K,V>, java.io.Serializable { |
1843 |
|
private K fromKey, toKey; |
1844 |
|
private Object readResolve() { |
1845 |
|
return new AscendingSubMap(TreeMap.this, |
1846 |
< |
fromStart, fromKey, 0, |
1847 |
< |
toEnd, toKey, 1); |
1846 |
> |
fromStart, fromKey, true, |
1847 |
> |
toEnd, toKey, false); |
1848 |
|
} |
1849 |
|
public Set<Map.Entry<K,V>> entrySet() { throw new InternalError(); } |
1850 |
|
public K lastKey() { throw new InternalError(); } |
1856 |
|
} |
1857 |
|
|
1858 |
|
|
1859 |
+ |
// Red-black mechanics |
1860 |
+ |
|
1861 |
|
private static final boolean RED = false; |
1862 |
|
private static final boolean BLACK = true; |
1863 |
|
|
1918 |
|
public boolean equals(Object o) { |
1919 |
|
if (!(o instanceof Map.Entry)) |
1920 |
|
return false; |
1921 |
< |
Map.Entry e = (Map.Entry)o; |
1921 |
> |
Map.Entry<?,?> e = (Map.Entry<?,?>)o; |
1922 |
|
|
1923 |
|
return valEquals(key,e.getKey()) && valEquals(value,e.getValue()); |
1924 |
|
} |
2033 |
|
return (p == null) ? null: p.right; |
2034 |
|
} |
2035 |
|
|
2036 |
< |
/** From CLR **/ |
2036 |
> |
/** From CLR */ |
2037 |
|
private void rotateLeft(Entry<K,V> p) { |
2038 |
< |
Entry<K,V> r = p.right; |
2039 |
< |
p.right = r.left; |
2040 |
< |
if (r.left != null) |
2041 |
< |
r.left.parent = p; |
2042 |
< |
r.parent = p.parent; |
2043 |
< |
if (p.parent == null) |
2044 |
< |
root = r; |
2045 |
< |
else if (p.parent.left == p) |
2046 |
< |
p.parent.left = r; |
2047 |
< |
else |
2048 |
< |
p.parent.right = r; |
2049 |
< |
r.left = p; |
2050 |
< |
p.parent = r; |
2038 |
> |
if (p != null) { |
2039 |
> |
Entry<K,V> r = p.right; |
2040 |
> |
p.right = r.left; |
2041 |
> |
if (r.left != null) |
2042 |
> |
r.left.parent = p; |
2043 |
> |
r.parent = p.parent; |
2044 |
> |
if (p.parent == null) |
2045 |
> |
root = r; |
2046 |
> |
else if (p.parent.left == p) |
2047 |
> |
p.parent.left = r; |
2048 |
> |
else |
2049 |
> |
p.parent.right = r; |
2050 |
> |
r.left = p; |
2051 |
> |
p.parent = r; |
2052 |
> |
} |
2053 |
|
} |
2054 |
|
|
2055 |
< |
/** From CLR **/ |
2055 |
> |
/** From CLR */ |
2056 |
|
private void rotateRight(Entry<K,V> p) { |
2057 |
< |
Entry<K,V> l = p.left; |
2058 |
< |
p.left = l.right; |
2059 |
< |
if (l.right != null) l.right.parent = p; |
2060 |
< |
l.parent = p.parent; |
2061 |
< |
if (p.parent == null) |
2062 |
< |
root = l; |
2063 |
< |
else if (p.parent.right == p) |
2064 |
< |
p.parent.right = l; |
2065 |
< |
else p.parent.left = l; |
2066 |
< |
l.right = p; |
2067 |
< |
p.parent = l; |
2057 |
> |
if (p != null) { |
2058 |
> |
Entry<K,V> l = p.left; |
2059 |
> |
p.left = l.right; |
2060 |
> |
if (l.right != null) l.right.parent = p; |
2061 |
> |
l.parent = p.parent; |
2062 |
> |
if (p.parent == null) |
2063 |
> |
root = l; |
2064 |
> |
else if (p.parent.right == p) |
2065 |
> |
p.parent.right = l; |
2066 |
> |
else p.parent.left = l; |
2067 |
> |
l.right = p; |
2068 |
> |
p.parent = l; |
2069 |
> |
} |
2070 |
|
} |
2071 |
|
|
2072 |
< |
|
2118 |
< |
/** From CLR **/ |
2072 |
> |
/** From CLR */ |
2073 |
|
private void fixAfterInsertion(Entry<K,V> x) { |
2074 |
|
x.color = RED; |
2075 |
|
|
2088 |
|
} |
2089 |
|
setColor(parentOf(x), BLACK); |
2090 |
|
setColor(parentOf(parentOf(x)), RED); |
2091 |
< |
if (parentOf(parentOf(x)) != null) |
2138 |
< |
rotateRight(parentOf(parentOf(x))); |
2091 |
> |
rotateRight(parentOf(parentOf(x))); |
2092 |
|
} |
2093 |
|
} else { |
2094 |
|
Entry<K,V> y = leftOf(parentOf(parentOf(x))); |
2104 |
|
} |
2105 |
|
setColor(parentOf(x), BLACK); |
2106 |
|
setColor(parentOf(parentOf(x)), RED); |
2107 |
< |
if (parentOf(parentOf(x)) != null) |
2155 |
< |
rotateLeft(parentOf(parentOf(x))); |
2107 |
> |
rotateLeft(parentOf(parentOf(x))); |
2108 |
|
} |
2109 |
|
} |
2110 |
|
} |
2114 |
|
/** |
2115 |
|
* Delete node p, and then rebalance the tree. |
2116 |
|
*/ |
2165 |
– |
|
2117 |
|
private void deleteEntry(Entry<K,V> p) { |
2118 |
< |
decrementSize(); |
2118 |
> |
modCount++; |
2119 |
> |
size--; |
2120 |
|
|
2121 |
|
// If strictly internal, copy successor's element to p and then make p |
2122 |
|
// point to successor. |
2162 |
|
} |
2163 |
|
} |
2164 |
|
|
2165 |
< |
/** From CLR **/ |
2165 |
> |
/** From CLR */ |
2166 |
|
private void fixAfterDeletion(Entry<K,V> x) { |
2167 |
|
while (x != root && colorOf(x) == BLACK) { |
2168 |
|
if (x == leftOf(parentOf(x))) { |
2270 |
|
buildFromSorted(size, null, s, null); |
2271 |
|
} |
2272 |
|
|
2273 |
< |
/** Intended to be called only from TreeSet.readObject **/ |
2273 |
> |
/** Intended to be called only from TreeSet.readObject */ |
2274 |
|
void readTreeSet(int size, java.io.ObjectInputStream s, V defaultVal) |
2275 |
|
throws java.io.IOException, ClassNotFoundException { |
2276 |
|
buildFromSorted(size, null, s, defaultVal); |
2277 |
|
} |
2278 |
|
|
2279 |
< |
/** Intended to be called only from TreeSet.addAll **/ |
2279 |
> |
/** Intended to be called only from TreeSet.addAll */ |
2280 |
|
void addAllForTreeSet(SortedSet<? extends K> set, V defaultVal) { |
2281 |
|
try { |
2282 |
|
buildFromSorted(set.size(), set.iterator(), null, defaultVal); |
2359 |
|
|
2360 |
|
if (hi < lo) return null; |
2361 |
|
|
2362 |
< |
int mid = (lo + hi) / 2; |
2362 |
> |
int mid = (lo + hi) >>> 1; |
2363 |
|
|
2364 |
|
Entry<K,V> left = null; |
2365 |
|
if (lo < mid) |