11 |
|
/** |
12 |
|
* Red-Black tree based implementation of the <tt>NavigableMap</tt> interface. |
13 |
|
* This class guarantees that the map will be in ascending key order, sorted |
14 |
< |
* according to the <i>natural order</i> for the key's class (see |
14 |
> |
* according to the <i>natural order</i> for the keys' class (see |
15 |
|
* <tt>Comparable</tt>), or by the comparator provided at creation time, |
16 |
|
* depending on which constructor is used.<p> |
17 |
|
* |
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 |
542 |
|
* @param key key with which the specified value is to be associated. |
543 |
|
* @param value value to be associated with the specified key. |
544 |
|
* |
545 |
< |
* @return previous value associated with specified key, or <tt>null</tt> |
545 |
> |
* @return the previous value associated with specified key, or <tt>null</tt> |
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. |
591 |
|
* Removes the mapping for this key from this TreeMap if present. |
592 |
|
* |
593 |
|
* @param key key for which mapping should be removed |
594 |
< |
* @return previous value associated with specified key, or <tt>null</tt> |
594 |
> |
* @return the previous value associated with specified key, or <tt>null</tt> |
595 |
|
* if there was no mapping for key. A <tt>null</tt> return can |
596 |
|
* also indicate that the map previously associated |
597 |
|
* <tt>null</tt> with the specified key. |
670 |
|
/** |
671 |
|
* Returns a key-value mapping associated with the greatest |
672 |
|
* key in this map, or <tt>null</tt> if the map is empty. |
673 |
– |
* The returned entry does <em>not</em> support |
674 |
– |
* the <tt>Entry.setValue</tt> method. |
673 |
|
* |
674 |
|
* @return an Entry with greatest key, or <tt>null</tt> |
675 |
|
* if the map is empty. |
1143 |
|
* the key-value mappings in <tt>m</tt> whose keys are less than or equal |
1144 |
|
* to <tt>high</tt>: |
1145 |
|
* <pre> |
1146 |
< |
* NavigableMap head = m.headMap(high+"\0"); |
1146 |
> |
* NavigableMap head = m.navigableHeadMap(high+"\0"); |
1147 |
|
* </pre> |
1148 |
|
* |
1149 |
|
* @param toKey high endpoint (exclusive) of the headMap. |
1183 |
|
* are strings. The following idiom obtains a view containing |
1184 |
|
* all of the key-value mappings in <tt>m</tt> whose keys are strictly |
1185 |
|
* greater than <tt>low</tt>: <pre> |
1186 |
< |
* NavigableMap tail = m.tailMap(low+"\0"); |
1186 |
> |
* NavigableMap tail = m.navigableTailMap(low+"\0"); |
1187 |
|
* </pre> |
1188 |
|
* |
1189 |
|
* @param fromKey low endpoint (inclusive) of the tailMap. |
1308 |
|
} |
1309 |
|
|
1310 |
|
public boolean isEmpty() { |
1311 |
< |
return entrySet.isEmpty(); |
1311 |
> |
return entrySet().isEmpty(); |
1312 |
|
} |
1313 |
|
|
1314 |
|
public boolean containsKey(Object key) { |
1372 |
|
public Map.Entry<K,V> pollFirstEntry() { |
1373 |
|
TreeMap.Entry<K,V> e = fromStart ? |
1374 |
|
getFirstEntry() : getCeilingEntry(fromKey); |
1375 |
< |
if (e == null || (!fromStart && compare(e.key, fromKey) < 0)) |
1375 |
> |
if (e == null || (!toEnd && compare(e.key, toKey) >= 0)) |
1376 |
|
return null; |
1377 |
|
Map.Entry result = new AbstractMap.SimpleImmutableEntry(e); |
1378 |
|
deleteEntry(e); |
1382 |
|
public Map.Entry<K,V> pollLastEntry() { |
1383 |
|
TreeMap.Entry<K,V> e = toEnd ? |
1384 |
|
getLastEntry() : getLowerEntry(toKey); |
1385 |
< |
if (e == null || (!toEnd && compare(e.key, toKey) >= 0)) |
1385 |
> |
if (e == null || (!fromStart && compare(e.key, fromKey) < 0)) |
1386 |
|
return null; |
1387 |
|
Map.Entry result = new AbstractMap.SimpleImmutableEntry(e); |
1388 |
|
deleteEntry(e); |
1462 |
|
return e == null? null : e.key; |
1463 |
|
} |
1464 |
|
|
1465 |
< |
private transient Set<Map.Entry<K,V>> entrySet = new EntrySetView(); |
1465 |
> |
private transient Set<Map.Entry<K,V>> entrySet = null; |
1466 |
|
|
1467 |
|
public Set<Map.Entry<K,V>> entrySet() { |
1468 |
< |
return entrySet; |
1468 |
> |
Set<Map.Entry<K,V>> es = entrySet; |
1469 |
> |
return (es != null)? es : (entrySet = new EntrySetView()); |
1470 |
|
} |
1471 |
|
|
1472 |
|
private class EntrySetView extends AbstractSet<Map.Entry<K,V>> { |
2163 |
|
// Write out size (number of Mappings) |
2164 |
|
s.writeInt(size); |
2165 |
|
|
2166 |
+ |
Set<Map.Entry<K,V>> es = entrySet(); |
2167 |
|
// Write out keys and values (alternating) |
2168 |
< |
for (Iterator<Map.Entry<K,V>> i = entrySet().iterator(); i.hasNext(); ) { |
2168 |
> |
for (Iterator<Map.Entry<K,V>> i = es.iterator(); i.hasNext(); ) { |
2169 |
|
Map.Entry<K,V> e = i.next(); |
2170 |
|
s.writeObject(e.getKey()); |
2171 |
|
s.writeObject(e.getValue()); |