4 |
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
< |
import junit.framework.*; |
8 |
< |
import java.util.*; |
9 |
< |
import java.util.concurrent.atomic.LongAdder; |
7 |
> |
import static java.util.Spliterator.CONCURRENT; |
8 |
> |
import static java.util.Spliterator.DISTINCT; |
9 |
> |
import static java.util.Spliterator.NONNULL; |
10 |
> |
|
11 |
> |
import java.util.AbstractMap; |
12 |
> |
import java.util.Arrays; |
13 |
> |
import java.util.Collection; |
14 |
> |
import java.util.Collections; |
15 |
> |
import java.util.Iterator; |
16 |
> |
import java.util.Map; |
17 |
> |
import java.util.NoSuchElementException; |
18 |
> |
import java.util.Set; |
19 |
> |
import java.util.Spliterator; |
20 |
|
import java.util.concurrent.ConcurrentHashMap; |
21 |
+ |
import java.util.concurrent.atomic.LongAdder; |
22 |
+ |
import java.util.function.BiFunction; |
23 |
+ |
|
24 |
+ |
import junit.framework.Test; |
25 |
+ |
import junit.framework.TestSuite; |
26 |
|
|
27 |
|
public class ConcurrentHashMap8Test extends JSR166TestCase { |
28 |
|
public static void main(String[] args) { |
29 |
< |
junit.textui.TestRunner.run(suite()); |
29 |
> |
main(suite(), args); |
30 |
|
} |
31 |
|
public static Test suite() { |
32 |
|
return new TestSuite(ConcurrentHashMap8Test.class); |
49 |
|
} |
50 |
|
|
51 |
|
/** |
52 |
+ |
* getOrDefault returns value if present, else default |
53 |
+ |
*/ |
54 |
+ |
public void testGetOrDefault() { |
55 |
+ |
ConcurrentHashMap map = map5(); |
56 |
+ |
assertEquals(map.getOrDefault(one, "Z"), "A"); |
57 |
+ |
assertEquals(map.getOrDefault(six, "Z"), "Z"); |
58 |
+ |
} |
59 |
+ |
|
60 |
+ |
/** |
61 |
|
* computeIfAbsent adds when the given key is not present |
62 |
|
*/ |
63 |
|
public void testComputeIfAbsent() { |
67 |
|
} |
68 |
|
|
69 |
|
/** |
70 |
< |
* computeIfAbsent does not replace if the key is already present |
70 |
> |
* computeIfAbsent does not replace if the key is already present |
71 |
|
*/ |
72 |
|
public void testComputeIfAbsent2() { |
73 |
|
ConcurrentHashMap map = map5(); |
82 |
|
map.computeIfAbsent(six, (x) -> null); |
83 |
|
assertFalse(map.containsKey(six)); |
84 |
|
} |
85 |
< |
|
85 |
> |
|
86 |
|
/** |
87 |
< |
* computeIfPresent does not replace if the key is already present |
87 |
> |
* computeIfPresent does not replace if the key is already present |
88 |
|
*/ |
89 |
|
public void testComputeIfPresent() { |
90 |
|
ConcurrentHashMap map = map5(); |
101 |
|
} |
102 |
|
|
103 |
|
/** |
104 |
< |
* compute does not replace if the function returns null |
104 |
> |
* compute does not replace if the function returns null |
105 |
|
*/ |
106 |
|
public void testCompute() { |
107 |
|
ConcurrentHashMap map = map5(); |
159 |
|
assertFalse(map.containsKey(one)); |
160 |
|
} |
161 |
|
|
162 |
+ |
static Set<Integer> populatedSet(int n) { |
163 |
+ |
Set<Integer> a = ConcurrentHashMap.<Integer>newKeySet(); |
164 |
+ |
assertTrue(a.isEmpty()); |
165 |
+ |
for (int i = 0; i < n; i++) |
166 |
+ |
assertTrue(a.add(i)); |
167 |
+ |
assertEquals(n == 0, a.isEmpty()); |
168 |
+ |
assertEquals(n, a.size()); |
169 |
+ |
return a; |
170 |
+ |
} |
171 |
+ |
|
172 |
+ |
static Set populatedSet(Integer[] elements) { |
173 |
+ |
Set<Integer> a = ConcurrentHashMap.<Integer>newKeySet(); |
174 |
+ |
assertTrue(a.isEmpty()); |
175 |
+ |
for (int i = 0; i < elements.length; i++) |
176 |
+ |
assertTrue(a.add(elements[i])); |
177 |
+ |
assertFalse(a.isEmpty()); |
178 |
+ |
assertEquals(elements.length, a.size()); |
179 |
+ |
return a; |
180 |
+ |
} |
181 |
+ |
|
182 |
+ |
/** |
183 |
+ |
* replaceAll replaces all matching values. |
184 |
+ |
*/ |
185 |
+ |
public void testReplaceAll() { |
186 |
+ |
ConcurrentHashMap<Integer, String> map = map5(); |
187 |
+ |
map.replaceAll((x, y) -> { return x > 3 ? "Z" : y; }); |
188 |
+ |
assertEquals("A", map.get(one)); |
189 |
+ |
assertEquals("B", map.get(two)); |
190 |
+ |
assertEquals("C", map.get(three)); |
191 |
+ |
assertEquals("Z", map.get(four)); |
192 |
+ |
assertEquals("Z", map.get(five)); |
193 |
+ |
} |
194 |
+ |
|
195 |
+ |
/** |
196 |
+ |
* Default-constructed set is empty |
197 |
+ |
*/ |
198 |
+ |
public void testNewKeySet() { |
199 |
+ |
Set a = ConcurrentHashMap.newKeySet(); |
200 |
+ |
assertTrue(a.isEmpty()); |
201 |
+ |
} |
202 |
+ |
|
203 |
+ |
/** |
204 |
+ |
* keySet.add adds the key with the established value to the map; |
205 |
+ |
* remove removes it. |
206 |
+ |
*/ |
207 |
+ |
public void testKeySetAddRemove() { |
208 |
+ |
ConcurrentHashMap map = map5(); |
209 |
+ |
Set set1 = map.keySet(); |
210 |
+ |
Set set2 = map.keySet(true); |
211 |
+ |
set2.add(six); |
212 |
+ |
assertTrue(((ConcurrentHashMap.KeySetView)set2).getMap() == map); |
213 |
+ |
assertTrue(((ConcurrentHashMap.KeySetView)set1).getMap() == map); |
214 |
+ |
assertEquals(set2.size(), map.size()); |
215 |
+ |
assertEquals(set1.size(), map.size()); |
216 |
+ |
assertTrue((Boolean)map.get(six)); |
217 |
+ |
assertTrue(set1.contains(six)); |
218 |
+ |
assertTrue(set2.contains(six)); |
219 |
+ |
set2.remove(six); |
220 |
+ |
assertNull(map.get(six)); |
221 |
+ |
assertFalse(set1.contains(six)); |
222 |
+ |
assertFalse(set2.contains(six)); |
223 |
+ |
} |
224 |
+ |
|
225 |
+ |
/** |
226 |
+ |
* keySet.addAll adds each element from the given collection |
227 |
+ |
*/ |
228 |
+ |
public void testAddAll() { |
229 |
+ |
Set full = populatedSet(3); |
230 |
+ |
assertTrue(full.addAll(Arrays.asList(three, four, five))); |
231 |
+ |
assertEquals(6, full.size()); |
232 |
+ |
assertFalse(full.addAll(Arrays.asList(three, four, five))); |
233 |
+ |
assertEquals(6, full.size()); |
234 |
+ |
} |
235 |
+ |
|
236 |
+ |
/** |
237 |
+ |
* keySet.addAll adds each element from the given collection that did not |
238 |
+ |
* already exist in the set |
239 |
+ |
*/ |
240 |
+ |
public void testAddAll2() { |
241 |
+ |
Set full = populatedSet(3); |
242 |
+ |
// "one" is duplicate and will not be added |
243 |
+ |
assertTrue(full.addAll(Arrays.asList(three, four, one))); |
244 |
+ |
assertEquals(5, full.size()); |
245 |
+ |
assertFalse(full.addAll(Arrays.asList(three, four, one))); |
246 |
+ |
assertEquals(5, full.size()); |
247 |
+ |
} |
248 |
+ |
|
249 |
+ |
/** |
250 |
+ |
* keySet.add will not add the element if it already exists in the set |
251 |
+ |
*/ |
252 |
+ |
public void testAdd2() { |
253 |
+ |
Set full = populatedSet(3); |
254 |
+ |
assertFalse(full.add(one)); |
255 |
+ |
assertEquals(3, full.size()); |
256 |
+ |
} |
257 |
+ |
|
258 |
+ |
/** |
259 |
+ |
* keySet.add adds the element when it does not exist in the set |
260 |
+ |
*/ |
261 |
+ |
public void testAdd3() { |
262 |
+ |
Set full = populatedSet(3); |
263 |
+ |
assertTrue(full.add(three)); |
264 |
+ |
assertTrue(full.contains(three)); |
265 |
+ |
assertFalse(full.add(three)); |
266 |
+ |
assertTrue(full.contains(three)); |
267 |
+ |
} |
268 |
+ |
|
269 |
+ |
/** |
270 |
+ |
* keySet.add throws UnsupportedOperationException if no default |
271 |
+ |
* mapped value |
272 |
+ |
*/ |
273 |
+ |
public void testAdd4() { |
274 |
+ |
Set full = map5().keySet(); |
275 |
+ |
try { |
276 |
+ |
full.add(three); |
277 |
+ |
shouldThrow(); |
278 |
+ |
} catch (UnsupportedOperationException success) {} |
279 |
+ |
} |
280 |
+ |
|
281 |
+ |
/** |
282 |
+ |
* keySet.add throws NullPointerException if the specified key is |
283 |
+ |
* null |
284 |
+ |
*/ |
285 |
+ |
public void testAdd5() { |
286 |
+ |
Set full = populatedSet(3); |
287 |
+ |
try { |
288 |
+ |
full.add(null); |
289 |
+ |
shouldThrow(); |
290 |
+ |
} catch (NullPointerException success) {} |
291 |
+ |
} |
292 |
+ |
|
293 |
+ |
/** |
294 |
+ |
* KeySetView.getMappedValue returns the map's mapped value |
295 |
+ |
*/ |
296 |
+ |
public void testGetMappedValue() { |
297 |
+ |
ConcurrentHashMap map = map5(); |
298 |
+ |
assertNull(map.keySet().getMappedValue()); |
299 |
+ |
try { |
300 |
+ |
map.keySet(null); |
301 |
+ |
shouldThrow(); |
302 |
+ |
} catch (NullPointerException success) {} |
303 |
+ |
ConcurrentHashMap.KeySetView set = map.keySet(one); |
304 |
+ |
assertFalse(set.add(one)); |
305 |
+ |
assertTrue(set.add(six)); |
306 |
+ |
assertTrue(set.add(seven)); |
307 |
+ |
assertTrue(set.getMappedValue() == one); |
308 |
+ |
assertTrue(map.get(one) != one); |
309 |
+ |
assertTrue(map.get(six) == one); |
310 |
+ |
assertTrue(map.get(seven) == one); |
311 |
+ |
} |
312 |
+ |
|
313 |
+ |
void checkSpliteratorCharacteristics(Spliterator<?> sp, |
314 |
+ |
int requiredCharacteristics) { |
315 |
+ |
assertEquals(requiredCharacteristics, |
316 |
+ |
requiredCharacteristics & sp.characteristics()); |
317 |
+ |
} |
318 |
+ |
|
319 |
+ |
/** |
320 |
+ |
* KeySetView.spliterator returns spliterator over the elements in this set |
321 |
+ |
*/ |
322 |
+ |
public void testKeySetSpliterator() { |
323 |
+ |
LongAdder adder = new LongAdder(); |
324 |
+ |
ConcurrentHashMap map = map5(); |
325 |
+ |
Set set = map.keySet(); |
326 |
+ |
Spliterator<Integer> sp = set.spliterator(); |
327 |
+ |
checkSpliteratorCharacteristics(sp, CONCURRENT | DISTINCT | NONNULL); |
328 |
+ |
assertEquals(sp.estimateSize(), map.size()); |
329 |
+ |
Spliterator<Integer> sp2 = sp.trySplit(); |
330 |
+ |
sp.forEachRemaining((Integer x) -> adder.add(x.longValue())); |
331 |
+ |
long v = adder.sumThenReset(); |
332 |
+ |
sp2.forEachRemaining((Integer x) -> adder.add(x.longValue())); |
333 |
+ |
long v2 = adder.sum(); |
334 |
+ |
assertEquals(v + v2, 15); |
335 |
+ |
} |
336 |
+ |
|
337 |
+ |
/** |
338 |
+ |
* keyset.clear removes all elements from the set |
339 |
+ |
*/ |
340 |
+ |
public void testClear() { |
341 |
+ |
Set full = populatedSet(3); |
342 |
+ |
full.clear(); |
343 |
+ |
assertEquals(0, full.size()); |
344 |
+ |
} |
345 |
+ |
|
346 |
+ |
/** |
347 |
+ |
* keyset.contains returns true for added elements |
348 |
+ |
*/ |
349 |
+ |
public void testContains() { |
350 |
+ |
Set full = populatedSet(3); |
351 |
+ |
assertTrue(full.contains(one)); |
352 |
+ |
assertFalse(full.contains(five)); |
353 |
+ |
} |
354 |
+ |
|
355 |
+ |
/** |
356 |
+ |
* KeySets with equal elements are equal |
357 |
+ |
*/ |
358 |
+ |
public void testEquals() { |
359 |
+ |
Set a = populatedSet(3); |
360 |
+ |
Set b = populatedSet(3); |
361 |
+ |
assertTrue(a.equals(b)); |
362 |
+ |
assertTrue(b.equals(a)); |
363 |
+ |
assertEquals(a.hashCode(), b.hashCode()); |
364 |
+ |
a.add(m1); |
365 |
+ |
assertFalse(a.equals(b)); |
366 |
+ |
assertFalse(b.equals(a)); |
367 |
+ |
b.add(m1); |
368 |
+ |
assertTrue(a.equals(b)); |
369 |
+ |
assertTrue(b.equals(a)); |
370 |
+ |
assertEquals(a.hashCode(), b.hashCode()); |
371 |
+ |
} |
372 |
+ |
|
373 |
+ |
/** |
374 |
+ |
* KeySet.containsAll returns true for collections with subset of elements |
375 |
+ |
*/ |
376 |
+ |
public void testContainsAll() { |
377 |
+ |
Collection full = populatedSet(3); |
378 |
+ |
assertTrue(full.containsAll(Arrays.asList())); |
379 |
+ |
assertTrue(full.containsAll(Arrays.asList(one))); |
380 |
+ |
assertTrue(full.containsAll(Arrays.asList(one, two))); |
381 |
+ |
assertFalse(full.containsAll(Arrays.asList(one, two, six))); |
382 |
+ |
assertFalse(full.containsAll(Arrays.asList(six))); |
383 |
+ |
} |
384 |
+ |
|
385 |
+ |
/** |
386 |
+ |
* KeySet.isEmpty is true when empty, else false |
387 |
+ |
*/ |
388 |
+ |
public void testIsEmpty() { |
389 |
+ |
assertTrue(populatedSet(0).isEmpty()); |
390 |
+ |
assertFalse(populatedSet(3).isEmpty()); |
391 |
+ |
} |
392 |
+ |
|
393 |
+ |
/** |
394 |
+ |
* KeySet.iterator() returns an iterator containing the elements of the |
395 |
+ |
* set |
396 |
+ |
*/ |
397 |
+ |
public void testIterator() { |
398 |
+ |
Collection empty = ConcurrentHashMap.newKeySet(); |
399 |
+ |
int size = 20; |
400 |
+ |
assertFalse(empty.iterator().hasNext()); |
401 |
+ |
try { |
402 |
+ |
empty.iterator().next(); |
403 |
+ |
shouldThrow(); |
404 |
+ |
} catch (NoSuchElementException success) {} |
405 |
+ |
|
406 |
+ |
Integer[] elements = new Integer[size]; |
407 |
+ |
for (int i = 0; i < size; i++) |
408 |
+ |
elements[i] = i; |
409 |
+ |
shuffle(elements); |
410 |
+ |
Collection<Integer> full = populatedSet(elements); |
411 |
+ |
|
412 |
+ |
Iterator it = full.iterator(); |
413 |
+ |
for (int j = 0; j < size; j++) { |
414 |
+ |
assertTrue(it.hasNext()); |
415 |
+ |
it.next(); |
416 |
+ |
} |
417 |
+ |
assertIteratorExhausted(it); |
418 |
+ |
} |
419 |
+ |
|
420 |
+ |
/** |
421 |
+ |
* iterator of empty collections has no elements |
422 |
+ |
*/ |
423 |
+ |
public void testEmptyIterator() { |
424 |
+ |
assertIteratorExhausted(ConcurrentHashMap.newKeySet().iterator()); |
425 |
+ |
assertIteratorExhausted(new ConcurrentHashMap().entrySet().iterator()); |
426 |
+ |
assertIteratorExhausted(new ConcurrentHashMap().values().iterator()); |
427 |
+ |
assertIteratorExhausted(new ConcurrentHashMap().keySet().iterator()); |
428 |
+ |
} |
429 |
+ |
|
430 |
+ |
/** |
431 |
+ |
* KeySet.iterator.remove removes current element |
432 |
+ |
*/ |
433 |
+ |
public void testIteratorRemove() { |
434 |
+ |
Set q = populatedSet(3); |
435 |
+ |
Iterator it = q.iterator(); |
436 |
+ |
Object removed = it.next(); |
437 |
+ |
it.remove(); |
438 |
+ |
|
439 |
+ |
it = q.iterator(); |
440 |
+ |
assertFalse(it.next().equals(removed)); |
441 |
+ |
assertFalse(it.next().equals(removed)); |
442 |
+ |
assertFalse(it.hasNext()); |
443 |
+ |
} |
444 |
+ |
|
445 |
+ |
/** |
446 |
+ |
* KeySet.toString holds toString of elements |
447 |
+ |
*/ |
448 |
+ |
public void testToString() { |
449 |
+ |
assertEquals("[]", ConcurrentHashMap.newKeySet().toString()); |
450 |
+ |
Set full = populatedSet(3); |
451 |
+ |
String s = full.toString(); |
452 |
+ |
for (int i = 0; i < 3; ++i) |
453 |
+ |
assertTrue(s.contains(String.valueOf(i))); |
454 |
+ |
} |
455 |
+ |
|
456 |
+ |
/** |
457 |
+ |
* KeySet.removeAll removes all elements from the given collection |
458 |
+ |
*/ |
459 |
+ |
public void testRemoveAll() { |
460 |
+ |
Set full = populatedSet(3); |
461 |
+ |
assertTrue(full.removeAll(Arrays.asList(one, two))); |
462 |
+ |
assertEquals(1, full.size()); |
463 |
+ |
assertFalse(full.removeAll(Arrays.asList(one, two))); |
464 |
+ |
assertEquals(1, full.size()); |
465 |
+ |
} |
466 |
+ |
|
467 |
+ |
/** |
468 |
+ |
* KeySet.remove removes an element |
469 |
+ |
*/ |
470 |
+ |
public void testRemove() { |
471 |
+ |
Set full = populatedSet(3); |
472 |
+ |
full.remove(one); |
473 |
+ |
assertFalse(full.contains(one)); |
474 |
+ |
assertEquals(2, full.size()); |
475 |
+ |
} |
476 |
+ |
|
477 |
+ |
/** |
478 |
+ |
* keySet.size returns the number of elements |
479 |
+ |
*/ |
480 |
+ |
public void testSize() { |
481 |
+ |
Set empty = ConcurrentHashMap.newKeySet(); |
482 |
+ |
Set full = populatedSet(3); |
483 |
+ |
assertEquals(3, full.size()); |
484 |
+ |
assertEquals(0, empty.size()); |
485 |
+ |
} |
486 |
+ |
|
487 |
+ |
/** |
488 |
+ |
* KeySet.toArray() returns an Object array containing all elements from |
489 |
+ |
* the set |
490 |
+ |
*/ |
491 |
+ |
public void testToArray() { |
492 |
+ |
Object[] a = ConcurrentHashMap.newKeySet().toArray(); |
493 |
+ |
assertTrue(Arrays.equals(new Object[0], a)); |
494 |
+ |
assertSame(Object[].class, a.getClass()); |
495 |
+ |
int size = 20; |
496 |
+ |
Integer[] elements = new Integer[size]; |
497 |
+ |
for (int i = 0; i < size; i++) |
498 |
+ |
elements[i] = i; |
499 |
+ |
shuffle(elements); |
500 |
+ |
Collection<Integer> full = populatedSet(elements); |
501 |
+ |
|
502 |
+ |
assertTrue(Arrays.asList(elements).containsAll(Arrays.asList(full.toArray()))); |
503 |
+ |
assertTrue(full.containsAll(Arrays.asList(full.toArray()))); |
504 |
+ |
assertSame(Object[].class, full.toArray().getClass()); |
505 |
+ |
} |
506 |
+ |
|
507 |
+ |
/** |
508 |
+ |
* toArray(Integer array) returns an Integer array containing all |
509 |
+ |
* elements from the set |
510 |
+ |
*/ |
511 |
+ |
public void testToArray2() { |
512 |
+ |
Collection empty = ConcurrentHashMap.newKeySet(); |
513 |
+ |
Integer[] a; |
514 |
+ |
int size = 20; |
515 |
+ |
|
516 |
+ |
a = new Integer[0]; |
517 |
+ |
assertSame(a, empty.toArray(a)); |
518 |
+ |
|
519 |
+ |
a = new Integer[size / 2]; |
520 |
+ |
Arrays.fill(a, 42); |
521 |
+ |
assertSame(a, empty.toArray(a)); |
522 |
+ |
assertNull(a[0]); |
523 |
+ |
for (int i = 1; i < a.length; i++) |
524 |
+ |
assertEquals(42, (int) a[i]); |
525 |
+ |
|
526 |
+ |
Integer[] elements = new Integer[size]; |
527 |
+ |
for (int i = 0; i < size; i++) |
528 |
+ |
elements[i] = i; |
529 |
+ |
shuffle(elements); |
530 |
+ |
Collection<Integer> full = populatedSet(elements); |
531 |
+ |
|
532 |
+ |
Arrays.fill(a, 42); |
533 |
+ |
assertTrue(Arrays.asList(elements).containsAll(Arrays.asList(full.toArray(a)))); |
534 |
+ |
for (int i = 0; i < a.length; i++) |
535 |
+ |
assertEquals(42, (int) a[i]); |
536 |
+ |
assertSame(Integer[].class, full.toArray(a).getClass()); |
537 |
+ |
|
538 |
+ |
a = new Integer[size]; |
539 |
+ |
Arrays.fill(a, 42); |
540 |
+ |
assertSame(a, full.toArray(a)); |
541 |
+ |
assertTrue(Arrays.asList(elements).containsAll(Arrays.asList(full.toArray(a)))); |
542 |
+ |
} |
543 |
+ |
|
544 |
+ |
/** |
545 |
+ |
* A deserialized serialized set is equal |
546 |
+ |
*/ |
547 |
+ |
public void testSerialization() throws Exception { |
548 |
+ |
int size = 20; |
549 |
+ |
Set x = populatedSet(size); |
550 |
+ |
Set y = serialClone(x); |
551 |
+ |
|
552 |
+ |
assertNotSame(x, y); |
553 |
+ |
assertEquals(x.size(), y.size()); |
554 |
+ |
assertEquals(x, y); |
555 |
+ |
assertEquals(y, x); |
556 |
+ |
} |
557 |
+ |
|
558 |
|
static final int SIZE = 10000; |
559 |
|
static ConcurrentHashMap<Long, Long> longMap; |
560 |
< |
|
560 |
> |
|
561 |
|
static ConcurrentHashMap<Long, Long> longMap() { |
562 |
|
if (longMap == null) { |
563 |
|
longMap = new ConcurrentHashMap<Long, Long>(SIZE); |
567 |
|
return longMap; |
568 |
|
} |
569 |
|
|
570 |
+ |
// explicit function class to avoid type inference problems |
571 |
+ |
static class AddKeys implements BiFunction<Map.Entry<Long,Long>, Map.Entry<Long,Long>, Map.Entry<Long,Long>> { |
572 |
+ |
public Map.Entry<Long,Long> apply(Map.Entry<Long,Long> x, Map.Entry<Long,Long> y) { |
573 |
+ |
return new AbstractMap.SimpleEntry<Long,Long> |
574 |
+ |
(Long.valueOf(x.getKey().longValue() + y.getKey().longValue()), |
575 |
+ |
Long.valueOf(1L)); |
576 |
+ |
} |
577 |
+ |
} |
578 |
+ |
|
579 |
|
/** |
580 |
< |
* forEachKeySequentially, forEachValueSequentially, |
152 |
< |
* forEachEntrySequentially, forEachSequentially, |
153 |
< |
* forEachKeyInParallel, forEachValueInParallel, |
154 |
< |
* forEachEntryInParallel, forEachInParallel traverse all keys, |
155 |
< |
* values, entries, or mappings accordingly |
580 |
> |
* forEachKeySequentially traverses all keys |
581 |
|
*/ |
582 |
< |
public void testForEach() { |
582 |
> |
public void testForEachKeySequentially() { |
583 |
|
LongAdder adder = new LongAdder(); |
584 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
585 |
< |
m.forEachKeySequentially((Long x) -> adder.add(x.longValue())); |
585 |
> |
m.forEachKey(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue())); |
586 |
|
assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2); |
587 |
< |
adder.reset(); |
588 |
< |
m.forEachValueSequentially((Long x) -> adder.add(x.longValue())); |
587 |
> |
} |
588 |
> |
|
589 |
> |
/** |
590 |
> |
* forEachValueSequentially traverses all values |
591 |
> |
*/ |
592 |
> |
public void testForEachValueSequentially() { |
593 |
> |
LongAdder adder = new LongAdder(); |
594 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
595 |
> |
m.forEachValue(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue())); |
596 |
|
assertEquals(adder.sum(), SIZE * (SIZE - 1)); |
597 |
< |
adder.reset(); |
598 |
< |
m.forEachSequentially((Long x, Long y) -> adder.add(x.longValue() + y.longValue())); |
597 |
> |
} |
598 |
> |
|
599 |
> |
/** |
600 |
> |
* forEachSequentially traverses all mappings |
601 |
> |
*/ |
602 |
> |
public void testForEachSequentially() { |
603 |
> |
LongAdder adder = new LongAdder(); |
604 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
605 |
> |
m.forEach(Long.MAX_VALUE, (Long x, Long y) -> adder.add(x.longValue() + y.longValue())); |
606 |
|
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
607 |
< |
adder.reset(); |
608 |
< |
m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue())); |
607 |
> |
} |
608 |
> |
|
609 |
> |
/** |
610 |
> |
* forEachEntrySequentially traverses all entries |
611 |
> |
*/ |
612 |
> |
public void testForEachEntrySequentially() { |
613 |
> |
LongAdder adder = new LongAdder(); |
614 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
615 |
> |
m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue())); |
616 |
|
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
617 |
< |
adder.reset(); |
618 |
< |
m.forEachKeyInParallel((Long x) -> adder.add(x.longValue())); |
617 |
> |
} |
618 |
> |
|
619 |
> |
/** |
620 |
> |
* forEachKeyInParallel traverses all keys |
621 |
> |
*/ |
622 |
> |
public void testForEachKeyInParallel() { |
623 |
> |
LongAdder adder = new LongAdder(); |
624 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
625 |
> |
m.forEachKey(1L, (Long x) -> adder.add(x.longValue())); |
626 |
|
assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2); |
627 |
< |
adder.reset(); |
628 |
< |
m.forEachValueInParallel((Long x) -> adder.add(x.longValue())); |
627 |
> |
} |
628 |
> |
|
629 |
> |
/** |
630 |
> |
* forEachValueInParallel traverses all values |
631 |
> |
*/ |
632 |
> |
public void testForEachValueInParallel() { |
633 |
> |
LongAdder adder = new LongAdder(); |
634 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
635 |
> |
m.forEachValue(1L, (Long x) -> adder.add(x.longValue())); |
636 |
|
assertEquals(adder.sum(), SIZE * (SIZE - 1)); |
637 |
< |
adder.reset(); |
638 |
< |
m.forEachInParallel((Long x, Long y) -> adder.add(x.longValue() + y.longValue())); |
637 |
> |
} |
638 |
> |
|
639 |
> |
/** |
640 |
> |
* forEachInParallel traverses all mappings |
641 |
> |
*/ |
642 |
> |
public void testForEachInParallel() { |
643 |
> |
LongAdder adder = new LongAdder(); |
644 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
645 |
> |
m.forEach(1L, (Long x, Long y) -> adder.add(x.longValue() + y.longValue())); |
646 |
|
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
647 |
< |
adder.reset(); |
648 |
< |
m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue())); |
647 |
> |
} |
648 |
> |
|
649 |
> |
/** |
650 |
> |
* forEachEntryInParallel traverses all entries |
651 |
> |
*/ |
652 |
> |
public void testForEachEntryInParallel() { |
653 |
> |
LongAdder adder = new LongAdder(); |
654 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
655 |
> |
m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue())); |
656 |
|
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
657 |
|
} |
658 |
|
|
659 |
|
/** |
660 |
< |
* Mapped forEachKeySequentially, forEachValueSequentially, |
661 |
< |
* forEachEntrySequentially, forEachSequentially, |
188 |
< |
* forEachKeyInParallel, forEachValueInParallel, |
189 |
< |
* forEachEntryInParallel, forEachInParallel traverse the given |
190 |
< |
* transformations of all keys, values, entries, or mappings |
191 |
< |
* accordingly |
660 |
> |
* Mapped forEachKeySequentially traverses the given |
661 |
> |
* transformations of all keys |
662 |
|
*/ |
663 |
< |
public void testMappedForEach() { |
663 |
> |
public void testMappedForEachKeySequentially() { |
664 |
|
LongAdder adder = new LongAdder(); |
665 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
666 |
< |
m.forEachKeySequentially((Long x) -> Long.valueOf(4 * x.longValue()), |
666 |
> |
m.forEachKey(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()), |
667 |
|
(Long x) -> adder.add(x.longValue())); |
668 |
|
assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2); |
669 |
< |
adder.reset(); |
670 |
< |
m.forEachValueSequentially((Long x) -> Long.valueOf(4 * x.longValue()), |
669 |
> |
} |
670 |
> |
|
671 |
> |
/** |
672 |
> |
* Mapped forEachValueSequentially traverses the given |
673 |
> |
* transformations of all values |
674 |
> |
*/ |
675 |
> |
public void testMappedForEachValueSequentially() { |
676 |
> |
LongAdder adder = new LongAdder(); |
677 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
678 |
> |
m.forEachValue(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()), |
679 |
|
(Long x) -> adder.add(x.longValue())); |
680 |
|
assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1)); |
681 |
< |
adder.reset(); |
682 |
< |
m.forEachSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()), |
681 |
> |
} |
682 |
> |
|
683 |
> |
/** |
684 |
> |
* Mapped forEachSequentially traverses the given |
685 |
> |
* transformations of all mappings |
686 |
> |
*/ |
687 |
> |
public void testMappedForEachSequentially() { |
688 |
> |
LongAdder adder = new LongAdder(); |
689 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
690 |
> |
m.forEach(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()), |
691 |
|
(Long x) -> adder.add(x.longValue())); |
692 |
|
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
693 |
< |
adder.reset(); |
694 |
< |
m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()), |
693 |
> |
} |
694 |
> |
|
695 |
> |
/** |
696 |
> |
* Mapped forEachEntrySequentially traverses the given |
697 |
> |
* transformations of all entries |
698 |
> |
*/ |
699 |
> |
public void testMappedForEachEntrySequentially() { |
700 |
> |
LongAdder adder = new LongAdder(); |
701 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
702 |
> |
m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()), |
703 |
|
(Long x) -> adder.add(x.longValue())); |
704 |
|
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
705 |
< |
adder.reset(); |
706 |
< |
m.forEachKeyInParallel((Long x) -> Long.valueOf(4 * x.longValue()), |
705 |
> |
} |
706 |
> |
|
707 |
> |
/** |
708 |
> |
* Mapped forEachKeyInParallel traverses the given |
709 |
> |
* transformations of all keys |
710 |
> |
*/ |
711 |
> |
public void testMappedForEachKeyInParallel() { |
712 |
> |
LongAdder adder = new LongAdder(); |
713 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
714 |
> |
m.forEachKey(1L, (Long x) -> Long.valueOf(4 * x.longValue()), |
715 |
|
(Long x) -> adder.add(x.longValue())); |
716 |
|
assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2); |
717 |
< |
adder.reset(); |
718 |
< |
m.forEachValueInParallel((Long x) -> Long.valueOf(4 * x.longValue()), |
717 |
> |
} |
718 |
> |
|
719 |
> |
/** |
720 |
> |
* Mapped forEachValueInParallel traverses the given |
721 |
> |
* transformations of all values |
722 |
> |
*/ |
723 |
> |
public void testMappedForEachValueInParallel() { |
724 |
> |
LongAdder adder = new LongAdder(); |
725 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
726 |
> |
m.forEachValue(1L, (Long x) -> Long.valueOf(4 * x.longValue()), |
727 |
|
(Long x) -> adder.add(x.longValue())); |
728 |
|
assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1)); |
729 |
< |
adder.reset(); |
730 |
< |
m.forEachInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()), |
729 |
> |
} |
730 |
> |
|
731 |
> |
/** |
732 |
> |
* Mapped forEachInParallel traverses the given |
733 |
> |
* transformations of all mappings |
734 |
> |
*/ |
735 |
> |
public void testMappedForEachInParallel() { |
736 |
> |
LongAdder adder = new LongAdder(); |
737 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
738 |
> |
m.forEach(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()), |
739 |
|
(Long x) -> adder.add(x.longValue())); |
740 |
|
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
741 |
< |
adder.reset(); |
742 |
< |
m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()), |
741 |
> |
} |
742 |
> |
|
743 |
> |
/** |
744 |
> |
* Mapped forEachEntryInParallel traverses the given |
745 |
> |
* transformations of all entries |
746 |
> |
*/ |
747 |
> |
public void testMappedForEachEntryInParallel() { |
748 |
> |
LongAdder adder = new LongAdder(); |
749 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
750 |
> |
m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()), |
751 |
|
(Long x) -> adder.add(x.longValue())); |
752 |
|
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
753 |
|
} |
754 |
|
|
755 |
|
/** |
756 |
< |
* reduceKeysSequentially, reduceValuesSequentially, |
231 |
< |
* reduceSequentially, reduceEntriesSequentially, |
232 |
< |
* reduceKeysInParallel, reduceValuesInParallel, reduceInParallel, |
233 |
< |
* and reduceEntriesInParallel, accumulate across all keys, |
234 |
< |
* values, entries, or mappings accordingly |
756 |
> |
* reduceKeysSequentially accumulates across all keys, |
757 |
|
*/ |
758 |
< |
public void testReduce() { |
758 |
> |
public void testReduceKeysSequentially() { |
759 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
760 |
|
Long r; |
761 |
< |
r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
761 |
> |
r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
762 |
|
assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2); |
763 |
< |
r = m.reduceValuesSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
763 |
> |
} |
764 |
> |
|
765 |
> |
/** |
766 |
> |
* reduceValuesSequentially accumulates across all values |
767 |
> |
*/ |
768 |
> |
public void testReduceValuesSequentially() { |
769 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
770 |
> |
Long r; |
771 |
> |
r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
772 |
> |
assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2); |
773 |
> |
} |
774 |
> |
|
775 |
> |
/** |
776 |
> |
* reduceEntriesSequentially accumulates across all entries |
777 |
> |
*/ |
778 |
> |
public void testReduceEntriesSequentially() { |
779 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
780 |
> |
Map.Entry<Long,Long> r; |
781 |
> |
r = m.reduceEntries(Long.MAX_VALUE, new AddKeys()); |
782 |
> |
assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2); |
783 |
> |
} |
784 |
> |
|
785 |
> |
/** |
786 |
> |
* reduceKeysInParallel accumulates across all keys |
787 |
> |
*/ |
788 |
> |
public void testReduceKeysInParallel() { |
789 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
790 |
> |
Long r; |
791 |
> |
r = m.reduceKeys(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
792 |
> |
assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2); |
793 |
> |
} |
794 |
> |
|
795 |
> |
/** |
796 |
> |
* reduceValuesInParallel accumulates across all values |
797 |
> |
*/ |
798 |
> |
public void testReduceValuesInParallel() { |
799 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
800 |
> |
Long r; |
801 |
> |
r = m.reduceValues(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
802 |
|
assertEquals((long)r, (long)SIZE * (SIZE - 1)); |
803 |
< |
r = m.reduceSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()), |
803 |
> |
} |
804 |
> |
|
805 |
> |
/** |
806 |
> |
* reduceEntriesInParallel accumulate across all entries |
807 |
> |
*/ |
808 |
> |
public void testReduceEntriesInParallel() { |
809 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
810 |
> |
Map.Entry<Long,Long> r; |
811 |
> |
r = m.reduceEntries(1L, new AddKeys()); |
812 |
> |
assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2); |
813 |
> |
} |
814 |
> |
|
815 |
> |
/** |
816 |
> |
* Mapped reduceKeysSequentially accumulates mapped keys |
817 |
> |
*/ |
818 |
> |
public void testMapReduceKeysSequentially() { |
819 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
820 |
> |
Long r = m.reduceKeys(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()), |
821 |
> |
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
822 |
> |
assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2); |
823 |
> |
} |
824 |
> |
|
825 |
> |
/** |
826 |
> |
* Mapped reduceValuesSequentially accumulates mapped values |
827 |
> |
*/ |
828 |
> |
public void testMapReduceValuesSequentially() { |
829 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
830 |
> |
Long r = m.reduceValues(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()), |
831 |
> |
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
832 |
> |
assertEquals((long)r, (long)4 * SIZE * (SIZE - 1)); |
833 |
> |
} |
834 |
> |
|
835 |
> |
/** |
836 |
> |
* reduceSequentially accumulates across all transformed mappings |
837 |
> |
*/ |
838 |
> |
public void testMappedReduceSequentially() { |
839 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
840 |
> |
Long r = m.reduce(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()), |
841 |
|
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
842 |
< |
|
246 |
< |
assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2); |
247 |
< |
r = m.reduceEntriesSequentially((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()), |
248 |
< |
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
842 |
> |
|
843 |
|
assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2); |
844 |
+ |
} |
845 |
|
|
846 |
< |
r = m.reduceKeysInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
847 |
< |
assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2); |
848 |
< |
r = m.reduceValuesInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
849 |
< |
assertEquals((long)r, (long)SIZE * (SIZE - 1)); |
850 |
< |
r = m.reduceInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()), |
846 |
> |
/** |
847 |
> |
* Mapped reduceKeysInParallel, accumulates mapped keys |
848 |
> |
*/ |
849 |
> |
public void testMapReduceKeysInParallel() { |
850 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
851 |
> |
Long r = m.reduceKeys(1L, (Long x) -> Long.valueOf(4 * x.longValue()), |
852 |
> |
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
853 |
> |
assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2); |
854 |
> |
} |
855 |
> |
|
856 |
> |
/** |
857 |
> |
* Mapped reduceValuesInParallel accumulates mapped values |
858 |
> |
*/ |
859 |
> |
public void testMapReduceValuesInParallel() { |
860 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
861 |
> |
Long r = m.reduceValues(1L, (Long x) -> Long.valueOf(4 * x.longValue()), |
862 |
> |
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
863 |
> |
assertEquals((long)r, (long)4 * SIZE * (SIZE - 1)); |
864 |
> |
} |
865 |
> |
|
866 |
> |
/** |
867 |
> |
* reduceInParallel accumulate across all transformed mappings |
868 |
> |
*/ |
869 |
> |
public void testMappedReduceInParallel() { |
870 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
871 |
> |
Long r; |
872 |
> |
r = m.reduce(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()), |
873 |
|
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
874 |
|
assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2); |
258 |
– |
r = m.reduceEntriesInParallel((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()), |
259 |
– |
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
260 |
– |
assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2); |
875 |
|
} |
876 |
|
|
877 |
< |
/* |
878 |
< |
* Mapped reduceKeysSequentially, reduceKeysToIntSequentially, |
265 |
< |
* reduceKeysToLongSequentially, reduceKeysToDoubleSequentially, |
266 |
< |
* reduceValuesSequentially, reduceValuesToLongSequentially, |
267 |
< |
* reduceValuesToDoubleSequentially, reduceKeysInParallel, |
268 |
< |
* reduceKeysToLongInParallel, reduceKeysToIntInParallel, |
269 |
< |
* reduceKeysToDoubleInParallel, reduceValuesInParallel, |
270 |
< |
* reduceValuesToLongInParallel, reduceValuesToIntInParallel, |
271 |
< |
* reduceValuesToDoubleInParallel accumulate mapped keys, values, |
272 |
< |
* entries, or mappings accordingly |
877 |
> |
/** |
878 |
> |
* reduceKeysToLongSequentially accumulates mapped keys |
879 |
|
*/ |
880 |
< |
public void testMapReduce() { |
880 |
> |
public void testReduceKeysToLongSequentially() { |
881 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
882 |
< |
Long r; long lr; int ir; double dr; |
277 |
< |
r = m.reduceKeysSequentially((Long x) -> Long.valueOf(4 * x.longValue()), |
278 |
< |
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
279 |
< |
assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2); |
280 |
< |
lr = m.reduceKeysToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum); |
882 |
> |
long lr = m.reduceKeysToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum); |
883 |
|
assertEquals(lr, (long)SIZE * (SIZE - 1) / 2); |
884 |
+ |
} |
885 |
+ |
|
886 |
+ |
/** |
887 |
+ |
* reduceKeysToIntSequentially accumulates mapped keys |
888 |
+ |
*/ |
889 |
+ |
public void testReduceKeysToIntSequentially() { |
890 |
+ |
ConcurrentHashMap<Long, Long> m = longMap(); |
891 |
+ |
int ir = m.reduceKeysToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum); |
892 |
+ |
assertEquals(ir, SIZE * (SIZE - 1) / 2); |
893 |
+ |
} |
894 |
|
|
895 |
< |
ir = m.reduceKeysToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum); |
896 |
< |
assertEquals(ir, (int)SIZE * (SIZE - 1) / 2); |
897 |
< |
dr = m.reduceKeysToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum); |
895 |
> |
/** |
896 |
> |
* reduceKeysToDoubleSequentially accumulates mapped keys |
897 |
> |
*/ |
898 |
> |
public void testReduceKeysToDoubleSequentially() { |
899 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
900 |
> |
double dr = m.reduceKeysToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum); |
901 |
|
assertEquals(dr, (double)SIZE * (SIZE - 1) / 2); |
902 |
+ |
} |
903 |
|
|
904 |
< |
r = m.reduceValuesSequentially((Long x) -> Long.valueOf(4 * x.longValue()), |
905 |
< |
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
906 |
< |
assertEquals((long)r, (long)4 * SIZE * (SIZE - 1)); |
907 |
< |
lr = m.reduceValuesToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum); |
904 |
> |
/** |
905 |
> |
* reduceValuesToLongSequentially accumulates mapped values |
906 |
> |
*/ |
907 |
> |
public void testReduceValuesToLongSequentially() { |
908 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
909 |
> |
long lr = m.reduceValuesToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum); |
910 |
|
assertEquals(lr, (long)SIZE * (SIZE - 1)); |
911 |
< |
ir = m.reduceValuesToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum); |
294 |
< |
assertEquals(ir, (int)SIZE * (SIZE - 1)); |
911 |
> |
} |
912 |
|
|
913 |
< |
dr = m.reduceValuesToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum); |
913 |
> |
/** |
914 |
> |
* reduceValuesToIntSequentially accumulates mapped values |
915 |
> |
*/ |
916 |
> |
public void testReduceValuesToIntSequentially() { |
917 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
918 |
> |
int ir = m.reduceValuesToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum); |
919 |
> |
assertEquals(ir, SIZE * (SIZE - 1)); |
920 |
> |
} |
921 |
> |
|
922 |
> |
/** |
923 |
> |
* reduceValuesToDoubleSequentially accumulates mapped values |
924 |
> |
*/ |
925 |
> |
public void testReduceValuesToDoubleSequentially() { |
926 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
927 |
> |
double dr = m.reduceValuesToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum); |
928 |
|
assertEquals(dr, (double)SIZE * (SIZE - 1)); |
929 |
+ |
} |
930 |
|
|
931 |
< |
r = m.reduceKeysInParallel((Long x) -> Long.valueOf(4 * x.longValue()), |
932 |
< |
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
933 |
< |
assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2); |
934 |
< |
lr = m.reduceKeysToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum); |
931 |
> |
/** |
932 |
> |
* reduceKeysToLongInParallel accumulates mapped keys |
933 |
> |
*/ |
934 |
> |
public void testReduceKeysToLongInParallel() { |
935 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
936 |
> |
long lr = m.reduceKeysToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum); |
937 |
|
assertEquals(lr, (long)SIZE * (SIZE - 1) / 2); |
938 |
< |
ir = m.reduceKeysToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum); |
939 |
< |
assertEquals(ir, (int)SIZE * (SIZE - 1) / 2); |
940 |
< |
dr = m.reduceKeysToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum); |
938 |
> |
} |
939 |
> |
|
940 |
> |
/** |
941 |
> |
* reduceKeysToIntInParallel accumulates mapped keys |
942 |
> |
*/ |
943 |
> |
public void testReduceKeysToIntInParallel() { |
944 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
945 |
> |
int ir = m.reduceKeysToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum); |
946 |
> |
assertEquals(ir, SIZE * (SIZE - 1) / 2); |
947 |
> |
} |
948 |
> |
|
949 |
> |
/** |
950 |
> |
* reduceKeysToDoubleInParallel accumulates mapped values |
951 |
> |
*/ |
952 |
> |
public void testReduceKeysToDoubleInParallel() { |
953 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
954 |
> |
double dr = m.reduceKeysToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum); |
955 |
|
assertEquals(dr, (double)SIZE * (SIZE - 1) / 2); |
956 |
+ |
} |
957 |
|
|
958 |
< |
r = m.reduceValuesInParallel((Long x) -> Long.valueOf(4 * x.longValue()), |
959 |
< |
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
960 |
< |
assertEquals((long)r, (long)4 * SIZE * (SIZE - 1)); |
961 |
< |
lr = m.reduceValuesToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum); |
958 |
> |
/** |
959 |
> |
* reduceValuesToLongInParallel accumulates mapped values |
960 |
> |
*/ |
961 |
> |
public void testReduceValuesToLongInParallel() { |
962 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
963 |
> |
long lr = m.reduceValuesToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum); |
964 |
|
assertEquals(lr, (long)SIZE * (SIZE - 1)); |
965 |
< |
ir = m.reduceValuesToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum); |
966 |
< |
assertEquals(ir, (int)SIZE * (SIZE - 1)); |
967 |
< |
dr = m.reduceValuesToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum); |
965 |
> |
} |
966 |
> |
|
967 |
> |
/** |
968 |
> |
* reduceValuesToIntInParallel accumulates mapped values |
969 |
> |
*/ |
970 |
> |
public void testReduceValuesToIntInParallel() { |
971 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
972 |
> |
int ir = m.reduceValuesToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum); |
973 |
> |
assertEquals(ir, SIZE * (SIZE - 1)); |
974 |
> |
} |
975 |
> |
|
976 |
> |
/** |
977 |
> |
* reduceValuesToDoubleInParallel accumulates mapped values |
978 |
> |
*/ |
979 |
> |
public void testReduceValuesToDoubleInParallel() { |
980 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
981 |
> |
double dr = m.reduceValuesToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum); |
982 |
|
assertEquals(dr, (double)SIZE * (SIZE - 1)); |
983 |
|
} |
984 |
|
|
985 |
|
/** |
986 |
< |
* searchKeysSequentially, searchValuesSequentially, |
987 |
< |
* searchSequentially, searchEntriesSequentially, |
323 |
< |
* searchKeysInParallel, searchValuesInParallel, searchInParallel, |
324 |
< |
* searchEntriesInParallel all return a non-null result of search |
325 |
< |
* function, or null if none, across keys, values, entries, or |
326 |
< |
* mappings accordingly |
986 |
> |
* searchKeysSequentially returns a non-null result of search |
987 |
> |
* function, or null if none |
988 |
|
*/ |
989 |
< |
public void testSearch() { |
989 |
> |
public void testSearchKeysSequentially() { |
990 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
991 |
|
Long r; |
992 |
< |
r = m.searchKeysSequentially((Long x) -> x.longValue() == (long)(SIZE/2)? x : null); |
332 |
< |
assertEquals((long)r, (long)(SIZE/2)); |
333 |
< |
r = m.searchValuesSequentially((Long x) -> x.longValue() == (long)(SIZE/2)? x : null); |
334 |
< |
assertEquals((long)r, (long)(SIZE/2)); |
335 |
< |
r = m.searchSequentially((Long x, Long y) -> x.longValue() == (long)(SIZE/2)? x : null); |
992 |
> |
r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null); |
993 |
|
assertEquals((long)r, (long)(SIZE/2)); |
994 |
< |
r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2)? e.getKey() : null); |
338 |
< |
assertEquals((long)r, (long)(SIZE/2)); |
339 |
< |
|
340 |
< |
r = m.searchKeysSequentially((Long x) -> x.longValue() < 0L? x : null); |
341 |
< |
assertNull(r); |
342 |
< |
r = m.searchValuesSequentially((Long x) -> x.longValue() < 0L? x : null); |
343 |
< |
assertNull(r); |
344 |
< |
r = m.searchSequentially((Long x, Long y) -> x.longValue() < 0L? x : null); |
345 |
< |
assertNull(r); |
346 |
< |
r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L? e.getKey() : null); |
994 |
> |
r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null); |
995 |
|
assertNull(r); |
996 |
+ |
} |
997 |
|
|
998 |
< |
r = m.searchKeysInParallel((Long x) -> x.longValue() == (long)(SIZE/2)? x : null); |
999 |
< |
assertEquals((long)r, (long)(SIZE/2)); |
1000 |
< |
r = m.searchValuesInParallel((Long x) -> x.longValue() == (long)(SIZE/2)? x : null); |
1001 |
< |
assertEquals((long)r, (long)(SIZE/2)); |
1002 |
< |
r = m.searchInParallel((Long x, Long y) -> x.longValue() == (long)(SIZE/2)? x : null); |
1003 |
< |
assertEquals((long)r, (long)(SIZE/2)); |
1004 |
< |
r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2)? e.getKey() : null); |
998 |
> |
/** |
999 |
> |
* searchValuesSequentially returns a non-null result of search |
1000 |
> |
* function, or null if none |
1001 |
> |
*/ |
1002 |
> |
public void testSearchValuesSequentially() { |
1003 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
1004 |
> |
Long r; |
1005 |
> |
r = m.searchValues(Long.MAX_VALUE, |
1006 |
> |
(Long x) -> (x.longValue() == (long)(SIZE/2)) ? x : null); |
1007 |
|
assertEquals((long)r, (long)(SIZE/2)); |
1008 |
< |
|
1009 |
< |
r = m.searchKeysInParallel((Long x) -> x.longValue() < 0L? x : null); |
359 |
< |
assertNull(r); |
360 |
< |
r = m.searchValuesInParallel((Long x) -> x.longValue() < 0L? x : null); |
361 |
< |
assertNull(r); |
362 |
< |
r = m.searchInParallel((Long x, Long y) -> x.longValue() < 0L? x : null); |
1008 |
> |
r = m.searchValues(Long.MAX_VALUE, |
1009 |
> |
(Long x) -> (x.longValue() < 0L) ? x : null); |
1010 |
|
assertNull(r); |
1011 |
< |
r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L? e.getKey() : null); |
1011 |
> |
} |
1012 |
> |
|
1013 |
> |
/** |
1014 |
> |
* searchSequentially returns a non-null result of search |
1015 |
> |
* function, or null if none |
1016 |
> |
*/ |
1017 |
> |
public void testSearchSequentially() { |
1018 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
1019 |
> |
Long r; |
1020 |
> |
r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null); |
1021 |
> |
assertEquals((long)r, (long)(SIZE/2)); |
1022 |
> |
r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() < 0L ? x : null); |
1023 |
|
assertNull(r); |
1024 |
|
} |
1025 |
|
|
1026 |
|
/** |
1027 |
< |
* Invoking task versions of bulk methods has same effect as |
1028 |
< |
* parallel methods |
1027 |
> |
* searchEntriesSequentially returns a non-null result of search |
1028 |
> |
* function, or null if none |
1029 |
|
*/ |
1030 |
< |
public void testForkJoinTasks() { |
373 |
< |
LongAdder adder = new LongAdder(); |
1030 |
> |
public void testSearchEntriesSequentially() { |
1031 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
1032 |
< |
ConcurrentHashMap.ForkJoinTasks.forEachKey |
1033 |
< |
(m, (Long x) -> adder.add(x.longValue())).invoke(); |
1034 |
< |
assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2); |
1035 |
< |
adder.reset(); |
1036 |
< |
ConcurrentHashMap.ForkJoinTasks.forEachValue |
1037 |
< |
(m, (Long x) -> adder.add(x.longValue())).invoke(); |
381 |
< |
assertEquals(adder.sum(), SIZE * (SIZE - 1)); |
382 |
< |
adder.reset(); |
383 |
< |
ConcurrentHashMap.ForkJoinTasks.forEach |
384 |
< |
(m, (Long x, Long y) -> adder.add(x.longValue() + y.longValue())).invoke(); |
385 |
< |
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
386 |
< |
adder.reset(); |
387 |
< |
ConcurrentHashMap.ForkJoinTasks.forEachEntry |
388 |
< |
(m, |
389 |
< |
(Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue())).invoke(); |
390 |
< |
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
391 |
< |
adder.reset(); |
392 |
< |
ConcurrentHashMap.ForkJoinTasks.forEachKey |
393 |
< |
(m, (Long x) -> Long.valueOf(4 * x.longValue()), |
394 |
< |
(Long x) -> adder.add(x.longValue())).invoke(); |
395 |
< |
assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2); |
396 |
< |
adder.reset(); |
397 |
< |
ConcurrentHashMap.ForkJoinTasks.forEachValue |
398 |
< |
(m, (Long x) -> Long.valueOf(4 * x.longValue()), |
399 |
< |
(Long x) -> adder.add(x.longValue())).invoke(); |
400 |
< |
assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1)); |
401 |
< |
adder.reset(); |
402 |
< |
ConcurrentHashMap.ForkJoinTasks.forEach |
403 |
< |
(m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()), |
404 |
< |
(Long x) -> adder.add(x.longValue())).invoke(); |
405 |
< |
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
406 |
< |
adder.reset(); |
407 |
< |
ConcurrentHashMap.ForkJoinTasks.forEachEntry |
408 |
< |
(m, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()), |
409 |
< |
(Long x) -> adder.add(x.longValue())).invoke(); |
410 |
< |
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
411 |
< |
adder.reset(); |
1032 |
> |
Long r; |
1033 |
> |
r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null); |
1034 |
> |
assertEquals((long)r, (long)(SIZE/2)); |
1035 |
> |
r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null); |
1036 |
> |
assertNull(r); |
1037 |
> |
} |
1038 |
|
|
1039 |
< |
Long r; long lr; int ir; double dr; |
1040 |
< |
r = ConcurrentHashMap.ForkJoinTasks.reduceKeys |
1041 |
< |
(m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke(); |
1042 |
< |
assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2); |
1043 |
< |
r = ConcurrentHashMap.ForkJoinTasks.reduceValues |
1044 |
< |
(m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke(); |
1045 |
< |
assertEquals((long)r, (long)SIZE * (SIZE - 1)); |
1046 |
< |
r = ConcurrentHashMap.ForkJoinTasks.reduce |
421 |
< |
(m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()), |
422 |
< |
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke(); |
423 |
< |
assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2); |
424 |
< |
r = ConcurrentHashMap.ForkJoinTasks.reduceEntries |
425 |
< |
(m, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()), |
426 |
< |
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke(); |
427 |
< |
assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2); |
428 |
< |
r = ConcurrentHashMap.ForkJoinTasks.reduceKeys |
429 |
< |
(m, (Long x) -> Long.valueOf(4 * x.longValue()), |
430 |
< |
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke(); |
431 |
< |
assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2); |
432 |
< |
lr = ConcurrentHashMap.ForkJoinTasks.reduceKeysToLong |
433 |
< |
(m, (Long x) -> x.longValue(), 0L, Long::sum).invoke(); |
434 |
< |
assertEquals(lr, (long)SIZE * (SIZE - 1) / 2); |
435 |
< |
ir = ConcurrentHashMap.ForkJoinTasks.reduceKeysToInt |
436 |
< |
(m, (Long x) -> x.intValue(), 0, Integer::sum).invoke(); |
437 |
< |
assertEquals(ir, (int)SIZE * (SIZE - 1) / 2); |
438 |
< |
dr = ConcurrentHashMap.ForkJoinTasks.reduceKeysToDouble |
439 |
< |
(m, (Long x) -> x.doubleValue(), 0.0, Double::sum).invoke(); |
440 |
< |
assertEquals(dr, (double)SIZE * (SIZE - 1) / 2); |
441 |
< |
r = ConcurrentHashMap.ForkJoinTasks.reduceValues |
442 |
< |
(m, (Long x) -> Long.valueOf(4 * x.longValue()), |
443 |
< |
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke(); |
444 |
< |
assertEquals((long)r, (long)4 * SIZE * (SIZE - 1)); |
445 |
< |
lr = ConcurrentHashMap.ForkJoinTasks.reduceValuesToLong |
446 |
< |
(m, (Long x) -> x.longValue(), 0L, Long::sum).invoke(); |
447 |
< |
assertEquals(lr, (long)SIZE * (SIZE - 1)); |
448 |
< |
ir = ConcurrentHashMap.ForkJoinTasks.reduceValuesToInt |
449 |
< |
(m, (Long x) -> x.intValue(), 0, Integer::sum).invoke(); |
450 |
< |
assertEquals(ir, (int)SIZE * (SIZE - 1)); |
451 |
< |
dr = ConcurrentHashMap.ForkJoinTasks.reduceValuesToDouble |
452 |
< |
(m, (Long x) -> x.doubleValue(), 0.0, Double::sum).invoke(); |
453 |
< |
assertEquals(dr, (double)SIZE * (SIZE - 1)); |
454 |
< |
r = ConcurrentHashMap.ForkJoinTasks.searchKeys |
455 |
< |
(m, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null).invoke(); |
1039 |
> |
/** |
1040 |
> |
* searchKeysInParallel returns a non-null result of search |
1041 |
> |
* function, or null if none |
1042 |
> |
*/ |
1043 |
> |
public void testSearchKeysInParallel() { |
1044 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
1045 |
> |
Long r; |
1046 |
> |
r = m.searchKeys(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null); |
1047 |
|
assertEquals((long)r, (long)(SIZE/2)); |
1048 |
< |
r = ConcurrentHashMap.ForkJoinTasks.searchValues |
1049 |
< |
(m, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null).invoke(); |
1048 |
> |
r = m.searchKeys(1L, (Long x) -> x.longValue() < 0L ? x : null); |
1049 |
> |
assertNull(r); |
1050 |
> |
} |
1051 |
> |
|
1052 |
> |
/** |
1053 |
> |
* searchValuesInParallel returns a non-null result of search |
1054 |
> |
* function, or null if none |
1055 |
> |
*/ |
1056 |
> |
public void testSearchValuesInParallel() { |
1057 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
1058 |
> |
Long r; |
1059 |
> |
r = m.searchValues(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null); |
1060 |
|
assertEquals((long)r, (long)(SIZE/2)); |
1061 |
< |
r = ConcurrentHashMap.ForkJoinTasks.search |
1062 |
< |
(m, (Long x, Long y) -> x.longValue() == (long)(SIZE/2)? x : null).invoke(); |
1061 |
> |
r = m.searchValues(1L, (Long x) -> x.longValue() < 0L ? x : null); |
1062 |
> |
assertNull(r); |
1063 |
> |
} |
1064 |
> |
|
1065 |
> |
/** |
1066 |
> |
* searchInParallel returns a non-null result of search function, |
1067 |
> |
* or null if none |
1068 |
> |
*/ |
1069 |
> |
public void testSearchInParallel() { |
1070 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
1071 |
> |
Long r; |
1072 |
> |
r = m.search(1L, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null); |
1073 |
|
assertEquals((long)r, (long)(SIZE/2)); |
1074 |
< |
r = ConcurrentHashMap.ForkJoinTasks.searchEntries |
1075 |
< |
(m, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2)? e.getKey() : null).invoke(); |
1074 |
> |
r = m.search(1L, (Long x, Long y) -> x.longValue() < 0L ? x : null); |
1075 |
> |
assertNull(r); |
1076 |
> |
} |
1077 |
> |
|
1078 |
> |
/** |
1079 |
> |
* searchEntriesInParallel returns a non-null result of search |
1080 |
> |
* function, or null if none |
1081 |
> |
*/ |
1082 |
> |
public void testSearchEntriesInParallel() { |
1083 |
> |
ConcurrentHashMap<Long, Long> m = longMap(); |
1084 |
> |
Long r; |
1085 |
> |
r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null); |
1086 |
|
assertEquals((long)r, (long)(SIZE/2)); |
1087 |
< |
} |
1087 |
> |
r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null); |
1088 |
> |
assertNull(r); |
1089 |
> |
} |
1090 |
> |
|
1091 |
|
} |