346 |
|
final Comparator<? super K> comparator; |
347 |
|
|
348 |
|
/** Lazily initialized key set */ |
349 |
< |
private transient KeySet<K> keySet; |
349 |
> |
private transient KeySet<K,V> keySet; |
350 |
|
/** Lazily initialized entry set */ |
351 |
|
private transient EntrySet<K,V> entrySet; |
352 |
|
/** Lazily initialized values collection */ |
353 |
< |
private transient Values<V> values; |
353 |
> |
private transient Values<K,V> values; |
354 |
|
/** Lazily initialized descending key set */ |
355 |
|
private transient ConcurrentNavigableMap<K,V> descendingMap; |
356 |
|
|
1798 |
|
* @return a navigable set view of the keys in this map |
1799 |
|
*/ |
1800 |
|
public NavigableSet<K> keySet() { |
1801 |
< |
KeySet<K> ks = keySet; |
1802 |
< |
return (ks != null) ? ks : (keySet = new KeySet<K>(this)); |
1801 |
> |
KeySet<K,V> ks = keySet; |
1802 |
> |
return (ks != null) ? ks : (keySet = new KeySet<>(this)); |
1803 |
|
} |
1804 |
|
|
1805 |
|
public NavigableSet<K> navigableKeySet() { |
1806 |
< |
KeySet<K> ks = keySet; |
1807 |
< |
return (ks != null) ? ks : (keySet = new KeySet<K>(this)); |
1806 |
> |
KeySet<K,V> ks = keySet; |
1807 |
> |
return (ks != null) ? ks : (keySet = new KeySet<>(this)); |
1808 |
|
} |
1809 |
|
|
1810 |
|
/** |
1827 |
|
* <a href="package-summary.html#Weakly"><i>weakly consistent</i></a>. |
1828 |
|
*/ |
1829 |
|
public Collection<V> values() { |
1830 |
< |
Values<V> vs = values; |
1831 |
< |
return (vs != null) ? vs : (values = new Values<V>(this)); |
1830 |
> |
Values<K,V> vs = values; |
1831 |
> |
return (vs != null) ? vs : (values = new Values<>(this)); |
1832 |
|
} |
1833 |
|
|
1834 |
|
/** |
2341 |
|
return list; |
2342 |
|
} |
2343 |
|
|
2344 |
< |
static final class KeySet<E> |
2345 |
< |
extends AbstractSet<E> implements NavigableSet<E> { |
2346 |
< |
final ConcurrentNavigableMap<E,?> m; |
2347 |
< |
KeySet(ConcurrentNavigableMap<E,?> map) { m = map; } |
2344 |
> |
static final class KeySet<K,V> |
2345 |
> |
extends AbstractSet<K> implements NavigableSet<K> { |
2346 |
> |
final ConcurrentNavigableMap<K,V> m; |
2347 |
> |
KeySet(ConcurrentNavigableMap<K,V> map) { m = map; } |
2348 |
|
public int size() { return m.size(); } |
2349 |
|
public boolean isEmpty() { return m.isEmpty(); } |
2350 |
|
public boolean contains(Object o) { return m.containsKey(o); } |
2351 |
|
public boolean remove(Object o) { return m.remove(o) != null; } |
2352 |
|
public void clear() { m.clear(); } |
2353 |
< |
public E lower(E e) { return m.lowerKey(e); } |
2354 |
< |
public E floor(E e) { return m.floorKey(e); } |
2355 |
< |
public E ceiling(E e) { return m.ceilingKey(e); } |
2356 |
< |
public E higher(E e) { return m.higherKey(e); } |
2357 |
< |
public Comparator<? super E> comparator() { return m.comparator(); } |
2358 |
< |
public E first() { return m.firstKey(); } |
2359 |
< |
public E last() { return m.lastKey(); } |
2360 |
< |
public E pollFirst() { |
2361 |
< |
Map.Entry<E,?> e = m.pollFirstEntry(); |
2353 |
> |
public K lower(K e) { return m.lowerKey(e); } |
2354 |
> |
public K floor(K e) { return m.floorKey(e); } |
2355 |
> |
public K ceiling(K e) { return m.ceilingKey(e); } |
2356 |
> |
public K higher(K e) { return m.higherKey(e); } |
2357 |
> |
public Comparator<? super K> comparator() { return m.comparator(); } |
2358 |
> |
public K first() { return m.firstKey(); } |
2359 |
> |
public K last() { return m.lastKey(); } |
2360 |
> |
public K pollFirst() { |
2361 |
> |
Map.Entry<K,V> e = m.pollFirstEntry(); |
2362 |
|
return (e == null) ? null : e.getKey(); |
2363 |
|
} |
2364 |
< |
public E pollLast() { |
2365 |
< |
Map.Entry<E,?> e = m.pollLastEntry(); |
2364 |
> |
public K pollLast() { |
2365 |
> |
Map.Entry<K,V> e = m.pollLastEntry(); |
2366 |
|
return (e == null) ? null : e.getKey(); |
2367 |
|
} |
2368 |
< |
@SuppressWarnings("unchecked") |
2369 |
< |
public Iterator<E> iterator() { |
2368 |
> |
public Iterator<K> iterator() { |
2369 |
|
if (m instanceof ConcurrentSkipListMap) |
2370 |
< |
return ((ConcurrentSkipListMap<E,Object>)m).keyIterator(); |
2370 |
> |
return ((ConcurrentSkipListMap<K,V>)m).keyIterator(); |
2371 |
|
else |
2372 |
< |
return ((ConcurrentSkipListMap.SubMap<E,Object>)m).keyIterator(); |
2372 |
> |
return ((ConcurrentSkipListMap.SubMap<K,V>)m).keyIterator(); |
2373 |
|
} |
2374 |
|
public boolean equals(Object o) { |
2375 |
|
if (o == this) |
2387 |
|
} |
2388 |
|
public Object[] toArray() { return toList(this).toArray(); } |
2389 |
|
public <T> T[] toArray(T[] a) { return toList(this).toArray(a); } |
2390 |
< |
public Iterator<E> descendingIterator() { |
2390 |
> |
public Iterator<K> descendingIterator() { |
2391 |
|
return descendingSet().iterator(); |
2392 |
|
} |
2393 |
< |
public NavigableSet<E> subSet(E fromElement, |
2393 |
> |
public NavigableSet<K> subSet(K fromElement, |
2394 |
|
boolean fromInclusive, |
2395 |
< |
E toElement, |
2395 |
> |
K toElement, |
2396 |
|
boolean toInclusive) { |
2397 |
< |
return new KeySet<E>(m.subMap(fromElement, fromInclusive, |
2398 |
< |
toElement, toInclusive)); |
2397 |
> |
return new KeySet<>(m.subMap(fromElement, fromInclusive, |
2398 |
> |
toElement, toInclusive)); |
2399 |
|
} |
2400 |
< |
public NavigableSet<E> headSet(E toElement, boolean inclusive) { |
2401 |
< |
return new KeySet<E>(m.headMap(toElement, inclusive)); |
2400 |
> |
public NavigableSet<K> headSet(K toElement, boolean inclusive) { |
2401 |
> |
return new KeySet<>(m.headMap(toElement, inclusive)); |
2402 |
|
} |
2403 |
< |
public NavigableSet<E> tailSet(E fromElement, boolean inclusive) { |
2404 |
< |
return new KeySet<E>(m.tailMap(fromElement, inclusive)); |
2403 |
> |
public NavigableSet<K> tailSet(K fromElement, boolean inclusive) { |
2404 |
> |
return new KeySet<>(m.tailMap(fromElement, inclusive)); |
2405 |
|
} |
2406 |
< |
public NavigableSet<E> subSet(E fromElement, E toElement) { |
2406 |
> |
public NavigableSet<K> subSet(K fromElement, K toElement) { |
2407 |
|
return subSet(fromElement, true, toElement, false); |
2408 |
|
} |
2409 |
< |
public NavigableSet<E> headSet(E toElement) { |
2409 |
> |
public NavigableSet<K> headSet(K toElement) { |
2410 |
|
return headSet(toElement, false); |
2411 |
|
} |
2412 |
< |
public NavigableSet<E> tailSet(E fromElement) { |
2412 |
> |
public NavigableSet<K> tailSet(K fromElement) { |
2413 |
|
return tailSet(fromElement, true); |
2414 |
|
} |
2415 |
< |
public NavigableSet<E> descendingSet() { |
2416 |
< |
return new KeySet<E>(m.descendingMap()); |
2415 |
> |
public NavigableSet<K> descendingSet() { |
2416 |
> |
return new KeySet<>(m.descendingMap()); |
2417 |
|
} |
2418 |
|
@SuppressWarnings("unchecked") |
2419 |
< |
public Spliterator<E> spliterator() { |
2419 |
> |
public Spliterator<K> spliterator() { |
2420 |
|
if (m instanceof ConcurrentSkipListMap) |
2421 |
< |
return ((ConcurrentSkipListMap<E,?>)m).keySpliterator(); |
2421 |
> |
return ((ConcurrentSkipListMap<K,V>)m).keySpliterator(); |
2422 |
|
else |
2423 |
< |
return (Spliterator<E>)((SubMap<E,?>)m).keyIterator(); |
2423 |
> |
return (Spliterator<K>)((SubMap<K,V>)m).keyIterator(); |
2424 |
|
} |
2425 |
|
} |
2426 |
|
|
2427 |
< |
static final class Values<E> extends AbstractCollection<E> { |
2428 |
< |
final ConcurrentNavigableMap<?,E> m; |
2429 |
< |
Values(ConcurrentNavigableMap<?,E> map) { |
2427 |
> |
static final class Values<K,V> extends AbstractCollection<V> { |
2428 |
> |
final ConcurrentNavigableMap<K,V> m; |
2429 |
> |
Values(ConcurrentNavigableMap<K,V> map) { |
2430 |
|
m = map; |
2431 |
|
} |
2432 |
< |
@SuppressWarnings("unchecked") |
2434 |
< |
public Iterator<E> iterator() { |
2432 |
> |
public Iterator<V> iterator() { |
2433 |
|
if (m instanceof ConcurrentSkipListMap) |
2434 |
< |
return ((ConcurrentSkipListMap<?,E>)m).valueIterator(); |
2434 |
> |
return ((ConcurrentSkipListMap<K,V>)m).valueIterator(); |
2435 |
|
else |
2436 |
< |
return ((SubMap<?,E>)m).valueIterator(); |
2439 |
< |
} |
2440 |
< |
public boolean isEmpty() { |
2441 |
< |
return m.isEmpty(); |
2442 |
< |
} |
2443 |
< |
public int size() { |
2444 |
< |
return m.size(); |
2445 |
< |
} |
2446 |
< |
public boolean contains(Object o) { |
2447 |
< |
return m.containsValue(o); |
2448 |
< |
} |
2449 |
< |
public void clear() { |
2450 |
< |
m.clear(); |
2436 |
> |
return ((SubMap<K,V>)m).valueIterator(); |
2437 |
|
} |
2438 |
+ |
public int size() { return m.size(); } |
2439 |
+ |
public boolean isEmpty() { return m.isEmpty(); } |
2440 |
+ |
public boolean contains(Object o) { return m.containsValue(o); } |
2441 |
+ |
public void clear() { m.clear(); } |
2442 |
|
public Object[] toArray() { return toList(this).toArray(); } |
2443 |
|
public <T> T[] toArray(T[] a) { return toList(this).toArray(a); } |
2444 |
|
@SuppressWarnings("unchecked") |
2445 |
< |
public Spliterator<E> spliterator() { |
2445 |
> |
public Spliterator<V> spliterator() { |
2446 |
|
if (m instanceof ConcurrentSkipListMap) |
2447 |
< |
return ((ConcurrentSkipListMap<?,E>)m).valueSpliterator(); |
2447 |
> |
return ((ConcurrentSkipListMap<K,V>)m).valueSpliterator(); |
2448 |
|
else |
2449 |
< |
return (Spliterator<E>)((SubMap<?,E>)m).valueIterator(); |
2449 |
> |
return (Spliterator<V>)((SubMap<K,V>)m).valueIterator(); |
2450 |
|
} |
2451 |
|
|
2452 |
< |
public boolean removeIf(Predicate<? super E> filter) { |
2452 |
> |
public boolean removeIf(Predicate<? super V> filter) { |
2453 |
|
if (filter == null) throw new NullPointerException(); |
2454 |
|
if (m instanceof ConcurrentSkipListMap) |
2455 |
< |
return ((ConcurrentSkipListMap<?,E>)m).removeValueIf(filter); |
2455 |
> |
return ((ConcurrentSkipListMap<K,V>)m).removeValueIf(filter); |
2456 |
|
// else use iterator |
2457 |
< |
@SuppressWarnings("unchecked") Iterator<Map.Entry<Object,E>> it = |
2468 |
< |
((SubMap<Object,E>)m).entryIterator(); |
2457 |
> |
Iterator<Map.Entry<K,V>> it = ((SubMap<K,V>)m).entryIterator(); |
2458 |
|
boolean removed = false; |
2459 |
|
while (it.hasNext()) { |
2460 |
< |
Map.Entry<Object,E> e = it.next(); |
2461 |
< |
E v = e.getValue(); |
2460 |
> |
Map.Entry<K,V> e = it.next(); |
2461 |
> |
V v = e.getValue(); |
2462 |
|
if (filter.test(v) && m.remove(e.getKey(), v)) |
2463 |
|
removed = true; |
2464 |
|
} |
2466 |
|
} |
2467 |
|
} |
2468 |
|
|
2469 |
< |
static final class EntrySet<K1,V1> extends AbstractSet<Map.Entry<K1,V1>> { |
2470 |
< |
final ConcurrentNavigableMap<K1, V1> m; |
2471 |
< |
EntrySet(ConcurrentNavigableMap<K1, V1> map) { |
2469 |
> |
static final class EntrySet<K,V> extends AbstractSet<Map.Entry<K,V>> { |
2470 |
> |
final ConcurrentNavigableMap<K,V> m; |
2471 |
> |
EntrySet(ConcurrentNavigableMap<K,V> map) { |
2472 |
|
m = map; |
2473 |
|
} |
2474 |
< |
@SuppressWarnings("unchecked") |
2486 |
< |
public Iterator<Map.Entry<K1,V1>> iterator() { |
2474 |
> |
public Iterator<Map.Entry<K,V>> iterator() { |
2475 |
|
if (m instanceof ConcurrentSkipListMap) |
2476 |
< |
return ((ConcurrentSkipListMap<K1,V1>)m).entryIterator(); |
2476 |
> |
return ((ConcurrentSkipListMap<K,V>)m).entryIterator(); |
2477 |
|
else |
2478 |
< |
return ((SubMap<K1,V1>)m).entryIterator(); |
2478 |
> |
return ((SubMap<K,V>)m).entryIterator(); |
2479 |
|
} |
2480 |
|
|
2481 |
|
public boolean contains(Object o) { |
2482 |
|
if (!(o instanceof Map.Entry)) |
2483 |
|
return false; |
2484 |
|
Map.Entry<?,?> e = (Map.Entry<?,?>)o; |
2485 |
< |
V1 v = m.get(e.getKey()); |
2485 |
> |
V v = m.get(e.getKey()); |
2486 |
|
return v != null && v.equals(e.getValue()); |
2487 |
|
} |
2488 |
|
public boolean remove(Object o) { |
2518 |
|
public Object[] toArray() { return toList(this).toArray(); } |
2519 |
|
public <T> T[] toArray(T[] a) { return toList(this).toArray(a); } |
2520 |
|
@SuppressWarnings("unchecked") |
2521 |
< |
public Spliterator<Map.Entry<K1,V1>> spliterator() { |
2521 |
> |
public Spliterator<Map.Entry<K,V>> spliterator() { |
2522 |
|
if (m instanceof ConcurrentSkipListMap) |
2523 |
< |
return ((ConcurrentSkipListMap<K1,V1>)m).entrySpliterator(); |
2523 |
> |
return ((ConcurrentSkipListMap<K,V>)m).entrySpliterator(); |
2524 |
|
else |
2525 |
< |
return (Spliterator<Map.Entry<K1,V1>>) |
2526 |
< |
((SubMap<K1,V1>)m).entryIterator(); |
2525 |
> |
return (Spliterator<Map.Entry<K,V>>) |
2526 |
> |
((SubMap<K,V>)m).entryIterator(); |
2527 |
|
} |
2528 |
< |
public boolean removeIf(Predicate<? super Entry<K1, V1>> filter) { |
2528 |
> |
public boolean removeIf(Predicate<? super Entry<K,V>> filter) { |
2529 |
|
if (filter == null) throw new NullPointerException(); |
2530 |
|
if (m instanceof ConcurrentSkipListMap) |
2531 |
< |
return ((ConcurrentSkipListMap<K1,V1>)m).removeEntryIf(filter); |
2531 |
> |
return ((ConcurrentSkipListMap<K,V>)m).removeEntryIf(filter); |
2532 |
|
// else use iterator |
2533 |
< |
Iterator<Map.Entry<K1,V1>> it = ((SubMap<K1,V1>)m).entryIterator(); |
2533 |
> |
Iterator<Map.Entry<K,V>> it = ((SubMap<K,V>)m).entryIterator(); |
2534 |
|
boolean removed = false; |
2535 |
|
while (it.hasNext()) { |
2536 |
< |
Map.Entry<K1,V1> e = it.next(); |
2536 |
> |
Map.Entry<K,V> e = it.next(); |
2537 |
|
if (filter.test(e) && m.remove(e.getKey(), e.getValue())) |
2538 |
|
removed = true; |
2539 |
|
} |
2571 |
|
private final boolean isDescending; |
2572 |
|
|
2573 |
|
// Lazily initialized view holders |
2574 |
< |
private transient KeySet<K> keySetView; |
2574 |
> |
private transient KeySet<K,V> keySetView; |
2575 |
|
private transient Set<Map.Entry<K,V>> entrySetView; |
2576 |
|
private transient Collection<V> valuesView; |
2577 |
|
|
3039 |
|
/* ---------------- Submap Views -------------- */ |
3040 |
|
|
3041 |
|
public NavigableSet<K> keySet() { |
3042 |
< |
KeySet<K> ks = keySetView; |
3043 |
< |
return (ks != null) ? ks : (keySetView = new KeySet<K>(this)); |
3042 |
> |
KeySet<K,V> ks = keySetView; |
3043 |
> |
return (ks != null) ? ks : (keySetView = new KeySet<>(this)); |
3044 |
|
} |
3045 |
|
|
3046 |
|
public NavigableSet<K> navigableKeySet() { |
3047 |
< |
KeySet<K> ks = keySetView; |
3048 |
< |
return (ks != null) ? ks : (keySetView = new KeySet<K>(this)); |
3047 |
> |
KeySet<K,V> ks = keySetView; |
3048 |
> |
return (ks != null) ? ks : (keySetView = new KeySet<>(this)); |
3049 |
|
} |
3050 |
|
|
3051 |
|
public Collection<V> values() { |
3052 |
|
Collection<V> vs = valuesView; |
3053 |
< |
return (vs != null) ? vs : (valuesView = new Values<V>(this)); |
3053 |
> |
return (vs != null) ? vs : (valuesView = new Values<>(this)); |
3054 |
|
} |
3055 |
|
|
3056 |
|
public Set<Map.Entry<K,V>> entrySet() { |