110 |
|
* when computing a snapshot summary of the values in a shared |
111 |
|
* registry. There are three kinds of operation, each with four |
112 |
|
* forms, accepting functions with Keys, Values, Entries, and (Key, |
113 |
< |
* Value) arguments and/or return values. Because the elements of a |
113 |
> |
* Value) arguments and/or return values. (The first three forms are |
114 |
> |
* also available via the {@link #keySet()}, {@link #values()} and |
115 |
> |
* {@link #entrySet()} views). Because the elements of a |
116 |
|
* ConcurrentHashMapV8 are not ordered in any particular way, and may be |
117 |
|
* processed in different orders in different parallel executions, the |
118 |
|
* correctness of supplied functions should not depend on any |
287 |
|
Spliterator<T> split(); |
288 |
|
} |
289 |
|
|
288 |
– |
/** |
289 |
– |
* A view of a ConcurrentHashMapV8 as a {@link Set} of keys, in |
290 |
– |
* which additions may optionally be enabled by mapping to a |
291 |
– |
* common value. This class cannot be directly instantiated. See |
292 |
– |
* {@link #keySet}, {@link #keySet(Object)}, {@link #newKeySet()}, |
293 |
– |
* {@link #newKeySet(int)}. |
294 |
– |
* |
295 |
– |
* <p>The view's {@code iterator} is a "weakly consistent" iterator |
296 |
– |
* that will never throw {@link ConcurrentModificationException}, |
297 |
– |
* and guarantees to traverse elements as they existed upon |
298 |
– |
* construction of the iterator, and may (but is not guaranteed to) |
299 |
– |
* reflect any modifications subsequent to construction. |
300 |
– |
*/ |
301 |
– |
public static class KeySetView<K,V> extends CHMView<K,V> implements Set<K>, java.io.Serializable { |
302 |
– |
private static final long serialVersionUID = 7249069246763182397L; |
303 |
– |
private final V value; |
304 |
– |
KeySetView(ConcurrentHashMapV8<K, V> map, V value) { // non-public |
305 |
– |
super(map); |
306 |
– |
this.value = value; |
307 |
– |
} |
308 |
– |
|
309 |
– |
/** |
310 |
– |
* Returns the map backing this view. |
311 |
– |
* |
312 |
– |
* @return the map backing this view |
313 |
– |
*/ |
314 |
– |
public ConcurrentHashMapV8<K,V> getMap() { return map; } |
315 |
– |
|
316 |
– |
/** |
317 |
– |
* Returns the default mapped value for additions, |
318 |
– |
* or {@code null} if additions are not supported. |
319 |
– |
* |
320 |
– |
* @return the default mapped value for additions, or {@code null} |
321 |
– |
* if not supported. |
322 |
– |
*/ |
323 |
– |
public V getMappedValue() { return value; } |
324 |
– |
|
325 |
– |
// implement Set API |
326 |
– |
|
327 |
– |
public boolean contains(Object o) { return map.containsKey(o); } |
328 |
– |
public boolean remove(Object o) { return map.remove(o) != null; } |
329 |
– |
public Iterator<K> iterator() { return new KeyIterator<K,V>(map); } |
330 |
– |
public boolean add(K e) { |
331 |
– |
V v; |
332 |
– |
if ((v = value) == null) |
333 |
– |
throw new UnsupportedOperationException(); |
334 |
– |
if (e == null) |
335 |
– |
throw new NullPointerException(); |
336 |
– |
return map.internalPutIfAbsent(e, v) == null; |
337 |
– |
} |
338 |
– |
public boolean addAll(Collection<? extends K> c) { |
339 |
– |
boolean added = false; |
340 |
– |
V v; |
341 |
– |
if ((v = value) == null) |
342 |
– |
throw new UnsupportedOperationException(); |
343 |
– |
for (K e : c) { |
344 |
– |
if (e == null) |
345 |
– |
throw new NullPointerException(); |
346 |
– |
if (map.internalPutIfAbsent(e, v) == null) |
347 |
– |
added = true; |
348 |
– |
} |
349 |
– |
return added; |
350 |
– |
} |
351 |
– |
public boolean equals(Object o) { |
352 |
– |
Set<?> c; |
353 |
– |
return ((o instanceof Set) && |
354 |
– |
((c = (Set<?>)o) == this || |
355 |
– |
(containsAll(c) && c.containsAll(this)))); |
356 |
– |
} |
357 |
– |
} |
290 |
|
|
291 |
|
/* |
292 |
|
* Overview: |
571 |
|
|
572 |
|
// views |
573 |
|
private transient KeySetView<K,V> keySet; |
574 |
< |
private transient Values<K,V> values; |
575 |
< |
private transient EntrySet<K,V> entrySet; |
574 |
> |
private transient ValuesView<K,V> values; |
575 |
> |
private transient EntrySetView<K,V> entrySet; |
576 |
|
|
577 |
|
/** For serialization compatibility. Null unless serialized; see below */ |
578 |
|
private Segment<K,V>[] segments; |
3010 |
|
/** |
3011 |
|
* Returns a {@link Collection} view of the values contained in this map. |
3012 |
|
* The collection is backed by the map, so changes to the map are |
3013 |
< |
* reflected in the collection, and vice-versa. The collection |
3082 |
< |
* supports element removal, which removes the corresponding |
3083 |
< |
* mapping from this map, via the {@code Iterator.remove}, |
3084 |
< |
* {@code Collection.remove}, {@code removeAll}, |
3085 |
< |
* {@code retainAll}, and {@code clear} operations. It does not |
3086 |
< |
* support the {@code add} or {@code addAll} operations. |
3087 |
< |
* |
3088 |
< |
* <p>The view's {@code iterator} is a "weakly consistent" iterator |
3089 |
< |
* that will never throw {@link ConcurrentModificationException}, |
3090 |
< |
* and guarantees to traverse elements as they existed upon |
3091 |
< |
* construction of the iterator, and may (but is not guaranteed to) |
3092 |
< |
* reflect any modifications subsequent to construction. |
3013 |
> |
* reflected in the collection, and vice-versa. |
3014 |
|
*/ |
3015 |
< |
public Collection<V> values() { |
3016 |
< |
Values<K,V> vs = values; |
3017 |
< |
return (vs != null) ? vs : (values = new Values<K,V>(this)); |
3015 |
> |
public ValuesView<K,V> values() { |
3016 |
> |
ValuesView<K,V> vs = values; |
3017 |
> |
return (vs != null) ? vs : (values = new ValuesView<K,V>(this)); |
3018 |
|
} |
3019 |
|
|
3020 |
|
/** |
3034 |
|
* reflect any modifications subsequent to construction. |
3035 |
|
*/ |
3036 |
|
public Set<Map.Entry<K,V>> entrySet() { |
3037 |
< |
EntrySet<K,V> es = entrySet; |
3038 |
< |
return (es != null) ? es : (entrySet = new EntrySet<K,V>(this)); |
3037 |
> |
EntrySetView<K,V> es = entrySet; |
3038 |
> |
return (es != null) ? es : (entrySet = new EntrySetView<K,V>(this)); |
3039 |
|
} |
3040 |
|
|
3041 |
|
/** |
3278 |
|
} |
3279 |
|
} |
3280 |
|
|
3360 |
– |
/* ----------------Views -------------- */ |
3361 |
– |
|
3362 |
– |
/** |
3363 |
– |
* Base class for views. |
3364 |
– |
*/ |
3365 |
– |
static abstract class CHMView<K, V> { |
3366 |
– |
final ConcurrentHashMapV8<K, V> map; |
3367 |
– |
CHMView(ConcurrentHashMapV8<K, V> map) { this.map = map; } |
3368 |
– |
public final int size() { return map.size(); } |
3369 |
– |
public final boolean isEmpty() { return map.isEmpty(); } |
3370 |
– |
public final void clear() { map.clear(); } |
3371 |
– |
|
3372 |
– |
// implementations below rely on concrete classes supplying these |
3373 |
– |
abstract public Iterator<?> iterator(); |
3374 |
– |
abstract public boolean contains(Object o); |
3375 |
– |
abstract public boolean remove(Object o); |
3376 |
– |
|
3377 |
– |
private static final String oomeMsg = "Required array size too large"; |
3378 |
– |
|
3379 |
– |
public final Object[] toArray() { |
3380 |
– |
long sz = map.mappingCount(); |
3381 |
– |
if (sz > (long)(MAX_ARRAY_SIZE)) |
3382 |
– |
throw new OutOfMemoryError(oomeMsg); |
3383 |
– |
int n = (int)sz; |
3384 |
– |
Object[] r = new Object[n]; |
3385 |
– |
int i = 0; |
3386 |
– |
Iterator<?> it = iterator(); |
3387 |
– |
while (it.hasNext()) { |
3388 |
– |
if (i == n) { |
3389 |
– |
if (n >= MAX_ARRAY_SIZE) |
3390 |
– |
throw new OutOfMemoryError(oomeMsg); |
3391 |
– |
if (n >= MAX_ARRAY_SIZE - (MAX_ARRAY_SIZE >>> 1) - 1) |
3392 |
– |
n = MAX_ARRAY_SIZE; |
3393 |
– |
else |
3394 |
– |
n += (n >>> 1) + 1; |
3395 |
– |
r = Arrays.copyOf(r, n); |
3396 |
– |
} |
3397 |
– |
r[i++] = it.next(); |
3398 |
– |
} |
3399 |
– |
return (i == n) ? r : Arrays.copyOf(r, i); |
3400 |
– |
} |
3401 |
– |
|
3402 |
– |
@SuppressWarnings("unchecked") public final <T> T[] toArray(T[] a) { |
3403 |
– |
long sz = map.mappingCount(); |
3404 |
– |
if (sz > (long)(MAX_ARRAY_SIZE)) |
3405 |
– |
throw new OutOfMemoryError(oomeMsg); |
3406 |
– |
int m = (int)sz; |
3407 |
– |
T[] r = (a.length >= m) ? a : |
3408 |
– |
(T[])java.lang.reflect.Array |
3409 |
– |
.newInstance(a.getClass().getComponentType(), m); |
3410 |
– |
int n = r.length; |
3411 |
– |
int i = 0; |
3412 |
– |
Iterator<?> it = iterator(); |
3413 |
– |
while (it.hasNext()) { |
3414 |
– |
if (i == n) { |
3415 |
– |
if (n >= MAX_ARRAY_SIZE) |
3416 |
– |
throw new OutOfMemoryError(oomeMsg); |
3417 |
– |
if (n >= MAX_ARRAY_SIZE - (MAX_ARRAY_SIZE >>> 1) - 1) |
3418 |
– |
n = MAX_ARRAY_SIZE; |
3419 |
– |
else |
3420 |
– |
n += (n >>> 1) + 1; |
3421 |
– |
r = Arrays.copyOf(r, n); |
3422 |
– |
} |
3423 |
– |
r[i++] = (T)it.next(); |
3424 |
– |
} |
3425 |
– |
if (a == r && i < n) { |
3426 |
– |
r[i] = null; // null-terminate |
3427 |
– |
return r; |
3428 |
– |
} |
3429 |
– |
return (i == n) ? r : Arrays.copyOf(r, i); |
3430 |
– |
} |
3431 |
– |
|
3432 |
– |
public final int hashCode() { |
3433 |
– |
int h = 0; |
3434 |
– |
for (Iterator<?> it = iterator(); it.hasNext();) |
3435 |
– |
h += it.next().hashCode(); |
3436 |
– |
return h; |
3437 |
– |
} |
3438 |
– |
|
3439 |
– |
public final String toString() { |
3440 |
– |
StringBuilder sb = new StringBuilder(); |
3441 |
– |
sb.append('['); |
3442 |
– |
Iterator<?> it = iterator(); |
3443 |
– |
if (it.hasNext()) { |
3444 |
– |
for (;;) { |
3445 |
– |
Object e = it.next(); |
3446 |
– |
sb.append(e == this ? "(this Collection)" : e); |
3447 |
– |
if (!it.hasNext()) |
3448 |
– |
break; |
3449 |
– |
sb.append(',').append(' '); |
3450 |
– |
} |
3451 |
– |
} |
3452 |
– |
return sb.append(']').toString(); |
3453 |
– |
} |
3454 |
– |
|
3455 |
– |
public final boolean containsAll(Collection<?> c) { |
3456 |
– |
if (c != this) { |
3457 |
– |
for (Iterator<?> it = c.iterator(); it.hasNext();) { |
3458 |
– |
Object e = it.next(); |
3459 |
– |
if (e == null || !contains(e)) |
3460 |
– |
return false; |
3461 |
– |
} |
3462 |
– |
} |
3463 |
– |
return true; |
3464 |
– |
} |
3465 |
– |
|
3466 |
– |
public final boolean removeAll(Collection<?> c) { |
3467 |
– |
boolean modified = false; |
3468 |
– |
for (Iterator<?> it = iterator(); it.hasNext();) { |
3469 |
– |
if (c.contains(it.next())) { |
3470 |
– |
it.remove(); |
3471 |
– |
modified = true; |
3472 |
– |
} |
3473 |
– |
} |
3474 |
– |
return modified; |
3475 |
– |
} |
3476 |
– |
|
3477 |
– |
public final boolean retainAll(Collection<?> c) { |
3478 |
– |
boolean modified = false; |
3479 |
– |
for (Iterator<?> it = iterator(); it.hasNext();) { |
3480 |
– |
if (!c.contains(it.next())) { |
3481 |
– |
it.remove(); |
3482 |
– |
modified = true; |
3483 |
– |
} |
3484 |
– |
} |
3485 |
– |
return modified; |
3486 |
– |
} |
3487 |
– |
|
3488 |
– |
} |
3489 |
– |
|
3490 |
– |
static final class Values<K,V> extends CHMView<K,V> |
3491 |
– |
implements Collection<V> { |
3492 |
– |
Values(ConcurrentHashMapV8<K, V> map) { super(map); } |
3493 |
– |
public final boolean contains(Object o) { return map.containsValue(o); } |
3494 |
– |
public final boolean remove(Object o) { |
3495 |
– |
if (o != null) { |
3496 |
– |
Iterator<V> it = new ValueIterator<K,V>(map); |
3497 |
– |
while (it.hasNext()) { |
3498 |
– |
if (o.equals(it.next())) { |
3499 |
– |
it.remove(); |
3500 |
– |
return true; |
3501 |
– |
} |
3502 |
– |
} |
3503 |
– |
} |
3504 |
– |
return false; |
3505 |
– |
} |
3506 |
– |
public final Iterator<V> iterator() { |
3507 |
– |
return new ValueIterator<K,V>(map); |
3508 |
– |
} |
3509 |
– |
public final boolean add(V e) { |
3510 |
– |
throw new UnsupportedOperationException(); |
3511 |
– |
} |
3512 |
– |
public final boolean addAll(Collection<? extends V> c) { |
3513 |
– |
throw new UnsupportedOperationException(); |
3514 |
– |
} |
3515 |
– |
|
3516 |
– |
} |
3517 |
– |
|
3518 |
– |
static final class EntrySet<K,V> extends CHMView<K,V> |
3519 |
– |
implements Set<Map.Entry<K,V>> { |
3520 |
– |
EntrySet(ConcurrentHashMapV8<K, V> map) { super(map); } |
3521 |
– |
public final boolean contains(Object o) { |
3522 |
– |
Object k, v, r; Map.Entry<?,?> e; |
3523 |
– |
return ((o instanceof Map.Entry) && |
3524 |
– |
(k = (e = (Map.Entry<?,?>)o).getKey()) != null && |
3525 |
– |
(r = map.get(k)) != null && |
3526 |
– |
(v = e.getValue()) != null && |
3527 |
– |
(v == r || v.equals(r))); |
3528 |
– |
} |
3529 |
– |
public final boolean remove(Object o) { |
3530 |
– |
Object k, v; Map.Entry<?,?> e; |
3531 |
– |
return ((o instanceof Map.Entry) && |
3532 |
– |
(k = (e = (Map.Entry<?,?>)o).getKey()) != null && |
3533 |
– |
(v = e.getValue()) != null && |
3534 |
– |
map.remove(k, v)); |
3535 |
– |
} |
3536 |
– |
public final Iterator<Map.Entry<K,V>> iterator() { |
3537 |
– |
return new EntryIterator<K,V>(map); |
3538 |
– |
} |
3539 |
– |
public final boolean add(Entry<K,V> e) { |
3540 |
– |
throw new UnsupportedOperationException(); |
3541 |
– |
} |
3542 |
– |
public final boolean addAll(Collection<? extends Entry<K,V>> c) { |
3543 |
– |
throw new UnsupportedOperationException(); |
3544 |
– |
} |
3545 |
– |
public boolean equals(Object o) { |
3546 |
– |
Set<?> c; |
3547 |
– |
return ((o instanceof Set) && |
3548 |
– |
((c = (Set<?>)o) == this || |
3549 |
– |
(containsAll(c) && c.containsAll(this)))); |
3550 |
– |
} |
3551 |
– |
} |
3552 |
– |
|
3281 |
|
/* ---------------- Serialization Support -------------- */ |
3282 |
|
|
3283 |
|
/** |
3948 |
|
(this, transformer, basis, reducer).invoke(); |
3949 |
|
} |
3950 |
|
|
3951 |
+ |
/* ----------------Views -------------- */ |
3952 |
+ |
|
3953 |
+ |
/** |
3954 |
+ |
* Base class for views. |
3955 |
+ |
*/ |
3956 |
+ |
static abstract class CHMView<K, V> { |
3957 |
+ |
final ConcurrentHashMapV8<K, V> map; |
3958 |
+ |
CHMView(ConcurrentHashMapV8<K, V> map) { this.map = map; } |
3959 |
+ |
|
3960 |
+ |
/** |
3961 |
+ |
* Returns the map backing this view. |
3962 |
+ |
* |
3963 |
+ |
* @return the map backing this view |
3964 |
+ |
*/ |
3965 |
+ |
public ConcurrentHashMapV8<K,V> getMap() { return map; } |
3966 |
+ |
|
3967 |
+ |
public final int size() { return map.size(); } |
3968 |
+ |
public final boolean isEmpty() { return map.isEmpty(); } |
3969 |
+ |
public final void clear() { map.clear(); } |
3970 |
+ |
|
3971 |
+ |
// implementations below rely on concrete classes supplying these |
3972 |
+ |
abstract public Iterator<?> iterator(); |
3973 |
+ |
abstract public boolean contains(Object o); |
3974 |
+ |
abstract public boolean remove(Object o); |
3975 |
+ |
|
3976 |
+ |
private static final String oomeMsg = "Required array size too large"; |
3977 |
+ |
|
3978 |
+ |
public final Object[] toArray() { |
3979 |
+ |
long sz = map.mappingCount(); |
3980 |
+ |
if (sz > (long)(MAX_ARRAY_SIZE)) |
3981 |
+ |
throw new OutOfMemoryError(oomeMsg); |
3982 |
+ |
int n = (int)sz; |
3983 |
+ |
Object[] r = new Object[n]; |
3984 |
+ |
int i = 0; |
3985 |
+ |
Iterator<?> it = iterator(); |
3986 |
+ |
while (it.hasNext()) { |
3987 |
+ |
if (i == n) { |
3988 |
+ |
if (n >= MAX_ARRAY_SIZE) |
3989 |
+ |
throw new OutOfMemoryError(oomeMsg); |
3990 |
+ |
if (n >= MAX_ARRAY_SIZE - (MAX_ARRAY_SIZE >>> 1) - 1) |
3991 |
+ |
n = MAX_ARRAY_SIZE; |
3992 |
+ |
else |
3993 |
+ |
n += (n >>> 1) + 1; |
3994 |
+ |
r = Arrays.copyOf(r, n); |
3995 |
+ |
} |
3996 |
+ |
r[i++] = it.next(); |
3997 |
+ |
} |
3998 |
+ |
return (i == n) ? r : Arrays.copyOf(r, i); |
3999 |
+ |
} |
4000 |
+ |
|
4001 |
+ |
@SuppressWarnings("unchecked") public final <T> T[] toArray(T[] a) { |
4002 |
+ |
long sz = map.mappingCount(); |
4003 |
+ |
if (sz > (long)(MAX_ARRAY_SIZE)) |
4004 |
+ |
throw new OutOfMemoryError(oomeMsg); |
4005 |
+ |
int m = (int)sz; |
4006 |
+ |
T[] r = (a.length >= m) ? a : |
4007 |
+ |
(T[])java.lang.reflect.Array |
4008 |
+ |
.newInstance(a.getClass().getComponentType(), m); |
4009 |
+ |
int n = r.length; |
4010 |
+ |
int i = 0; |
4011 |
+ |
Iterator<?> it = iterator(); |
4012 |
+ |
while (it.hasNext()) { |
4013 |
+ |
if (i == n) { |
4014 |
+ |
if (n >= MAX_ARRAY_SIZE) |
4015 |
+ |
throw new OutOfMemoryError(oomeMsg); |
4016 |
+ |
if (n >= MAX_ARRAY_SIZE - (MAX_ARRAY_SIZE >>> 1) - 1) |
4017 |
+ |
n = MAX_ARRAY_SIZE; |
4018 |
+ |
else |
4019 |
+ |
n += (n >>> 1) + 1; |
4020 |
+ |
r = Arrays.copyOf(r, n); |
4021 |
+ |
} |
4022 |
+ |
r[i++] = (T)it.next(); |
4023 |
+ |
} |
4024 |
+ |
if (a == r && i < n) { |
4025 |
+ |
r[i] = null; // null-terminate |
4026 |
+ |
return r; |
4027 |
+ |
} |
4028 |
+ |
return (i == n) ? r : Arrays.copyOf(r, i); |
4029 |
+ |
} |
4030 |
+ |
|
4031 |
+ |
public final int hashCode() { |
4032 |
+ |
int h = 0; |
4033 |
+ |
for (Iterator<?> it = iterator(); it.hasNext();) |
4034 |
+ |
h += it.next().hashCode(); |
4035 |
+ |
return h; |
4036 |
+ |
} |
4037 |
+ |
|
4038 |
+ |
public final String toString() { |
4039 |
+ |
StringBuilder sb = new StringBuilder(); |
4040 |
+ |
sb.append('['); |
4041 |
+ |
Iterator<?> it = iterator(); |
4042 |
+ |
if (it.hasNext()) { |
4043 |
+ |
for (;;) { |
4044 |
+ |
Object e = it.next(); |
4045 |
+ |
sb.append(e == this ? "(this Collection)" : e); |
4046 |
+ |
if (!it.hasNext()) |
4047 |
+ |
break; |
4048 |
+ |
sb.append(',').append(' '); |
4049 |
+ |
} |
4050 |
+ |
} |
4051 |
+ |
return sb.append(']').toString(); |
4052 |
+ |
} |
4053 |
+ |
|
4054 |
+ |
public final boolean containsAll(Collection<?> c) { |
4055 |
+ |
if (c != this) { |
4056 |
+ |
for (Iterator<?> it = c.iterator(); it.hasNext();) { |
4057 |
+ |
Object e = it.next(); |
4058 |
+ |
if (e == null || !contains(e)) |
4059 |
+ |
return false; |
4060 |
+ |
} |
4061 |
+ |
} |
4062 |
+ |
return true; |
4063 |
+ |
} |
4064 |
+ |
|
4065 |
+ |
public final boolean removeAll(Collection<?> c) { |
4066 |
+ |
boolean modified = false; |
4067 |
+ |
for (Iterator<?> it = iterator(); it.hasNext();) { |
4068 |
+ |
if (c.contains(it.next())) { |
4069 |
+ |
it.remove(); |
4070 |
+ |
modified = true; |
4071 |
+ |
} |
4072 |
+ |
} |
4073 |
+ |
return modified; |
4074 |
+ |
} |
4075 |
+ |
|
4076 |
+ |
public final boolean retainAll(Collection<?> c) { |
4077 |
+ |
boolean modified = false; |
4078 |
+ |
for (Iterator<?> it = iterator(); it.hasNext();) { |
4079 |
+ |
if (!c.contains(it.next())) { |
4080 |
+ |
it.remove(); |
4081 |
+ |
modified = true; |
4082 |
+ |
} |
4083 |
+ |
} |
4084 |
+ |
return modified; |
4085 |
+ |
} |
4086 |
+ |
|
4087 |
+ |
} |
4088 |
+ |
|
4089 |
+ |
/** |
4090 |
+ |
* A view of a ConcurrentHashMapV8 as a {@link Set} of keys, in |
4091 |
+ |
* which additions may optionally be enabled by mapping to a |
4092 |
+ |
* common value. This class cannot be directly instantiated. See |
4093 |
+ |
* {@link #keySet}, {@link #keySet(Object)}, {@link #newKeySet()}, |
4094 |
+ |
* {@link #newKeySet(int)}. |
4095 |
+ |
*/ |
4096 |
+ |
public static class KeySetView<K,V> extends CHMView<K,V> implements Set<K>, java.io.Serializable { |
4097 |
+ |
private static final long serialVersionUID = 7249069246763182397L; |
4098 |
+ |
private final V value; |
4099 |
+ |
KeySetView(ConcurrentHashMapV8<K, V> map, V value) { // non-public |
4100 |
+ |
super(map); |
4101 |
+ |
this.value = value; |
4102 |
+ |
} |
4103 |
+ |
|
4104 |
+ |
/** |
4105 |
+ |
* Returns the default mapped value for additions, |
4106 |
+ |
* or {@code null} if additions are not supported. |
4107 |
+ |
* |
4108 |
+ |
* @return the default mapped value for additions, or {@code null} |
4109 |
+ |
* if not supported. |
4110 |
+ |
*/ |
4111 |
+ |
public V getMappedValue() { return value; } |
4112 |
+ |
|
4113 |
+ |
// implement Set API |
4114 |
+ |
|
4115 |
+ |
public boolean contains(Object o) { return map.containsKey(o); } |
4116 |
+ |
public boolean remove(Object o) { return map.remove(o) != null; } |
4117 |
+ |
|
4118 |
+ |
/** |
4119 |
+ |
* Returns a "weakly consistent" iterator that will never |
4120 |
+ |
* throw {@link ConcurrentModificationException}, and |
4121 |
+ |
* guarantees to traverse elements as they existed upon |
4122 |
+ |
* construction of the iterator, and may (but is not |
4123 |
+ |
* guaranteed to) reflect any modifications subsequent to |
4124 |
+ |
* construction. |
4125 |
+ |
* |
4126 |
+ |
* @return an iterator over the keys of this map |
4127 |
+ |
*/ |
4128 |
+ |
public Iterator<K> iterator() { return new KeyIterator<K,V>(map); } |
4129 |
+ |
public boolean add(K e) { |
4130 |
+ |
V v; |
4131 |
+ |
if ((v = value) == null) |
4132 |
+ |
throw new UnsupportedOperationException(); |
4133 |
+ |
if (e == null) |
4134 |
+ |
throw new NullPointerException(); |
4135 |
+ |
return map.internalPutIfAbsent(e, v) == null; |
4136 |
+ |
} |
4137 |
+ |
public boolean addAll(Collection<? extends K> c) { |
4138 |
+ |
boolean added = false; |
4139 |
+ |
V v; |
4140 |
+ |
if ((v = value) == null) |
4141 |
+ |
throw new UnsupportedOperationException(); |
4142 |
+ |
for (K e : c) { |
4143 |
+ |
if (e == null) |
4144 |
+ |
throw new NullPointerException(); |
4145 |
+ |
if (map.internalPutIfAbsent(e, v) == null) |
4146 |
+ |
added = true; |
4147 |
+ |
} |
4148 |
+ |
return added; |
4149 |
+ |
} |
4150 |
+ |
public boolean equals(Object o) { |
4151 |
+ |
Set<?> c; |
4152 |
+ |
return ((o instanceof Set) && |
4153 |
+ |
((c = (Set<?>)o) == this || |
4154 |
+ |
(containsAll(c) && c.containsAll(this)))); |
4155 |
+ |
} |
4156 |
+ |
|
4157 |
+ |
/** |
4158 |
+ |
* Performs the given action for each key. |
4159 |
+ |
* |
4160 |
+ |
* @param action the action |
4161 |
+ |
*/ |
4162 |
+ |
public void forEach(Action<K> action) { |
4163 |
+ |
ForkJoinTasks.forEachKey |
4164 |
+ |
(map, action).invoke(); |
4165 |
+ |
} |
4166 |
+ |
|
4167 |
+ |
/** |
4168 |
+ |
* Performs the given action for each non-null transformation |
4169 |
+ |
* of each key. |
4170 |
+ |
* |
4171 |
+ |
* @param transformer a function returning the transformation |
4172 |
+ |
* for an element, or null of there is no transformation (in |
4173 |
+ |
* which case the action is not applied). |
4174 |
+ |
* @param action the action |
4175 |
+ |
*/ |
4176 |
+ |
public <U> void forEach(Fun<? super K, ? extends U> transformer, |
4177 |
+ |
Action<U> action) { |
4178 |
+ |
ForkJoinTasks.forEachKey |
4179 |
+ |
(map, transformer, action).invoke(); |
4180 |
+ |
} |
4181 |
+ |
|
4182 |
+ |
/** |
4183 |
+ |
* Returns a non-null result from applying the given search |
4184 |
+ |
* function on each key, or null if none. Upon success, |
4185 |
+ |
* further element processing is suppressed and the results of |
4186 |
+ |
* any other parallel invocations of the search function are |
4187 |
+ |
* ignored. |
4188 |
+ |
* |
4189 |
+ |
* @param searchFunction a function returning a non-null |
4190 |
+ |
* result on success, else null |
4191 |
+ |
* @return a non-null result from applying the given search |
4192 |
+ |
* function on each key, or null if none |
4193 |
+ |
*/ |
4194 |
+ |
public <U> U search(Fun<? super K, ? extends U> searchFunction) { |
4195 |
+ |
return ForkJoinTasks.searchKeys |
4196 |
+ |
(map, searchFunction).invoke(); |
4197 |
+ |
} |
4198 |
+ |
|
4199 |
+ |
/** |
4200 |
+ |
* Returns the result of accumulating all keys using the given |
4201 |
+ |
* reducer to combine values, or null if none. |
4202 |
+ |
* |
4203 |
+ |
* @param reducer a commutative associative combining function |
4204 |
+ |
* @return the result of accumulating all keys using the given |
4205 |
+ |
* reducer to combine values, or null if none |
4206 |
+ |
*/ |
4207 |
+ |
public K reduce(BiFun<? super K, ? super K, ? extends K> reducer) { |
4208 |
+ |
return ForkJoinTasks.reduceKeys |
4209 |
+ |
(map, reducer).invoke(); |
4210 |
+ |
} |
4211 |
+ |
|
4212 |
+ |
/** |
4213 |
+ |
* Returns the result of accumulating the given transformation |
4214 |
+ |
* of all keys using the given reducer to combine values, and |
4215 |
+ |
* the given basis as an identity value. |
4216 |
+ |
* |
4217 |
+ |
* @param transformer a function returning the transformation |
4218 |
+ |
* for an element |
4219 |
+ |
* @param basis the identity (initial default value) for the reduction |
4220 |
+ |
* @param reducer a commutative associative combining function |
4221 |
+ |
* @return the result of accumulating the given transformation |
4222 |
+ |
* of all keys |
4223 |
+ |
*/ |
4224 |
+ |
public double reduceToDouble(ObjectToDouble<? super K> transformer, |
4225 |
+ |
double basis, |
4226 |
+ |
DoubleByDoubleToDouble reducer) { |
4227 |
+ |
return ForkJoinTasks.reduceKeysToDouble |
4228 |
+ |
(map, transformer, basis, reducer).invoke(); |
4229 |
+ |
} |
4230 |
+ |
|
4231 |
+ |
|
4232 |
+ |
/** |
4233 |
+ |
* Returns the result of accumulating the given transformation |
4234 |
+ |
* of all keys using the given reducer to combine values, and |
4235 |
+ |
* the given basis as an identity value. |
4236 |
+ |
* |
4237 |
+ |
* @param transformer a function returning the transformation |
4238 |
+ |
* for an element |
4239 |
+ |
* @param basis the identity (initial default value) for the reduction |
4240 |
+ |
* @param reducer a commutative associative combining function |
4241 |
+ |
* @return the result of accumulating the given transformation |
4242 |
+ |
* of all keys |
4243 |
+ |
*/ |
4244 |
+ |
public long reduceToLong(ObjectToLong<? super K> transformer, |
4245 |
+ |
long basis, |
4246 |
+ |
LongByLongToLong reducer) { |
4247 |
+ |
return ForkJoinTasks.reduceKeysToLong |
4248 |
+ |
(map, transformer, basis, reducer).invoke(); |
4249 |
+ |
} |
4250 |
+ |
|
4251 |
+ |
/** |
4252 |
+ |
* Returns the result of accumulating the given transformation |
4253 |
+ |
* of all keys using the given reducer to combine values, and |
4254 |
+ |
* the given basis as an identity value. |
4255 |
+ |
* |
4256 |
+ |
* @param transformer a function returning the transformation |
4257 |
+ |
* for an element |
4258 |
+ |
* @param basis the identity (initial default value) for the reduction |
4259 |
+ |
* @param reducer a commutative associative combining function |
4260 |
+ |
* @return the result of accumulating the given transformation |
4261 |
+ |
* of all keys |
4262 |
+ |
*/ |
4263 |
+ |
public int reduceToInt(ObjectToInt<? super K> transformer, |
4264 |
+ |
int basis, |
4265 |
+ |
IntByIntToInt reducer) { |
4266 |
+ |
return ForkJoinTasks.reduceKeysToInt |
4267 |
+ |
(map, transformer, basis, reducer).invoke(); |
4268 |
+ |
} |
4269 |
+ |
|
4270 |
+ |
} |
4271 |
+ |
|
4272 |
+ |
/** |
4273 |
+ |
* A view of a ConcurrentHashMapV8 as a {@link Collection} of |
4274 |
+ |
* values, in which additions are disabled. This class cannot be |
4275 |
+ |
* directly instantiated. See {@link #values}, |
4276 |
+ |
* |
4277 |
+ |
* <p>The view's {@code iterator} is a "weakly consistent" iterator |
4278 |
+ |
* that will never throw {@link ConcurrentModificationException}, |
4279 |
+ |
* and guarantees to traverse elements as they existed upon |
4280 |
+ |
* construction of the iterator, and may (but is not guaranteed to) |
4281 |
+ |
* reflect any modifications subsequent to construction. |
4282 |
+ |
*/ |
4283 |
+ |
public static final class ValuesView<K,V> extends CHMView<K,V> |
4284 |
+ |
implements Collection<V> { |
4285 |
+ |
ValuesView(ConcurrentHashMapV8<K, V> map) { super(map); } |
4286 |
+ |
public final boolean contains(Object o) { return map.containsValue(o); } |
4287 |
+ |
public final boolean remove(Object o) { |
4288 |
+ |
if (o != null) { |
4289 |
+ |
Iterator<V> it = new ValueIterator<K,V>(map); |
4290 |
+ |
while (it.hasNext()) { |
4291 |
+ |
if (o.equals(it.next())) { |
4292 |
+ |
it.remove(); |
4293 |
+ |
return true; |
4294 |
+ |
} |
4295 |
+ |
} |
4296 |
+ |
} |
4297 |
+ |
return false; |
4298 |
+ |
} |
4299 |
+ |
|
4300 |
+ |
/** |
4301 |
+ |
* Returns a "weakly consistent" iterator that will never |
4302 |
+ |
* throw {@link ConcurrentModificationException}, and |
4303 |
+ |
* guarantees to traverse elements as they existed upon |
4304 |
+ |
* construction of the iterator, and may (but is not |
4305 |
+ |
* guaranteed to) reflect any modifications subsequent to |
4306 |
+ |
* construction. |
4307 |
+ |
* |
4308 |
+ |
* @return an iterator over the values of this map |
4309 |
+ |
*/ |
4310 |
+ |
public final Iterator<V> iterator() { |
4311 |
+ |
return new ValueIterator<K,V>(map); |
4312 |
+ |
} |
4313 |
+ |
public final boolean add(V e) { |
4314 |
+ |
throw new UnsupportedOperationException(); |
4315 |
+ |
} |
4316 |
+ |
public final boolean addAll(Collection<? extends V> c) { |
4317 |
+ |
throw new UnsupportedOperationException(); |
4318 |
+ |
} |
4319 |
+ |
|
4320 |
+ |
/** |
4321 |
+ |
* Performs the given action for each value. |
4322 |
+ |
* |
4323 |
+ |
* @param action the action |
4324 |
+ |
*/ |
4325 |
+ |
public void forEach(Action<V> action) { |
4326 |
+ |
ForkJoinTasks.forEachValue |
4327 |
+ |
(map, action).invoke(); |
4328 |
+ |
} |
4329 |
+ |
|
4330 |
+ |
/** |
4331 |
+ |
* Performs the given action for each non-null transformation |
4332 |
+ |
* of each value. |
4333 |
+ |
* |
4334 |
+ |
* @param transformer a function returning the transformation |
4335 |
+ |
* for an element, or null of there is no transformation (in |
4336 |
+ |
* which case the action is not applied). |
4337 |
+ |
*/ |
4338 |
+ |
public <U> void forEach(Fun<? super V, ? extends U> transformer, |
4339 |
+ |
Action<U> action) { |
4340 |
+ |
ForkJoinTasks.forEachValue |
4341 |
+ |
(map, transformer, action).invoke(); |
4342 |
+ |
} |
4343 |
+ |
|
4344 |
+ |
/** |
4345 |
+ |
* Returns a non-null result from applying the given search |
4346 |
+ |
* function on each value, or null if none. Upon success, |
4347 |
+ |
* further element processing is suppressed and the results of |
4348 |
+ |
* any other parallel invocations of the search function are |
4349 |
+ |
* ignored. |
4350 |
+ |
* |
4351 |
+ |
* @param searchFunction a function returning a non-null |
4352 |
+ |
* result on success, else null |
4353 |
+ |
* @return a non-null result from applying the given search |
4354 |
+ |
* function on each value, or null if none |
4355 |
+ |
* |
4356 |
+ |
*/ |
4357 |
+ |
public <U> U search(Fun<? super V, ? extends U> searchFunction) { |
4358 |
+ |
return ForkJoinTasks.searchValues |
4359 |
+ |
(map, searchFunction).invoke(); |
4360 |
+ |
} |
4361 |
+ |
|
4362 |
+ |
/** |
4363 |
+ |
* Returns the result of accumulating all values using the |
4364 |
+ |
* given reducer to combine values, or null if none. |
4365 |
+ |
* |
4366 |
+ |
* @param reducer a commutative associative combining function |
4367 |
+ |
* @return the result of accumulating all values |
4368 |
+ |
*/ |
4369 |
+ |
public V reduce(BiFun<? super V, ? super V, ? extends V> reducer) { |
4370 |
+ |
return ForkJoinTasks.reduceValues |
4371 |
+ |
(map, reducer).invoke(); |
4372 |
+ |
} |
4373 |
+ |
|
4374 |
+ |
/** |
4375 |
+ |
* Returns the result of accumulating the given transformation |
4376 |
+ |
* of all values using the given reducer to combine values, or |
4377 |
+ |
* null if none. |
4378 |
+ |
* |
4379 |
+ |
* @param transformer a function returning the transformation |
4380 |
+ |
* for an element, or null of there is no transformation (in |
4381 |
+ |
* which case it is not combined). |
4382 |
+ |
* @param reducer a commutative associative combining function |
4383 |
+ |
* @return the result of accumulating the given transformation |
4384 |
+ |
* of all values |
4385 |
+ |
*/ |
4386 |
+ |
public <U> U reduce(Fun<? super V, ? extends U> transformer, |
4387 |
+ |
BiFun<? super U, ? super U, ? extends U> reducer) { |
4388 |
+ |
return ForkJoinTasks.reduceValues |
4389 |
+ |
(map, transformer, reducer).invoke(); |
4390 |
+ |
} |
4391 |
+ |
|
4392 |
+ |
/** |
4393 |
+ |
* Returns the result of accumulating the given transformation |
4394 |
+ |
* of all values using the given reducer to combine values, |
4395 |
+ |
* and the given basis as an identity value. |
4396 |
+ |
* |
4397 |
+ |
* @param transformer a function returning the transformation |
4398 |
+ |
* for an element |
4399 |
+ |
* @param basis the identity (initial default value) for the reduction |
4400 |
+ |
* @param reducer a commutative associative combining function |
4401 |
+ |
* @return the result of accumulating the given transformation |
4402 |
+ |
* of all values |
4403 |
+ |
*/ |
4404 |
+ |
public double reduceToDouble(ObjectToDouble<? super V> transformer, |
4405 |
+ |
double basis, |
4406 |
+ |
DoubleByDoubleToDouble reducer) { |
4407 |
+ |
return ForkJoinTasks.reduceValuesToDouble |
4408 |
+ |
(map, transformer, basis, reducer).invoke(); |
4409 |
+ |
} |
4410 |
+ |
|
4411 |
+ |
/** |
4412 |
+ |
* Returns the result of accumulating the given transformation |
4413 |
+ |
* of all values using the given reducer to combine values, |
4414 |
+ |
* and the given basis as an identity value. |
4415 |
+ |
* |
4416 |
+ |
* @param transformer a function returning the transformation |
4417 |
+ |
* for an element |
4418 |
+ |
* @param basis the identity (initial default value) for the reduction |
4419 |
+ |
* @param reducer a commutative associative combining function |
4420 |
+ |
* @return the result of accumulating the given transformation |
4421 |
+ |
* of all values |
4422 |
+ |
*/ |
4423 |
+ |
public long reduceToLong(ObjectToLong<? super V> transformer, |
4424 |
+ |
long basis, |
4425 |
+ |
LongByLongToLong reducer) { |
4426 |
+ |
return ForkJoinTasks.reduceValuesToLong |
4427 |
+ |
(map, transformer, basis, reducer).invoke(); |
4428 |
+ |
} |
4429 |
+ |
|
4430 |
+ |
/** |
4431 |
+ |
* Returns the result of accumulating the given transformation |
4432 |
+ |
* of all values using the given reducer to combine values, |
4433 |
+ |
* and the given basis as an identity value. |
4434 |
+ |
* |
4435 |
+ |
* @param transformer a function returning the transformation |
4436 |
+ |
* for an element |
4437 |
+ |
* @param basis the identity (initial default value) for the reduction |
4438 |
+ |
* @param reducer a commutative associative combining function |
4439 |
+ |
* @return the result of accumulating the given transformation |
4440 |
+ |
* of all values |
4441 |
+ |
*/ |
4442 |
+ |
public int reduceToInt(ObjectToInt<? super V> transformer, |
4443 |
+ |
int basis, |
4444 |
+ |
IntByIntToInt reducer) { |
4445 |
+ |
return ForkJoinTasks.reduceValuesToInt |
4446 |
+ |
(map, transformer, basis, reducer).invoke(); |
4447 |
+ |
} |
4448 |
+ |
|
4449 |
+ |
} |
4450 |
+ |
|
4451 |
+ |
/** |
4452 |
+ |
* A view of a ConcurrentHashMapV8 as a {@link Set} of (key, value) |
4453 |
+ |
* entries. This class cannot be directly instantiated. See |
4454 |
+ |
* {@link #entrySet}. |
4455 |
+ |
*/ |
4456 |
+ |
public static final class EntrySetView<K,V> extends CHMView<K,V> |
4457 |
+ |
implements Set<Map.Entry<K,V>> { |
4458 |
+ |
EntrySetView(ConcurrentHashMapV8<K, V> map) { super(map); } |
4459 |
+ |
public final boolean contains(Object o) { |
4460 |
+ |
Object k, v, r; Map.Entry<?,?> e; |
4461 |
+ |
return ((o instanceof Map.Entry) && |
4462 |
+ |
(k = (e = (Map.Entry<?,?>)o).getKey()) != null && |
4463 |
+ |
(r = map.get(k)) != null && |
4464 |
+ |
(v = e.getValue()) != null && |
4465 |
+ |
(v == r || v.equals(r))); |
4466 |
+ |
} |
4467 |
+ |
public final boolean remove(Object o) { |
4468 |
+ |
Object k, v; Map.Entry<?,?> e; |
4469 |
+ |
return ((o instanceof Map.Entry) && |
4470 |
+ |
(k = (e = (Map.Entry<?,?>)o).getKey()) != null && |
4471 |
+ |
(v = e.getValue()) != null && |
4472 |
+ |
map.remove(k, v)); |
4473 |
+ |
} |
4474 |
+ |
|
4475 |
+ |
/** |
4476 |
+ |
* Returns a "weakly consistent" iterator that will never |
4477 |
+ |
* throw {@link ConcurrentModificationException}, and |
4478 |
+ |
* guarantees to traverse elements as they existed upon |
4479 |
+ |
* construction of the iterator, and may (but is not |
4480 |
+ |
* guaranteed to) reflect any modifications subsequent to |
4481 |
+ |
* construction. |
4482 |
+ |
* |
4483 |
+ |
* @return an iterator over the entries of this map |
4484 |
+ |
*/ |
4485 |
+ |
public final Iterator<Map.Entry<K,V>> iterator() { |
4486 |
+ |
return new EntryIterator<K,V>(map); |
4487 |
+ |
} |
4488 |
+ |
|
4489 |
+ |
public final boolean add(Entry<K,V> e) { |
4490 |
+ |
K key = e.getKey(); |
4491 |
+ |
V value = e.getValue(); |
4492 |
+ |
if (key == null || value == null) |
4493 |
+ |
throw new NullPointerException(); |
4494 |
+ |
return map.internalPut(key, value) == null; |
4495 |
+ |
} |
4496 |
+ |
public final boolean addAll(Collection<? extends Entry<K,V>> c) { |
4497 |
+ |
boolean added = false; |
4498 |
+ |
for (Entry<K,V> e : c) { |
4499 |
+ |
if (add(e)) |
4500 |
+ |
added = true; |
4501 |
+ |
} |
4502 |
+ |
return added; |
4503 |
+ |
} |
4504 |
+ |
public boolean equals(Object o) { |
4505 |
+ |
Set<?> c; |
4506 |
+ |
return ((o instanceof Set) && |
4507 |
+ |
((c = (Set<?>)o) == this || |
4508 |
+ |
(containsAll(c) && c.containsAll(this)))); |
4509 |
+ |
} |
4510 |
+ |
|
4511 |
+ |
/** |
4512 |
+ |
* Performs the given action for each entry. |
4513 |
+ |
* |
4514 |
+ |
* @param action the action |
4515 |
+ |
*/ |
4516 |
+ |
public void forEach(Action<Map.Entry<K,V>> action) { |
4517 |
+ |
ForkJoinTasks.forEachEntry |
4518 |
+ |
(map, action).invoke(); |
4519 |
+ |
} |
4520 |
+ |
|
4521 |
+ |
/** |
4522 |
+ |
* Performs the given action for each non-null transformation |
4523 |
+ |
* of each entry. |
4524 |
+ |
* |
4525 |
+ |
* @param transformer a function returning the transformation |
4526 |
+ |
* for an element, or null of there is no transformation (in |
4527 |
+ |
* which case the action is not applied). |
4528 |
+ |
* @param action the action |
4529 |
+ |
*/ |
4530 |
+ |
public <U> void forEach(Fun<Map.Entry<K,V>, ? extends U> transformer, |
4531 |
+ |
Action<U> action) { |
4532 |
+ |
ForkJoinTasks.forEachEntry |
4533 |
+ |
(map, transformer, action).invoke(); |
4534 |
+ |
} |
4535 |
+ |
|
4536 |
+ |
/** |
4537 |
+ |
* Returns a non-null result from applying the given search |
4538 |
+ |
* function on each entry, or null if none. Upon success, |
4539 |
+ |
* further element processing is suppressed and the results of |
4540 |
+ |
* any other parallel invocations of the search function are |
4541 |
+ |
* ignored. |
4542 |
+ |
* |
4543 |
+ |
* @param searchFunction a function returning a non-null |
4544 |
+ |
* result on success, else null |
4545 |
+ |
* @return a non-null result from applying the given search |
4546 |
+ |
* function on each entry, or null if none |
4547 |
+ |
*/ |
4548 |
+ |
public <U> U search(Fun<Map.Entry<K,V>, ? extends U> searchFunction) { |
4549 |
+ |
return ForkJoinTasks.searchEntries |
4550 |
+ |
(map, searchFunction).invoke(); |
4551 |
+ |
} |
4552 |
+ |
|
4553 |
+ |
/** |
4554 |
+ |
* Returns the result of accumulating all entries using the |
4555 |
+ |
* given reducer to combine values, or null if none. |
4556 |
+ |
* |
4557 |
+ |
* @param reducer a commutative associative combining function |
4558 |
+ |
* @return the result of accumulating all entries |
4559 |
+ |
*/ |
4560 |
+ |
public Map.Entry<K,V> reduce(BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) { |
4561 |
+ |
return ForkJoinTasks.reduceEntries |
4562 |
+ |
(map, reducer).invoke(); |
4563 |
+ |
} |
4564 |
+ |
|
4565 |
+ |
/** |
4566 |
+ |
* Returns the result of accumulating the given transformation |
4567 |
+ |
* of all entries using the given reducer to combine values, |
4568 |
+ |
* or null if none. |
4569 |
+ |
* |
4570 |
+ |
* @param transformer a function returning the transformation |
4571 |
+ |
* for an element, or null of there is no transformation (in |
4572 |
+ |
* which case it is not combined). |
4573 |
+ |
* @param reducer a commutative associative combining function |
4574 |
+ |
* @return the result of accumulating the given transformation |
4575 |
+ |
* of all entries |
4576 |
+ |
*/ |
4577 |
+ |
public <U> U reduce(Fun<Map.Entry<K,V>, ? extends U> transformer, |
4578 |
+ |
BiFun<? super U, ? super U, ? extends U> reducer) { |
4579 |
+ |
return ForkJoinTasks.reduceEntries |
4580 |
+ |
(map, transformer, reducer).invoke(); |
4581 |
+ |
} |
4582 |
+ |
|
4583 |
+ |
/** |
4584 |
+ |
* Returns the result of accumulating the given transformation |
4585 |
+ |
* of all entries using the given reducer to combine values, |
4586 |
+ |
* and the given basis as an identity value. |
4587 |
+ |
* |
4588 |
+ |
* @param transformer a function returning the transformation |
4589 |
+ |
* for an element |
4590 |
+ |
* @param basis the identity (initial default value) for the reduction |
4591 |
+ |
* @param reducer a commutative associative combining function |
4592 |
+ |
* @return the result of accumulating the given transformation |
4593 |
+ |
* of all entries |
4594 |
+ |
*/ |
4595 |
+ |
public double reduceToDouble(ObjectToDouble<Map.Entry<K,V>> transformer, |
4596 |
+ |
double basis, |
4597 |
+ |
DoubleByDoubleToDouble reducer) { |
4598 |
+ |
return ForkJoinTasks.reduceEntriesToDouble |
4599 |
+ |
(map, transformer, basis, reducer).invoke(); |
4600 |
+ |
} |
4601 |
+ |
|
4602 |
+ |
/** |
4603 |
+ |
* Returns the result of accumulating the given transformation |
4604 |
+ |
* of all entries using the given reducer to combine values, |
4605 |
+ |
* and the given basis as an identity value. |
4606 |
+ |
* |
4607 |
+ |
* @param transformer a function returning the transformation |
4608 |
+ |
* for an element |
4609 |
+ |
* @param basis the identity (initial default value) for the reduction |
4610 |
+ |
* @param reducer a commutative associative combining function |
4611 |
+ |
* @return the result of accumulating the given transformation |
4612 |
+ |
* of all entries |
4613 |
+ |
*/ |
4614 |
+ |
public long reduceToLong(ObjectToLong<Map.Entry<K,V>> transformer, |
4615 |
+ |
long basis, |
4616 |
+ |
LongByLongToLong reducer) { |
4617 |
+ |
return ForkJoinTasks.reduceEntriesToLong |
4618 |
+ |
(map, transformer, basis, reducer).invoke(); |
4619 |
+ |
} |
4620 |
+ |
|
4621 |
+ |
/** |
4622 |
+ |
* Returns the result of accumulating the given transformation |
4623 |
+ |
* of all entries using the given reducer to combine values, |
4624 |
+ |
* and the given basis as an identity value. |
4625 |
+ |
* |
4626 |
+ |
* @param transformer a function returning the transformation |
4627 |
+ |
* for an element |
4628 |
+ |
* @param basis the identity (initial default value) for the reduction |
4629 |
+ |
* @param reducer a commutative associative combining function |
4630 |
+ |
* @return the result of accumulating the given transformation |
4631 |
+ |
* of all entries |
4632 |
+ |
*/ |
4633 |
+ |
public int reduceToInt(ObjectToInt<Map.Entry<K,V>> transformer, |
4634 |
+ |
int basis, |
4635 |
+ |
IntByIntToInt reducer) { |
4636 |
+ |
return ForkJoinTasks.reduceEntriesToInt |
4637 |
+ |
(map, transformer, basis, reducer).invoke(); |
4638 |
+ |
} |
4639 |
+ |
|
4640 |
+ |
} |
4641 |
+ |
|
4642 |
|
// --------------------------------------------------------------------- |
4643 |
|
|
4644 |
|
/** |
7176 |
|
public final Integer getRawResult() { return result; } |
7177 |
|
} |
7178 |
|
|
6760 |
– |
|
7179 |
|
// Unsafe mechanics |
7180 |
|
private static final sun.misc.Unsafe UNSAFE; |
7181 |
|
private static final long counterOffset; |