6 |
|
|
7 |
|
import junit.framework.*; |
8 |
|
import java.util.*; |
9 |
+ |
import static java.util.Spliterator.*; |
10 |
|
import java.util.function.*; |
11 |
|
import java.util.concurrent.atomic.LongAdder; |
12 |
|
import java.util.concurrent.ConcurrentHashMap; |
55 |
|
} |
56 |
|
|
57 |
|
/** |
58 |
< |
* computeIfAbsent does not replace if the key is already present |
58 |
> |
* computeIfAbsent does not replace if the key is already present |
59 |
|
*/ |
60 |
|
public void testComputeIfAbsent2() { |
61 |
|
ConcurrentHashMap map = map5(); |
72 |
|
} |
73 |
|
|
74 |
|
/** |
75 |
< |
* computeIfPresent does not replace if the key is already present |
75 |
> |
* computeIfPresent does not replace if the key is already present |
76 |
|
*/ |
77 |
|
public void testComputeIfPresent() { |
78 |
|
ConcurrentHashMap map = map5(); |
89 |
|
} |
90 |
|
|
91 |
|
/** |
92 |
< |
* compute does not replace if the function returns null |
92 |
> |
* compute does not replace if the function returns null |
93 |
|
*/ |
94 |
|
public void testCompute() { |
95 |
|
ConcurrentHashMap map = map5(); |
300 |
|
assertTrue(map.get(seven) == one); |
301 |
|
} |
302 |
|
|
303 |
+ |
void checkSpliteratorCharacteristics(Spliterator<?> sp, |
304 |
+ |
int requiredCharacteristics) { |
305 |
+ |
assertEquals(requiredCharacteristics, |
306 |
+ |
requiredCharacteristics & sp.characteristics()); |
307 |
+ |
} |
308 |
+ |
|
309 |
|
/** |
310 |
|
* KeySetView.spliterator returns spliterator over the elements in this set |
311 |
|
*/ |
314 |
|
ConcurrentHashMap map = map5(); |
315 |
|
Set set = map.keySet(); |
316 |
|
Spliterator<Integer> sp = set.spliterator(); |
317 |
+ |
checkSpliteratorCharacteristics(sp, CONCURRENT | DISTINCT | NONNULL); |
318 |
|
assertEquals(sp.estimateSize(), map.size()); |
319 |
|
Spliterator<Integer> sp2 = sp.trySplit(); |
320 |
|
sp.forEachRemaining((Integer x) -> adder.add(x.longValue())); |