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.7 by jsr166, Thu Apr 11 19:54:13 2013 UTC vs.
Revision 1.31 by jsr166, Wed Aug 24 22:22:39 2016 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.function.*;
10 < 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.Iterator;
15 > import java.util.Map;
16 > import java.util.NoSuchElementException;
17 > import java.util.Set;
18 > import java.util.Spliterator;
19   import java.util.concurrent.ConcurrentHashMap;
20 + import java.util.concurrent.atomic.LongAdder;
21 + import java.util.function.BiFunction;
22 +
23 + import junit.framework.Test;
24 + import junit.framework.TestSuite;
25  
26   public class ConcurrentHashMap8Test extends JSR166TestCase {
27      public static void main(String[] args) {
28 <        junit.textui.TestRunner.run(suite());
28 >        main(suite(), args);
29      }
30      public static Test suite() {
31          return new TestSuite(ConcurrentHashMap8Test.class);
# Line 34 | Line 47 | public class ConcurrentHashMap8Test exte
47          return map;
48      }
49  
37    // classes for testing Comparable fallbacks
38    static class BI implements Comparable<BI> {
39        private final int value;
40        BI(int value) { this.value = value; }
41        public int compareTo(BI other) {
42            return Integer.compare(value, other.value);
43        }
44        public boolean equals(Object x) {
45            return (x instanceof BI) && ((BI)x).value == value;
46        }
47        public int hashCode() { return 42; }
48    }
49    static class CI extends BI { CI(int value) { super(value); } }
50    static class DI extends BI { DI(int value) { super(value); } }
51
52    static class BS implements Comparable<BS> {
53        private final String value;
54        BS(String value) { this.value = value; }
55        public int compareTo(BS other) {
56            return value.compareTo(other.value);
57        }
58        public boolean equals(Object x) {
59            return (x instanceof BS) && value.equals(((BS)x).value);
60        }
61        public int hashCode() { return 42; }
62    }
63
64    static class LexicographicList<E extends Comparable<E>> extends ArrayList<E>
65        implements Comparable<LexicographicList<E>> {
66        LexicographicList(Collection<E> c) { super(c); }
67        LexicographicList(E e) { super(Collections.singleton(e)); }
68        public int compareTo(LexicographicList<E> other) {
69            int common = Math.min(size(), other.size());
70            int r = 0;
71            for (int i = 0; i < common; i++) {
72                if ((r = get(i).compareTo(other.get(i))) != 0)
73                    break;
74            }
75            if (r == 0)
76                r = Integer.compare(size(), other.size());
77            return r;
78        }
79        private static final long serialVersionUID = 0;
80    }
81
82    /**
83     * Inserted elements that are subclasses of the same Comparable
84     * class are found.
85     */
86    public void testComparableFamily() {
87        ConcurrentHashMap<BI, Boolean> m = new ConcurrentHashMap<>();
88        for (int i = 0; i < 1000; i++) {
89            assertTrue(m.put(new CI(i), true) == null);
90        }
91        for (int i = 0; i < 1000; i++) {
92            assertTrue(m.containsKey(new CI(i)));
93            assertTrue(m.containsKey(new DI(i)));
94        }
95    }
96
97    /**
98     * Elements of classes with erased generic type parameters based
99     * on Comparable can be inserted and found.
100     */
101    public void testGenericComparable() {
102        ConcurrentHashMap<Object, Boolean> m = new ConcurrentHashMap<>();
103        for (int i = 0; i < 1000; i++) {
104            BI bi = new BI(i);
105            BS bs = new BS(String.valueOf(i));
106            LexicographicList<BI> bis = new LexicographicList<BI>(bi);
107            LexicographicList<BS> bss = new LexicographicList<BS>(bs);
108            assertTrue(m.putIfAbsent(bis, true) == null);
109            assertTrue(m.containsKey(bis));
110            if (m.putIfAbsent(bss, true) == null)
111                assertTrue(m.containsKey(bss));
112            assertTrue(m.containsKey(bis));
113        }
114        for (int i = 0; i < 1000; i++) {
115            assertTrue(m.containsKey(new ArrayList(Collections.singleton(new BI(i)))));
116        }
117    }
118
119    /**
120     * Elements of non-comparable classes equal to those of classes
121     * with erased generic type parameters based on Comparable can be
122     * inserted and found.
123     */
124    public void testGenericComparable2() {
125        ConcurrentHashMap<Object, Boolean> m = new ConcurrentHashMap<>();
126        for (int i = 0; i < 1000; i++) {
127            m.put(new ArrayList(Collections.singleton(new BI(i))), true);
128        }
129
130        for (int i = 0; i < 1000; i++) {
131            LexicographicList<BI> bis = new LexicographicList<BI>(new BI(i));
132            assertTrue(m.containsKey(bis));
133        }
134    }
135
50      /**
51       * getOrDefault returns value if present, else default
52       */
# Line 152 | Line 66 | public class ConcurrentHashMap8Test exte
66      }
67  
68      /**
69 <     * computeIfAbsent does not replace  if the key is already present
69 >     * computeIfAbsent does not replace if the key is already present
70       */
71      public void testComputeIfAbsent2() {
72          ConcurrentHashMap map = map5();
# Line 169 | Line 83 | public class ConcurrentHashMap8Test exte
83      }
84  
85      /**
86 <     * computeIfPresent does not replace  if the key is already present
86 >     * computeIfPresent does not replace if the key is already present
87       */
88      public void testComputeIfPresent() {
89          ConcurrentHashMap map = map5();
# Line 186 | Line 100 | public class ConcurrentHashMap8Test exte
100      }
101  
102      /**
103 <     * compute does not replace  if the function returns null
103 >     * compute does not replace if the function returns null
104       */
105      public void testCompute() {
106          ConcurrentHashMap map = map5();
# Line 248 | Line 162 | public class ConcurrentHashMap8Test exte
162          Set<Integer> a = ConcurrentHashMap.<Integer>newKeySet();
163          assertTrue(a.isEmpty());
164          for (int i = 0; i < n; i++)
165 <            a.add(i);
166 <        assertFalse(a.isEmpty());
165 >            assertTrue(a.add(i));
166 >        assertEquals(n == 0, a.isEmpty());
167          assertEquals(n, a.size());
168          return a;
169      }
# Line 258 | Line 172 | public class ConcurrentHashMap8Test exte
172          Set<Integer> a = ConcurrentHashMap.<Integer>newKeySet();
173          assertTrue(a.isEmpty());
174          for (int i = 0; i < elements.length; i++)
175 <            a.add(elements[i]);
175 >            assertTrue(a.add(elements[i]));
176          assertFalse(a.isEmpty());
177          assertEquals(elements.length, a.size());
178          return a;
179      }
180  
181      /**
182 +     * replaceAll replaces all matching values.
183 +     */
184 +    public void testReplaceAll() {
185 +        ConcurrentHashMap<Integer, String> map = map5();
186 +        map.replaceAll((x, y) -> { return x > 3 ? "Z" : y; });
187 +        assertEquals("A", map.get(one));
188 +        assertEquals("B", map.get(two));
189 +        assertEquals("C", map.get(three));
190 +        assertEquals("Z", map.get(four));
191 +        assertEquals("Z", map.get(five));
192 +    }
193 +
194 +    /**
195       * Default-constructed set is empty
196       */
197      public void testNewKeySet() {
# Line 273 | Line 200 | public class ConcurrentHashMap8Test exte
200      }
201  
202      /**
203 +     * keySet.add adds the key with the established value to the map;
204 +     * remove removes it.
205 +     */
206 +    public void testKeySetAddRemove() {
207 +        ConcurrentHashMap map = map5();
208 +        Set set1 = map.keySet();
209 +        Set set2 = map.keySet(true);
210 +        set2.add(six);
211 +        assertTrue(((ConcurrentHashMap.KeySetView)set2).getMap() == map);
212 +        assertTrue(((ConcurrentHashMap.KeySetView)set1).getMap() == map);
213 +        assertEquals(set2.size(), map.size());
214 +        assertEquals(set1.size(), map.size());
215 +        assertTrue((Boolean)map.get(six));
216 +        assertTrue(set1.contains(six));
217 +        assertTrue(set2.contains(six));
218 +        set2.remove(six);
219 +        assertNull(map.get(six));
220 +        assertFalse(set1.contains(six));
221 +        assertFalse(set2.contains(six));
222 +    }
223 +
224 +    /**
225       * keySet.addAll adds each element from the given collection
226       */
227      public void testAddAll() {
228          Set full = populatedSet(3);
229 <        Vector v = new Vector();
230 <        v.add(three);
231 <        v.add(four);
283 <        v.add(five);
284 <        full.addAll(v);
229 >        assertTrue(full.addAll(Arrays.asList(three, four, five)));
230 >        assertEquals(6, full.size());
231 >        assertFalse(full.addAll(Arrays.asList(three, four, five)));
232          assertEquals(6, full.size());
233      }
234  
# Line 291 | Line 238 | public class ConcurrentHashMap8Test exte
238       */
239      public void testAddAll2() {
240          Set full = populatedSet(3);
241 <        Vector v = new Vector();
242 <        v.add(three);
243 <        v.add(four);
244 <        v.add(one); // will not add this element
298 <        full.addAll(v);
241 >        // "one" is duplicate and will not be added
242 >        assertTrue(full.addAll(Arrays.asList(three, four, one)));
243 >        assertEquals(5, full.size());
244 >        assertFalse(full.addAll(Arrays.asList(three, four, one)));
245          assertEquals(5, full.size());
246      }
247  
# Line 304 | Line 250 | public class ConcurrentHashMap8Test exte
250       */
251      public void testAdd2() {
252          Set full = populatedSet(3);
253 <        full.add(one);
253 >        assertFalse(full.add(one));
254          assertEquals(3, full.size());
255      }
256  
# Line 313 | Line 259 | public class ConcurrentHashMap8Test exte
259       */
260      public void testAdd3() {
261          Set full = populatedSet(3);
262 <        full.add(three);
262 >        assertTrue(full.add(three));
263 >        assertTrue(full.contains(three));
264 >        assertFalse(full.add(three));
265          assertTrue(full.contains(three));
266      }
267  
268      /**
269 +     * keySet.add throws UnsupportedOperationException if no default
270 +     * mapped value
271 +     */
272 +    public void testAdd4() {
273 +        Set full = map5().keySet();
274 +        try {
275 +            full.add(three);
276 +            shouldThrow();
277 +        } catch (UnsupportedOperationException success) {}
278 +    }
279 +
280 +    /**
281 +     * keySet.add throws NullPointerException if the specified key is
282 +     * null
283 +     */
284 +    public void testAdd5() {
285 +        Set full = populatedSet(3);
286 +        try {
287 +            full.add(null);
288 +            shouldThrow();
289 +        } catch (NullPointerException success) {}
290 +    }
291 +
292 +    /**
293 +     * KeySetView.getMappedValue returns the map's mapped value
294 +     */
295 +    public void testGetMappedValue() {
296 +        ConcurrentHashMap map = map5();
297 +        assertNull(map.keySet().getMappedValue());
298 +        try {
299 +            map.keySet(null);
300 +            shouldThrow();
301 +        } catch (NullPointerException success) {}
302 +        ConcurrentHashMap.KeySetView set = map.keySet(one);
303 +        assertFalse(set.add(one));
304 +        assertTrue(set.add(six));
305 +        assertTrue(set.add(seven));
306 +        assertTrue(set.getMappedValue() == one);
307 +        assertTrue(map.get(one) != one);
308 +        assertTrue(map.get(six) == one);
309 +        assertTrue(map.get(seven) == one);
310 +    }
311 +
312 +    void checkSpliteratorCharacteristics(Spliterator<?> sp,
313 +                                         int requiredCharacteristics) {
314 +        assertEquals(requiredCharacteristics,
315 +                     requiredCharacteristics & sp.characteristics());
316 +    }
317 +
318 +    /**
319 +     * KeySetView.spliterator returns spliterator over the elements in this set
320 +     */
321 +    public void testKeySetSpliterator() {
322 +        LongAdder adder = new LongAdder();
323 +        ConcurrentHashMap map = map5();
324 +        Set set = map.keySet();
325 +        Spliterator<Integer> sp = set.spliterator();
326 +        checkSpliteratorCharacteristics(sp, CONCURRENT | DISTINCT | NONNULL);
327 +        assertEquals(sp.estimateSize(), map.size());
328 +        Spliterator<Integer> sp2 = sp.trySplit();
329 +        sp.forEachRemaining((Integer x) -> adder.add(x.longValue()));
330 +        long v = adder.sumThenReset();
331 +        sp2.forEachRemaining((Integer x) -> adder.add(x.longValue()));
332 +        long v2 = adder.sum();
333 +        assertEquals(v + v2, 15);
334 +    }
335 +
336 +    /**
337       * keyset.clear removes all elements from the set
338       */
339      public void testClear() {
# Line 357 | Line 373 | public class ConcurrentHashMap8Test exte
373       * KeySet.containsAll returns true for collections with subset of elements
374       */
375      public void testContainsAll() {
376 <        Set full = populatedSet(3);
377 <        Vector v = new Vector();
378 <        v.add(one);
379 <        v.add(two);
380 <        assertTrue(full.containsAll(v));
381 <        v.add(six);
366 <        assertFalse(full.containsAll(v));
376 >        Collection full = populatedSet(3);
377 >        assertTrue(full.containsAll(Arrays.asList()));
378 >        assertTrue(full.containsAll(Arrays.asList(one)));
379 >        assertTrue(full.containsAll(Arrays.asList(one, two)));
380 >        assertFalse(full.containsAll(Arrays.asList(one, two, six)));
381 >        assertFalse(full.containsAll(Arrays.asList(six)));
382      }
383  
384      /**
385       * KeySet.isEmpty is true when empty, else false
386       */
387      public void testIsEmpty() {
388 <        Set empty = ConcurrentHashMap.newKeySet();
389 <        Set full = populatedSet(3);
375 <        assertTrue(empty.isEmpty());
376 <        assertFalse(full.isEmpty());
388 >        assertTrue(populatedSet(0).isEmpty());
389 >        assertFalse(populatedSet(3).isEmpty());
390      }
391  
392      /**
# Line 392 | Line 405 | public class ConcurrentHashMap8Test exte
405          Integer[] elements = new Integer[size];
406          for (int i = 0; i < size; i++)
407              elements[i] = i;
408 <        Collections.shuffle(Arrays.asList(elements));
408 >        shuffle(elements);
409          Collection<Integer> full = populatedSet(elements);
410  
411          Iterator it = full.iterator();
# Line 400 | Line 413 | public class ConcurrentHashMap8Test exte
413              assertTrue(it.hasNext());
414              it.next();
415          }
416 <        assertFalse(it.hasNext());
417 <        try {
418 <            it.next();
419 <            shouldThrow();
420 <        } catch (NoSuchElementException success) {}
416 >        assertIteratorExhausted(it);
417 >    }
418 >
419 >    /**
420 >     * iterator of empty collections has no elements
421 >     */
422 >    public void testEmptyIterator() {
423 >        assertIteratorExhausted(ConcurrentHashMap.newKeySet().iterator());
424 >        assertIteratorExhausted(new ConcurrentHashMap().entrySet().iterator());
425 >        assertIteratorExhausted(new ConcurrentHashMap().values().iterator());
426 >        assertIteratorExhausted(new ConcurrentHashMap().keySet().iterator());
427      }
428  
429      /**
# Line 438 | Line 457 | public class ConcurrentHashMap8Test exte
457       */
458      public void testRemoveAll() {
459          Set full = populatedSet(3);
460 <        Vector v = new Vector();
461 <        v.add(one);
462 <        v.add(two);
444 <        full.removeAll(v);
460 >        assertTrue(full.removeAll(Arrays.asList(one, two)));
461 >        assertEquals(1, full.size());
462 >        assertFalse(full.removeAll(Arrays.asList(one, two)));
463          assertEquals(1, full.size());
464      }
465  
# Line 477 | Line 495 | public class ConcurrentHashMap8Test exte
495          Integer[] elements = new Integer[size];
496          for (int i = 0; i < size; i++)
497              elements[i] = i;
498 <        Collections.shuffle(Arrays.asList(elements));
498 >        shuffle(elements);
499          Collection<Integer> full = populatedSet(elements);
500  
501          assertTrue(Arrays.asList(elements).containsAll(Arrays.asList(full.toArray())));
# Line 497 | Line 515 | public class ConcurrentHashMap8Test exte
515          a = new Integer[0];
516          assertSame(a, empty.toArray(a));
517  
518 <        a = new Integer[size/2];
518 >        a = new Integer[size / 2];
519          Arrays.fill(a, 42);
520          assertSame(a, empty.toArray(a));
521          assertNull(a[0]);
# Line 507 | Line 525 | public class ConcurrentHashMap8Test exte
525          Integer[] elements = new Integer[size];
526          for (int i = 0; i < size; i++)
527              elements[i] = i;
528 <        Collections.shuffle(Arrays.asList(elements));
528 >        shuffle(elements);
529          Collection<Integer> full = populatedSet(elements);
530  
531          Arrays.fill(a, 42);
# Line 530 | Line 548 | public class ConcurrentHashMap8Test exte
548          Set x = populatedSet(size);
549          Set y = serialClone(x);
550  
551 <        assertTrue(x != y);
551 >        assertNotSame(x, y);
552          assertEquals(x.size(), y.size());
535        assertEquals(x.toString(), y.toString());
536        assertTrue(Arrays.equals(x.toArray(), y.toArray()));
553          assertEquals(x, y);
554          assertEquals(y, x);
555      }
556  
541
557      static final int SIZE = 10000;
558      static ConcurrentHashMap<Long, Long> longMap;
559  
# Line 566 | Line 581 | public class ConcurrentHashMap8Test exte
581      public void testForEachKeySequentially() {
582          LongAdder adder = new LongAdder();
583          ConcurrentHashMap<Long, Long> m = longMap();
584 <        m.forEachKeySequentially((Long x) -> adder.add(x.longValue()));
584 >        m.forEachKey(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
585          assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
586      }
587  
# Line 576 | Line 591 | public class ConcurrentHashMap8Test exte
591      public void testForEachValueSequentially() {
592          LongAdder adder = new LongAdder();
593          ConcurrentHashMap<Long, Long> m = longMap();
594 <        m.forEachValueSequentially((Long x) -> adder.add(x.longValue()));
594 >        m.forEachValue(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
595          assertEquals(adder.sum(), SIZE * (SIZE - 1));
596      }
597  
# Line 586 | Line 601 | public class ConcurrentHashMap8Test exte
601      public void testForEachSequentially() {
602          LongAdder adder = new LongAdder();
603          ConcurrentHashMap<Long, Long> m = longMap();
604 <        m.forEachSequentially((Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
604 >        m.forEach(Long.MAX_VALUE, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
605          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
606      }
607  
# Line 596 | Line 611 | public class ConcurrentHashMap8Test exte
611      public void testForEachEntrySequentially() {
612          LongAdder adder = new LongAdder();
613          ConcurrentHashMap<Long, Long> m = longMap();
614 <        m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
614 >        m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
615          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
616      }
617  
# Line 606 | Line 621 | public class ConcurrentHashMap8Test exte
621      public void testForEachKeyInParallel() {
622          LongAdder adder = new LongAdder();
623          ConcurrentHashMap<Long, Long> m = longMap();
624 <        m.forEachKeyInParallel((Long x) -> adder.add(x.longValue()));
624 >        m.forEachKey(1L, (Long x) -> adder.add(x.longValue()));
625          assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
626      }
627  
# Line 616 | Line 631 | public class ConcurrentHashMap8Test exte
631      public void testForEachValueInParallel() {
632          LongAdder adder = new LongAdder();
633          ConcurrentHashMap<Long, Long> m = longMap();
634 <        m.forEachValueInParallel((Long x) -> adder.add(x.longValue()));
634 >        m.forEachValue(1L, (Long x) -> adder.add(x.longValue()));
635          assertEquals(adder.sum(), SIZE * (SIZE - 1));
636      }
637  
# Line 626 | Line 641 | public class ConcurrentHashMap8Test exte
641      public void testForEachInParallel() {
642          LongAdder adder = new LongAdder();
643          ConcurrentHashMap<Long, Long> m = longMap();
644 <        m.forEachInParallel((Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
644 >        m.forEach(1L, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
645          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
646      }
647  
# Line 636 | Line 651 | public class ConcurrentHashMap8Test exte
651      public void testForEachEntryInParallel() {
652          LongAdder adder = new LongAdder();
653          ConcurrentHashMap<Long, Long> m = longMap();
654 <        m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
654 >        m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
655          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
656      }
657  
# Line 647 | Line 662 | public class ConcurrentHashMap8Test exte
662      public void testMappedForEachKeySequentially() {
663          LongAdder adder = new LongAdder();
664          ConcurrentHashMap<Long, Long> m = longMap();
665 <        m.forEachKeySequentially((Long x) -> Long.valueOf(4 * x.longValue()),
665 >        m.forEachKey(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
666                                   (Long x) -> adder.add(x.longValue()));
667          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
668      }
# Line 659 | Line 674 | public class ConcurrentHashMap8Test exte
674      public void testMappedForEachValueSequentially() {
675          LongAdder adder = new LongAdder();
676          ConcurrentHashMap<Long, Long> m = longMap();
677 <        m.forEachValueSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
677 >        m.forEachValue(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
678                                     (Long x) -> adder.add(x.longValue()));
679          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
680      }
# Line 671 | Line 686 | public class ConcurrentHashMap8Test exte
686      public void testMappedForEachSequentially() {
687          LongAdder adder = new LongAdder();
688          ConcurrentHashMap<Long, Long> m = longMap();
689 <        m.forEachSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
689 >        m.forEach(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
690                                (Long x) -> adder.add(x.longValue()));
691          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
692      }
# Line 683 | Line 698 | public class ConcurrentHashMap8Test exte
698      public void testMappedForEachEntrySequentially() {
699          LongAdder adder = new LongAdder();
700          ConcurrentHashMap<Long, Long> m = longMap();
701 <        m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
701 >        m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
702                                     (Long x) -> adder.add(x.longValue()));
703          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
704      }
# Line 695 | Line 710 | public class ConcurrentHashMap8Test exte
710      public void testMappedForEachKeyInParallel() {
711          LongAdder adder = new LongAdder();
712          ConcurrentHashMap<Long, Long> m = longMap();
713 <        m.forEachKeyInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
713 >        m.forEachKey(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
714                                 (Long x) -> adder.add(x.longValue()));
715          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
716      }
# Line 707 | Line 722 | public class ConcurrentHashMap8Test exte
722      public void testMappedForEachValueInParallel() {
723          LongAdder adder = new LongAdder();
724          ConcurrentHashMap<Long, Long> m = longMap();
725 <        m.forEachValueInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
725 >        m.forEachValue(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
726                                   (Long x) -> adder.add(x.longValue()));
727          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
728      }
# Line 719 | Line 734 | public class ConcurrentHashMap8Test exte
734      public void testMappedForEachInParallel() {
735          LongAdder adder = new LongAdder();
736          ConcurrentHashMap<Long, Long> m = longMap();
737 <        m.forEachInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
737 >        m.forEach(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
738                              (Long x) -> adder.add(x.longValue()));
739          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
740      }
# Line 731 | Line 746 | public class ConcurrentHashMap8Test exte
746      public void testMappedForEachEntryInParallel() {
747          LongAdder adder = new LongAdder();
748          ConcurrentHashMap<Long, Long> m = longMap();
749 <        m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
749 >        m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
750                                   (Long x) -> adder.add(x.longValue()));
751          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
752      }
753  
739
754      /**
755       * reduceKeysSequentially accumulates across all keys,
756       */
757      public void testReduceKeysSequentially() {
758          ConcurrentHashMap<Long, Long> m = longMap();
759          Long r;
760 <        r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
760 >        r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
761          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
762      }
763  
# Line 753 | Line 767 | public class ConcurrentHashMap8Test exte
767      public void testReduceValuesSequentially() {
768          ConcurrentHashMap<Long, Long> m = longMap();
769          Long r;
770 <        r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
770 >        r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
771          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
772      }
773  
760
774      /**
775       * reduceEntriesSequentially accumulates across all entries
776       */
777      public void testReduceEntriesSequentially() {
778          ConcurrentHashMap<Long, Long> m = longMap();
779          Map.Entry<Long,Long> r;
780 <        r = m.reduceEntriesSequentially(new AddKeys());
780 >        r = m.reduceEntries(Long.MAX_VALUE, new AddKeys());
781          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
782      }
783  
# Line 774 | Line 787 | public class ConcurrentHashMap8Test exte
787      public void testReduceKeysInParallel() {
788          ConcurrentHashMap<Long, Long> m = longMap();
789          Long r;
790 <        r = m.reduceKeysInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
790 >        r = m.reduceKeys(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
791          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
792      }
793  
# Line 784 | Line 797 | public class ConcurrentHashMap8Test exte
797      public void testReduceValuesInParallel() {
798          ConcurrentHashMap<Long, Long> m = longMap();
799          Long r;
800 <        r = m.reduceValuesInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
800 >        r = m.reduceValues(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
801          assertEquals((long)r, (long)SIZE * (SIZE - 1));
802      }
803  
# Line 794 | Line 807 | public class ConcurrentHashMap8Test exte
807      public void testReduceEntriesInParallel() {
808          ConcurrentHashMap<Long, Long> m = longMap();
809          Map.Entry<Long,Long> r;
810 <        r = m.reduceEntriesInParallel(new AddKeys());
810 >        r = m.reduceEntries(1L, new AddKeys());
811          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
812      }
813  
# Line 803 | Line 816 | public class ConcurrentHashMap8Test exte
816       */
817      public void testMapReduceKeysSequentially() {
818          ConcurrentHashMap<Long, Long> m = longMap();
819 <        Long r = m.reduceKeysSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
819 >        Long r = m.reduceKeys(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
820                                       (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
821          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
822      }
# Line 813 | Line 826 | public class ConcurrentHashMap8Test exte
826       */
827      public void testMapReduceValuesSequentially() {
828          ConcurrentHashMap<Long, Long> m = longMap();
829 <        Long r = m.reduceValuesSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
829 >        Long r = m.reduceValues(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
830                                         (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
831          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
832      }
# Line 823 | Line 836 | public class ConcurrentHashMap8Test exte
836       */
837      public void testMappedReduceSequentially() {
838          ConcurrentHashMap<Long, Long> m = longMap();
839 <        Long r = m.reduceSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
839 >        Long r = m.reduce(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
840                                   (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
841  
842          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
# Line 834 | Line 847 | public class ConcurrentHashMap8Test exte
847       */
848      public void testMapReduceKeysInParallel() {
849          ConcurrentHashMap<Long, Long> m = longMap();
850 <        Long r = m.reduceKeysInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
850 >        Long r = m.reduceKeys(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
851                                     (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
852          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
853      }
# Line 844 | Line 857 | public class ConcurrentHashMap8Test exte
857       */
858      public void testMapReduceValuesInParallel() {
859          ConcurrentHashMap<Long, Long> m = longMap();
860 <        Long r = m.reduceValuesInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
860 >        Long r = m.reduceValues(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
861                                       (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
862          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
863      }
# Line 855 | Line 868 | public class ConcurrentHashMap8Test exte
868      public void testMappedReduceInParallel() {
869          ConcurrentHashMap<Long, Long> m = longMap();
870          Long r;
871 <        r = m.reduceInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
871 >        r = m.reduce(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
872                                 (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
873          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
874      }
875  
863
876      /**
877       * reduceKeysToLongSequentially accumulates mapped keys
878       */
879      public void testReduceKeysToLongSequentially() {
880          ConcurrentHashMap<Long, Long> m = longMap();
881 <        long lr = m.reduceKeysToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum);
881 >        long lr = m.reduceKeysToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum);
882          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
883      }
884  
# Line 875 | Line 887 | public class ConcurrentHashMap8Test exte
887       */
888      public void testReduceKeysToIntSequentially() {
889          ConcurrentHashMap<Long, Long> m = longMap();
890 <        int ir = m.reduceKeysToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
890 >        int ir = m.reduceKeysToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum);
891          assertEquals(ir, SIZE * (SIZE - 1) / 2);
892      }
893  
# Line 884 | Line 896 | public class ConcurrentHashMap8Test exte
896       */
897      public void testReduceKeysToDoubleSequentially() {
898          ConcurrentHashMap<Long, Long> m = longMap();
899 <        double dr = m.reduceKeysToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum);
899 >        double dr = m.reduceKeysToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
900          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
901      }
902  
# Line 893 | Line 905 | public class ConcurrentHashMap8Test exte
905       */
906      public void testReduceValuesToLongSequentially() {
907          ConcurrentHashMap<Long, Long> m = longMap();
908 <        long lr = m.reduceValuesToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum);
908 >        long lr = m.reduceValuesToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum);
909          assertEquals(lr, (long)SIZE * (SIZE - 1));
910      }
911  
# Line 902 | Line 914 | public class ConcurrentHashMap8Test exte
914       */
915      public void testReduceValuesToIntSequentially() {
916          ConcurrentHashMap<Long, Long> m = longMap();
917 <        int ir = m.reduceValuesToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
917 >        int ir = m.reduceValuesToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum);
918          assertEquals(ir, SIZE * (SIZE - 1));
919      }
920  
# Line 911 | Line 923 | public class ConcurrentHashMap8Test exte
923       */
924      public void testReduceValuesToDoubleSequentially() {
925          ConcurrentHashMap<Long, Long> m = longMap();
926 <        double dr = m.reduceValuesToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum);
926 >        double dr = m.reduceValuesToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
927          assertEquals(dr, (double)SIZE * (SIZE - 1));
928      }
929  
# Line 920 | Line 932 | public class ConcurrentHashMap8Test exte
932       */
933      public void testReduceKeysToLongInParallel() {
934          ConcurrentHashMap<Long, Long> m = longMap();
935 <        long lr = m.reduceKeysToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum);
935 >        long lr = m.reduceKeysToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum);
936          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
937      }
938  
# Line 929 | Line 941 | public class ConcurrentHashMap8Test exte
941       */
942      public void testReduceKeysToIntInParallel() {
943          ConcurrentHashMap<Long, Long> m = longMap();
944 <        int ir = m.reduceKeysToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
944 >        int ir = m.reduceKeysToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum);
945          assertEquals(ir, SIZE * (SIZE - 1) / 2);
946      }
947  
# Line 938 | Line 950 | public class ConcurrentHashMap8Test exte
950       */
951      public void testReduceKeysToDoubleInParallel() {
952          ConcurrentHashMap<Long, Long> m = longMap();
953 <        double dr = m.reduceKeysToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum);
953 >        double dr = m.reduceKeysToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
954          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
955      }
956  
# Line 947 | Line 959 | public class ConcurrentHashMap8Test exte
959       */
960      public void testReduceValuesToLongInParallel() {
961          ConcurrentHashMap<Long, Long> m = longMap();
962 <        long lr = m.reduceValuesToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum);
962 >        long lr = m.reduceValuesToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum);
963          assertEquals(lr, (long)SIZE * (SIZE - 1));
964      }
965  
# Line 956 | Line 968 | public class ConcurrentHashMap8Test exte
968       */
969      public void testReduceValuesToIntInParallel() {
970          ConcurrentHashMap<Long, Long> m = longMap();
971 <        int ir = m.reduceValuesToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
971 >        int ir = m.reduceValuesToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum);
972          assertEquals(ir, SIZE * (SIZE - 1));
973      }
974  
# Line 965 | Line 977 | public class ConcurrentHashMap8Test exte
977       */
978      public void testReduceValuesToDoubleInParallel() {
979          ConcurrentHashMap<Long, Long> m = longMap();
980 <        double dr = m.reduceValuesToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum);
980 >        double dr = m.reduceValuesToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
981          assertEquals(dr, (double)SIZE * (SIZE - 1));
982      }
983  
# Line 976 | Line 988 | public class ConcurrentHashMap8Test exte
988      public void testSearchKeysSequentially() {
989          ConcurrentHashMap<Long, Long> m = longMap();
990          Long r;
991 <        r = m.searchKeysSequentially((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
991 >        r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
992          assertEquals((long)r, (long)(SIZE/2));
993 <        r = m.searchKeysSequentially((Long x) -> x.longValue() < 0L ? x : null);
993 >        r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null);
994          assertNull(r);
995      }
996  
# Line 989 | Line 1001 | public class ConcurrentHashMap8Test exte
1001      public void testSearchValuesSequentially() {
1002          ConcurrentHashMap<Long, Long> m = longMap();
1003          Long r;
1004 <        r = m.searchValuesSequentially((Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
1004 >        r = m.searchValues(Long.MAX_VALUE,
1005 >            (Long x) -> (x.longValue() == (long)(SIZE/2)) ? x : null);
1006          assertEquals((long)r, (long)(SIZE/2));
1007 <        r = m.searchValuesSequentially((Long x) -> x.longValue() < 0L ? x : null);
1007 >        r = m.searchValues(Long.MAX_VALUE,
1008 >            (Long x) -> (x.longValue() < 0L) ? x : null);
1009          assertNull(r);
1010      }
1011  
# Line 1002 | Line 1016 | public class ConcurrentHashMap8Test exte
1016      public void testSearchSequentially() {
1017          ConcurrentHashMap<Long, Long> m = longMap();
1018          Long r;
1019 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
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.searchSequentially((Long x, Long y) -> x.longValue() < 0L ? x : null);
1021 >        r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() < 0L ? x : null);
1022          assertNull(r);
1023      }
1024  
# Line 1015 | Line 1029 | public class ConcurrentHashMap8Test exte
1029      public void testSearchEntriesSequentially() {
1030          ConcurrentHashMap<Long, Long> m = longMap();
1031          Long r;
1032 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
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.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1034 >        r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1035          assertNull(r);
1036      }
1037  
# Line 1028 | Line 1042 | public class ConcurrentHashMap8Test exte
1042      public void testSearchKeysInParallel() {
1043          ConcurrentHashMap<Long, Long> m = longMap();
1044          Long r;
1045 <        r = m.searchKeysInParallel((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1045 >        r = m.searchKeys(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1046          assertEquals((long)r, (long)(SIZE/2));
1047 <        r = m.searchKeysInParallel((Long x) -> x.longValue() < 0L ? x : null);
1047 >        r = m.searchKeys(1L, (Long x) -> x.longValue() < 0L ? x : null);
1048          assertNull(r);
1049      }
1050  
# Line 1041 | Line 1055 | public class ConcurrentHashMap8Test exte
1055      public void testSearchValuesInParallel() {
1056          ConcurrentHashMap<Long, Long> m = longMap();
1057          Long r;
1058 <        r = m.searchValuesInParallel((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1058 >        r = m.searchValues(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1059          assertEquals((long)r, (long)(SIZE/2));
1060 <        r = m.searchValuesInParallel((Long x) -> x.longValue() < 0L ? x : null);
1060 >        r = m.searchValues(1L, (Long x) -> x.longValue() < 0L ? x : null);
1061          assertNull(r);
1062      }
1063  
# Line 1054 | Line 1068 | public class ConcurrentHashMap8Test exte
1068      public void testSearchInParallel() {
1069          ConcurrentHashMap<Long, Long> m = longMap();
1070          Long r;
1071 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
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 = m.searchInParallel((Long x, Long y) -> x.longValue() < 0L ? x : null);
1073 >        r = m.search(1L, (Long x, Long y) -> x.longValue() < 0L ? x : null);
1074          assertNull(r);
1075      }
1076  
# Line 1067 | Line 1081 | public class ConcurrentHashMap8Test exte
1081      public void testSearchEntriesInParallel() {
1082          ConcurrentHashMap<Long, Long> m = longMap();
1083          Long r;
1084 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
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 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1086 >        r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1087          assertNull(r);
1088      }
1089  
1076    /**
1077     * Invoking task versions of bulk methods has same effect as
1078     * parallel methods
1079     */
1080    public void testForkJoinTasks() {
1081        LongAdder adder = new LongAdder();
1082        ConcurrentHashMap<Long, Long> m = longMap();
1083        ConcurrentHashMap.ForkJoinTasks.forEachKey
1084            (m, (Long x) -> adder.add(x.longValue())).invoke();
1085        assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
1086        adder.reset();
1087        ConcurrentHashMap.ForkJoinTasks.forEachValue
1088            (m, (Long x) -> adder.add(x.longValue())).invoke();
1089        assertEquals(adder.sum(), SIZE * (SIZE - 1));
1090        adder.reset();
1091        ConcurrentHashMap.ForkJoinTasks.forEach
1092            (m, (Long x, Long y) -> adder.add(x.longValue() + y.longValue())).invoke();
1093        assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
1094        adder.reset();
1095        ConcurrentHashMap.ForkJoinTasks.forEachEntry
1096            (m,
1097             (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue())).invoke();
1098        assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
1099        adder.reset();
1100        ConcurrentHashMap.ForkJoinTasks.forEachKey
1101            (m, (Long x) -> Long.valueOf(4 * x.longValue()),
1102             (Long x) -> adder.add(x.longValue())).invoke();
1103        assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
1104        adder.reset();
1105        ConcurrentHashMap.ForkJoinTasks.forEachValue
1106            (m, (Long x) -> Long.valueOf(4 * x.longValue()),
1107             (Long x) -> adder.add(x.longValue())).invoke();
1108        assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
1109        adder.reset();
1110        ConcurrentHashMap.ForkJoinTasks.forEach
1111            (m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
1112             (Long x) -> adder.add(x.longValue())).invoke();
1113        assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
1114        adder.reset();
1115        ConcurrentHashMap.ForkJoinTasks.forEachEntry
1116            (m, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
1117             (Long x) -> adder.add(x.longValue())).invoke();
1118        assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
1119        adder.reset();
1120
1121        Long r; long lr; int ir; double dr;
1122        r = ConcurrentHashMap.ForkJoinTasks.reduceKeys
1123            (m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1124        assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
1125        r = ConcurrentHashMap.ForkJoinTasks.reduceValues
1126            (m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1127        assertEquals((long)r, (long)SIZE * (SIZE - 1));
1128        r = ConcurrentHashMap.ForkJoinTasks.reduce
1129            (m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
1130             (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1131        assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
1132        r = ConcurrentHashMap.ForkJoinTasks.reduceEntries
1133            (m, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
1134             (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1135        assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
1136        r = ConcurrentHashMap.ForkJoinTasks.reduceKeys
1137            (m, (Long x) -> Long.valueOf(4 * x.longValue()),
1138             (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1139        assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
1140        lr = ConcurrentHashMap.ForkJoinTasks.reduceKeysToLong
1141            (m, (Long x) -> x.longValue(), 0L, Long::sum).invoke();
1142        assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
1143        ir = ConcurrentHashMap.ForkJoinTasks.reduceKeysToInt
1144            (m, (Long x) -> x.intValue(), 0, Integer::sum).invoke();
1145        assertEquals(ir, SIZE * (SIZE - 1) / 2);
1146        dr = ConcurrentHashMap.ForkJoinTasks.reduceKeysToDouble
1147            (m, (Long x) -> x.doubleValue(), 0.0, Double::sum).invoke();
1148        assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
1149        r = ConcurrentHashMap.ForkJoinTasks.reduceValues
1150            (m, (Long x) -> Long.valueOf(4 * x.longValue()),
1151             (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1152        assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
1153        lr = ConcurrentHashMap.ForkJoinTasks.reduceValuesToLong
1154            (m, (Long x) -> x.longValue(), 0L, Long::sum).invoke();
1155        assertEquals(lr, (long)SIZE * (SIZE - 1));
1156        ir = ConcurrentHashMap.ForkJoinTasks.reduceValuesToInt
1157            (m, (Long x) -> x.intValue(), 0, Integer::sum).invoke();
1158        assertEquals(ir, SIZE * (SIZE - 1));
1159        dr = ConcurrentHashMap.ForkJoinTasks.reduceValuesToDouble
1160            (m, (Long x) -> x.doubleValue(), 0.0, Double::sum).invoke();
1161        assertEquals(dr, (double)SIZE * (SIZE - 1));
1162        r = ConcurrentHashMap.ForkJoinTasks.searchKeys
1163            (m, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null).invoke();
1164        assertEquals((long)r, (long)(SIZE/2));
1165        r = ConcurrentHashMap.ForkJoinTasks.searchValues
1166            (m, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null).invoke();
1167        assertEquals((long)r, (long)(SIZE/2));
1168        r = ConcurrentHashMap.ForkJoinTasks.search
1169            (m, (Long x, Long y) -> x.longValue() == (long)(SIZE/2)? x : null).invoke();
1170        assertEquals((long)r, (long)(SIZE/2));
1171        r = ConcurrentHashMap.ForkJoinTasks.searchEntries
1172            (m, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2)? e.getKey() : null).invoke();
1173        assertEquals((long)r, (long)(SIZE/2));
1174    }
1090   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines