ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ConcurrentHashMap8Test.java
(Generate patch)

Comparing jsr166/src/test/tck/ConcurrentHashMap8Test.java (file contents):
Revision 1.2 by dl, Fri Mar 22 00:24:35 2013 UTC vs.
Revision 1.17 by dl, Sun Dec 1 12:19:59 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines