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.19 by jsr166, Wed Dec 31 21:35:01 2014 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines