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 |
|
/** |
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 |
|
/** |
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 |
|
} |
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 |
|
} |
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 |
|
|
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 |
|
/** |
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 |
|
/** |
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 |
|
/** |
1308 |
|
getFirstEntry() : getCeilingEntry(fromKey); |
1309 |
|
if (e == null || (!fromStart && compare(e.key, fromKey) < 0)) |
1310 |
|
return null; |
1311 |
< |
Map.Entry result = new SnapshotEntry(e); |
1311 |
> |
Map.Entry result = new AbstractMap.SimpleImmutableEntry(e); |
1312 |
|
deleteEntry(e); |
1313 |
|
return result; |
1314 |
|
} |
1318 |
|
getLastEntry() : getLowerEntry(toKey); |
1319 |
|
if (e == null || (!toEnd && compare(e.key, toKey) >= 0)) |
1320 |
|
return null; |
1321 |
< |
Map.Entry result = new SnapshotEntry(e); |
1321 |
> |
Map.Entry result = new AbstractMap.SimpleImmutableEntry(e); |
1322 |
|
deleteEntry(e); |
1323 |
|
return result; |
1324 |
|
} |
1333 |
|
|
1334 |
|
public Map.Entry<K,V> ceilingEntry(K key) { |
1335 |
|
TreeMap.Entry<K,V> e = subceiling(key); |
1336 |
< |
return e == null? null : new SnapshotEntry(e); |
1336 |
> |
return e == null? null : new AbstractMap.SimpleImmutableEntry(e); |
1337 |
|
} |
1338 |
|
|
1339 |
|
public K ceilingKey(K key) { |
1352 |
|
|
1353 |
|
public Map.Entry<K,V> higherEntry(K key) { |
1354 |
|
TreeMap.Entry<K,V> e = subhigher(key); |
1355 |
< |
return e == null? null : new SnapshotEntry(e); |
1355 |
> |
return e == null? null : new AbstractMap.SimpleImmutableEntry(e); |
1356 |
|
} |
1357 |
|
|
1358 |
|
public K higherKey(K key) { |
1370 |
|
|
1371 |
|
public Map.Entry<K,V> floorEntry(K key) { |
1372 |
|
TreeMap.Entry<K,V> e = subfloor(key); |
1373 |
< |
return e == null? null : new SnapshotEntry(e); |
1373 |
> |
return e == null? null : new AbstractMap.SimpleImmutableEntry(e); |
1374 |
|
} |
1375 |
|
|
1376 |
|
public K floorKey(K key) { |
1388 |
|
|
1389 |
|
public Map.Entry<K,V> lowerEntry(K key) { |
1390 |
|
TreeMap.Entry<K,V> e = sublower(key); |
1391 |
< |
return e == null? null : new SnapshotEntry(e); |
1391 |
> |
return e == null? null : new AbstractMap.SimpleImmutableEntry(e); |
1392 |
|
} |
1393 |
|
|
1394 |
|
public K lowerKey(K key) { |
2260 |
|
return level; |
2261 |
|
} |
2262 |
|
|
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 |
– |
|
2263 |
|
} |