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.5 by jsr166, Fri Mar 22 18:09:52 2013 UTC vs.
Revision 1.17 by dl, Sun Dec 1 12:19:59 2013 UTC

# Line 6 | Line 6
6  
7   import junit.framework.*;
8   import java.util.*;
9 + import static java.util.Spliterator.*;
10   import java.util.function.*;
11   import java.util.concurrent.atomic.LongAdder;
12   import java.util.concurrent.ConcurrentHashMap;
13 + import java.util.concurrent.ConcurrentHashMap.KeySetView;
14  
15   public class ConcurrentHashMap8Test extends JSR166TestCase {
16      public static void main(String[] args) {
# Line 53 | Line 55 | public class ConcurrentHashMap8Test exte
55      }
56  
57      /**
58 <     * computeIfAbsent does not replace  if the key is already present
58 >     * computeIfAbsent does not replace if the key is already present
59       */
60      public void testComputeIfAbsent2() {
61          ConcurrentHashMap map = map5();
# Line 70 | Line 72 | public class ConcurrentHashMap8Test exte
72      }
73  
74      /**
75 <     * computeIfPresent does not replace  if the key is already present
75 >     * computeIfPresent does not replace if the key is already present
76       */
77      public void testComputeIfPresent() {
78          ConcurrentHashMap map = map5();
# Line 87 | Line 89 | public class ConcurrentHashMap8Test exte
89      }
90  
91      /**
92 <     * compute does not replace  if the function returns null
92 >     * compute does not replace if the function returns null
93       */
94      public void testCompute() {
95          ConcurrentHashMap map = map5();
# Line 165 | Line 167 | public class ConcurrentHashMap8Test exte
167          return a;
168      }
169  
170 +    /*
171 +     * replaceAll replaces all matching values.
172 +     */
173 +    public void testReplaceAll() {
174 +        ConcurrentHashMap<Integer, String> map = map5();
175 +        map.replaceAll((x, y) -> {return x > 3 ? "Z" : y;});
176 +        assertEquals("A", map.get(one));
177 +        assertEquals("B", map.get(two));
178 +        assertEquals("C", map.get(three));
179 +        assertEquals("Z", map.get(four));
180 +        assertEquals("Z", map.get(five));
181 +    }
182 +
183      /**
184       * Default-constructed set is empty
185       */
# Line 174 | Line 189 | public class ConcurrentHashMap8Test exte
189      }
190  
191      /**
192 +     * keySet.add adds the key with the established value to the map;
193 +     * remove removes it.
194 +     */
195 +    public void testKeySetAddRemove() {
196 +        ConcurrentHashMap map = map5();
197 +        Set set1 = map.keySet();
198 +        Set set2 = map.keySet(true);
199 +        set2.add(six);
200 +        assertTrue(((KeySetView)set2).getMap() == map);
201 +        assertTrue(((KeySetView)set1).getMap() == map);
202 +        assertEquals(set2.size(), map.size());
203 +        assertEquals(set1.size(), map.size());
204 +        assertTrue((Boolean)map.get(six));
205 +        assertTrue(set1.contains(six));
206 +        assertTrue(set2.contains(six));
207 +        set2.remove(six);
208 +        assertNull(map.get(six));
209 +        assertFalse(set1.contains(six));
210 +        assertFalse(set2.contains(six));
211 +    }
212 +
213 +
214 +    /**
215       * keySet.addAll adds each element from the given collection
216       */
217      public void testAddAll() {
# Line 219 | Line 257 | public class ConcurrentHashMap8Test exte
257      }
258  
259      /**
260 +     * keySet.add throws UnsupportedOperationException if no default
261 +     * mapped value
262 +     */
263 +    public void testAdd4() {
264 +        Set full = map5().keySet();
265 +        try {
266 +            full.add(three);
267 +            shouldThrow();
268 +        } catch (UnsupportedOperationException e){}
269 +    }
270 +
271 +    /**
272 +     * keySet.add throws NullPointerException if the specified key is
273 +     * null
274 +     */
275 +    public void testAdd5() {
276 +        Set full = populatedSet(3);
277 +        try {
278 +            full.add(null);
279 +            shouldThrow();
280 +        } catch (NullPointerException e){}
281 +    }
282 +
283 +    /**
284 +     * KeySetView.getMappedValue returns the map's mapped value
285 +     */
286 +    public void testGetMappedValue() {
287 +        ConcurrentHashMap map = map5();
288 +        assertNull(map.keySet().getMappedValue());
289 +        try {
290 +            map.keySet(null);
291 +            shouldThrow();
292 +        } catch (NullPointerException e) {}
293 +        KeySetView set = map.keySet(one);
294 +        set.add(one);
295 +        set.add(six);
296 +        set.add(seven);
297 +        assertTrue(set.getMappedValue() == one);
298 +        assertTrue(map.get(one) != one);
299 +        assertTrue(map.get(six) == one);
300 +        assertTrue(map.get(seven) == one);
301 +    }
302 +
303 +    void checkSpliteratorCharacteristics(Spliterator<?> sp,
304 +                                         int requiredCharacteristics) {
305 +        assertEquals(requiredCharacteristics,
306 +                     requiredCharacteristics & sp.characteristics());
307 +    }
308 +
309 +    /**
310 +     * KeySetView.spliterator returns spliterator over the elements in this set
311 +     */
312 +    public void testKeySetSpliterator() {
313 +        LongAdder adder = new LongAdder();
314 +        ConcurrentHashMap map = map5();
315 +        Set set = map.keySet();
316 +        Spliterator<Integer> sp = set.spliterator();
317 +        checkSpliteratorCharacteristics(sp, CONCURRENT | DISTINCT | NONNULL);
318 +        assertEquals(sp.estimateSize(), map.size());
319 +        Spliterator<Integer> sp2 = sp.trySplit();
320 +        sp.forEachRemaining((Integer x) -> adder.add(x.longValue()));
321 +        long v = adder.sumThenReset();
322 +        sp2.forEachRemaining((Integer x) -> adder.add(x.longValue()));
323 +        long v2 = adder.sum();
324 +        assertEquals(v + v2, 15);
325 +    }
326 +
327 +    /**
328       * keyset.clear removes all elements from the set
329       */
330      public void testClear() {
# Line 431 | Line 537 | public class ConcurrentHashMap8Test exte
537          Set x = populatedSet(size);
538          Set y = serialClone(x);
539  
540 <        assertTrue(x != y);
540 >        assertNotSame(x, y);
541          assertEquals(x.size(), y.size());
436        assertEquals(x.toString(), y.toString());
437        assertTrue(Arrays.equals(x.toArray(), y.toArray()));
542          assertEquals(x, y);
543          assertEquals(y, x);
544      }
545  
442
546      static final int SIZE = 10000;
547      static ConcurrentHashMap<Long, Long> longMap;
548  
# Line 467 | Line 570 | public class ConcurrentHashMap8Test exte
570      public void testForEachKeySequentially() {
571          LongAdder adder = new LongAdder();
572          ConcurrentHashMap<Long, Long> m = longMap();
573 <        m.forEachKeySequentially((Long x) -> adder.add(x.longValue()));
573 >        m.forEachKey(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
574          assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
575      }
576  
# Line 477 | Line 580 | public class ConcurrentHashMap8Test exte
580      public void testForEachValueSequentially() {
581          LongAdder adder = new LongAdder();
582          ConcurrentHashMap<Long, Long> m = longMap();
583 <        m.forEachValueSequentially((Long x) -> adder.add(x.longValue()));
583 >        m.forEachValue(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
584          assertEquals(adder.sum(), SIZE * (SIZE - 1));
585      }
586  
# Line 487 | Line 590 | public class ConcurrentHashMap8Test exte
590      public void testForEachSequentially() {
591          LongAdder adder = new LongAdder();
592          ConcurrentHashMap<Long, Long> m = longMap();
593 <        m.forEachSequentially((Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
593 >        m.forEach(Long.MAX_VALUE, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
594          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
595      }
596  
# Line 497 | Line 600 | public class ConcurrentHashMap8Test exte
600      public void testForEachEntrySequentially() {
601          LongAdder adder = new LongAdder();
602          ConcurrentHashMap<Long, Long> m = longMap();
603 <        m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
603 >        m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
604          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
605      }
606  
# Line 507 | Line 610 | public class ConcurrentHashMap8Test exte
610      public void testForEachKeyInParallel() {
611          LongAdder adder = new LongAdder();
612          ConcurrentHashMap<Long, Long> m = longMap();
613 <        m.forEachKeyInParallel((Long x) -> adder.add(x.longValue()));
613 >        m.forEachKey(1L, (Long x) -> adder.add(x.longValue()));
614          assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
615      }
616  
# Line 517 | Line 620 | public class ConcurrentHashMap8Test exte
620      public void testForEachValueInParallel() {
621          LongAdder adder = new LongAdder();
622          ConcurrentHashMap<Long, Long> m = longMap();
623 <        m.forEachValueInParallel((Long x) -> adder.add(x.longValue()));
623 >        m.forEachValue(1L, (Long x) -> adder.add(x.longValue()));
624          assertEquals(adder.sum(), SIZE * (SIZE - 1));
625      }
626  
# Line 527 | Line 630 | public class ConcurrentHashMap8Test exte
630      public void testForEachInParallel() {
631          LongAdder adder = new LongAdder();
632          ConcurrentHashMap<Long, Long> m = longMap();
633 <        m.forEachInParallel((Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
633 >        m.forEach(1L, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
634          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
635      }
636  
# Line 537 | Line 640 | public class ConcurrentHashMap8Test exte
640      public void testForEachEntryInParallel() {
641          LongAdder adder = new LongAdder();
642          ConcurrentHashMap<Long, Long> m = longMap();
643 <        m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
643 >        m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
644          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
645      }
646  
# Line 548 | Line 651 | public class ConcurrentHashMap8Test exte
651      public void testMappedForEachKeySequentially() {
652          LongAdder adder = new LongAdder();
653          ConcurrentHashMap<Long, Long> m = longMap();
654 <        m.forEachKeySequentially((Long x) -> Long.valueOf(4 * x.longValue()),
654 >        m.forEachKey(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
655                                   (Long x) -> adder.add(x.longValue()));
656          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
657      }
# Line 560 | Line 663 | public class ConcurrentHashMap8Test exte
663      public void testMappedForEachValueSequentially() {
664          LongAdder adder = new LongAdder();
665          ConcurrentHashMap<Long, Long> m = longMap();
666 <        m.forEachValueSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
666 >        m.forEachValue(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
667                                     (Long x) -> adder.add(x.longValue()));
668          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
669      }
# Line 572 | Line 675 | public class ConcurrentHashMap8Test exte
675      public void testMappedForEachSequentially() {
676          LongAdder adder = new LongAdder();
677          ConcurrentHashMap<Long, Long> m = longMap();
678 <        m.forEachSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
678 >        m.forEach(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
679                                (Long x) -> adder.add(x.longValue()));
680          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
681      }
# Line 584 | Line 687 | public class ConcurrentHashMap8Test exte
687      public void testMappedForEachEntrySequentially() {
688          LongAdder adder = new LongAdder();
689          ConcurrentHashMap<Long, Long> m = longMap();
690 <        m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
690 >        m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
691                                     (Long x) -> adder.add(x.longValue()));
692          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
693      }
# Line 596 | Line 699 | public class ConcurrentHashMap8Test exte
699      public void testMappedForEachKeyInParallel() {
700          LongAdder adder = new LongAdder();
701          ConcurrentHashMap<Long, Long> m = longMap();
702 <        m.forEachKeyInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
702 >        m.forEachKey(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
703                                 (Long x) -> adder.add(x.longValue()));
704          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
705      }
# Line 608 | Line 711 | public class ConcurrentHashMap8Test exte
711      public void testMappedForEachValueInParallel() {
712          LongAdder adder = new LongAdder();
713          ConcurrentHashMap<Long, Long> m = longMap();
714 <        m.forEachValueInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
714 >        m.forEachValue(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
715                                   (Long x) -> adder.add(x.longValue()));
716          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
717      }
# Line 620 | Line 723 | public class ConcurrentHashMap8Test exte
723      public void testMappedForEachInParallel() {
724          LongAdder adder = new LongAdder();
725          ConcurrentHashMap<Long, Long> m = longMap();
726 <        m.forEachInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
726 >        m.forEach(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
727                              (Long x) -> adder.add(x.longValue()));
728          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
729      }
# Line 632 | Line 735 | public class ConcurrentHashMap8Test exte
735      public void testMappedForEachEntryInParallel() {
736          LongAdder adder = new LongAdder();
737          ConcurrentHashMap<Long, Long> m = longMap();
738 <        m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
738 >        m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
739                                   (Long x) -> adder.add(x.longValue()));
740          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
741      }
742  
640
743      /**
744       * reduceKeysSequentially accumulates across all keys,
745       */
746      public void testReduceKeysSequentially() {
747          ConcurrentHashMap<Long, Long> m = longMap();
748          Long r;
749 <        r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
749 >        r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
750          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
751      }
752  
# Line 654 | Line 756 | public class ConcurrentHashMap8Test exte
756      public void testReduceValuesSequentially() {
757          ConcurrentHashMap<Long, Long> m = longMap();
758          Long r;
759 <        r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
759 >        r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
760          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
761      }
762  
661
763      /**
764       * reduceEntriesSequentially accumulates across all entries
765       */
766      public void testReduceEntriesSequentially() {
767          ConcurrentHashMap<Long, Long> m = longMap();
768          Map.Entry<Long,Long> r;
769 <        r = m.reduceEntriesSequentially(new AddKeys());
769 >        r = m.reduceEntries(Long.MAX_VALUE, new AddKeys());
770          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
771      }
772  
# Line 675 | Line 776 | public class ConcurrentHashMap8Test exte
776      public void testReduceKeysInParallel() {
777          ConcurrentHashMap<Long, Long> m = longMap();
778          Long r;
779 <        r = m.reduceKeysInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
779 >        r = m.reduceKeys(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
780          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
781      }
782  
# Line 685 | Line 786 | public class ConcurrentHashMap8Test exte
786      public void testReduceValuesInParallel() {
787          ConcurrentHashMap<Long, Long> m = longMap();
788          Long r;
789 <        r = m.reduceValuesInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
789 >        r = m.reduceValues(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
790          assertEquals((long)r, (long)SIZE * (SIZE - 1));
791      }
792  
# Line 695 | Line 796 | public class ConcurrentHashMap8Test exte
796      public void testReduceEntriesInParallel() {
797          ConcurrentHashMap<Long, Long> m = longMap();
798          Map.Entry<Long,Long> r;
799 <        r = m.reduceEntriesInParallel(new AddKeys());
799 >        r = m.reduceEntries(1L, new AddKeys());
800          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
801      }
802  
803 <    /*
803 >    /**
804       * Mapped reduceKeysSequentially accumulates mapped keys
805       */
806      public void testMapReduceKeysSequentially() {
807          ConcurrentHashMap<Long, Long> m = longMap();
808 <        Long r = m.reduceKeysSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
808 >        Long r = m.reduceKeys(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
809                                       (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
810          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
811      }
812  
813 <    /*
813 >    /**
814       * Mapped reduceValuesSequentially accumulates mapped values
815       */
816      public void testMapReduceValuesSequentially() {
817          ConcurrentHashMap<Long, Long> m = longMap();
818 <        Long r = m.reduceValuesSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
818 >        Long r = m.reduceValues(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
819                                         (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
820          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
821      }
# Line 724 | Line 825 | public class ConcurrentHashMap8Test exte
825       */
826      public void testMappedReduceSequentially() {
827          ConcurrentHashMap<Long, Long> m = longMap();
828 <        Long r = m.reduceSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
828 >        Long r = m.reduce(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
829                                   (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
830  
831          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
832      }
833  
834 <    /*
834 >    /**
835       * Mapped reduceKeysInParallel, accumulates mapped keys
836       */
837      public void testMapReduceKeysInParallel() {
838          ConcurrentHashMap<Long, Long> m = longMap();
839 <        Long r = m.reduceKeysInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
839 >        Long r = m.reduceKeys(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
840                                     (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
841          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
842      }
843  
844 <    /*
844 >    /**
845       * Mapped reduceValuesInParallel accumulates mapped values
846       */
847      public void testMapReduceValuesInParallel() {
848          ConcurrentHashMap<Long, Long> m = longMap();
849 <        Long r = m.reduceValuesInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
849 >        Long r = m.reduceValues(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
850                                       (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
851          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
852      }
# Line 756 | Line 857 | public class ConcurrentHashMap8Test exte
857      public void testMappedReduceInParallel() {
858          ConcurrentHashMap<Long, Long> m = longMap();
859          Long r;
860 <        r = m.reduceInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
860 >        r = m.reduce(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
861                                 (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
862          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
863      }
864  
865 <
765 <    /*
865 >    /**
866       * reduceKeysToLongSequentially accumulates mapped keys
867       */
868      public void testReduceKeysToLongSequentially() {
869          ConcurrentHashMap<Long, Long> m = longMap();
870 <        long lr = m.reduceKeysToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum);
870 >        long lr = m.reduceKeysToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum);
871          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
872      }
873  
874 <    /*
874 >    /**
875       * reduceKeysToIntSequentially accumulates mapped keys
876       */
877      public void testReduceKeysToIntSequentially() {
878          ConcurrentHashMap<Long, Long> m = longMap();
879 <        int ir = m.reduceKeysToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
879 >        int ir = m.reduceKeysToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum);
880          assertEquals(ir, SIZE * (SIZE - 1) / 2);
881      }
882  
883 <    /*
883 >    /**
884       * reduceKeysToDoubleSequentially accumulates mapped keys
885       */
886      public void testReduceKeysToDoubleSequentially() {
887          ConcurrentHashMap<Long, Long> m = longMap();
888 <        double dr = m.reduceKeysToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum);
888 >        double dr = m.reduceKeysToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
889          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
890      }
891  
892 <    /*
892 >    /**
893       * reduceValuesToLongSequentially accumulates mapped values
894       */
895      public void testReduceValuesToLongSequentially() {
896          ConcurrentHashMap<Long, Long> m = longMap();
897 <        long lr = m.reduceValuesToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum);
897 >        long lr = m.reduceValuesToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum);
898          assertEquals(lr, (long)SIZE * (SIZE - 1));
899      }
900  
901 <    /*
901 >    /**
902       * reduceValuesToIntSequentially accumulates mapped values
903       */
904      public void testReduceValuesToIntSequentially() {
905          ConcurrentHashMap<Long, Long> m = longMap();
906 <        int ir = m.reduceValuesToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
906 >        int ir = m.reduceValuesToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum);
907          assertEquals(ir, SIZE * (SIZE - 1));
908      }
909  
910 <    /*
910 >    /**
911       * reduceValuesToDoubleSequentially accumulates mapped values
912       */
913      public void testReduceValuesToDoubleSequentially() {
914          ConcurrentHashMap<Long, Long> m = longMap();
915 <        double dr = m.reduceValuesToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum);
915 >        double dr = m.reduceValuesToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
916          assertEquals(dr, (double)SIZE * (SIZE - 1));
917      }
918  
919 <    /*
919 >    /**
920       * reduceKeysToLongInParallel accumulates mapped keys
921       */
922      public void testReduceKeysToLongInParallel() {
923          ConcurrentHashMap<Long, Long> m = longMap();
924 <        long lr = m.reduceKeysToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum);
924 >        long lr = m.reduceKeysToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum);
925          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
926      }
927  
928 <    /*
928 >    /**
929       * reduceKeysToIntInParallel accumulates mapped keys
930       */
931      public void testReduceKeysToIntInParallel() {
932          ConcurrentHashMap<Long, Long> m = longMap();
933 <        int ir = m.reduceKeysToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
933 >        int ir = m.reduceKeysToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum);
934          assertEquals(ir, SIZE * (SIZE - 1) / 2);
935      }
936  
937 <    /*
937 >    /**
938       * reduceKeysToDoubleInParallel accumulates mapped values
939       */
940      public void testReduceKeysToDoubleInParallel() {
941          ConcurrentHashMap<Long, Long> m = longMap();
942 <        double dr = m.reduceKeysToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum);
942 >        double dr = m.reduceKeysToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
943          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
944      }
945  
946 <    /*
946 >    /**
947       * reduceValuesToLongInParallel accumulates mapped values
948       */
949      public void testReduceValuesToLongInParallel() {
950          ConcurrentHashMap<Long, Long> m = longMap();
951 <        long lr = m.reduceValuesToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum);
951 >        long lr = m.reduceValuesToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum);
952          assertEquals(lr, (long)SIZE * (SIZE - 1));
953      }
954  
955 <    /*
955 >    /**
956       * reduceValuesToIntInParallel accumulates mapped values
957       */
958      public void testReduceValuesToIntInParallel() {
959          ConcurrentHashMap<Long, Long> m = longMap();
960 <        int ir = m.reduceValuesToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
960 >        int ir = m.reduceValuesToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum);
961          assertEquals(ir, SIZE * (SIZE - 1));
962      }
963  
964 <    /*
964 >    /**
965       * reduceValuesToDoubleInParallel accumulates mapped values
966       */
967      public void testReduceValuesToDoubleInParallel() {
968          ConcurrentHashMap<Long, Long> m = longMap();
969 <        double dr = m.reduceValuesToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum);
969 >        double dr = m.reduceValuesToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
970          assertEquals(dr, (double)SIZE * (SIZE - 1));
971      }
972  
# Line 877 | Line 977 | public class ConcurrentHashMap8Test exte
977      public void testSearchKeysSequentially() {
978          ConcurrentHashMap<Long, Long> m = longMap();
979          Long r;
980 <        r = m.searchKeysSequentially((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
980 >        r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
981          assertEquals((long)r, (long)(SIZE/2));
982 <        r = m.searchKeysSequentially((Long x) -> x.longValue() < 0L ? x : null);
982 >        r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null);
983          assertNull(r);
984      }
985  
# Line 890 | Line 990 | public class ConcurrentHashMap8Test exte
990      public void testSearchValuesSequentially() {
991          ConcurrentHashMap<Long, Long> m = longMap();
992          Long r;
993 <        r = m.searchValuesSequentially((Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
993 >        r = m.searchValues(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
994          assertEquals((long)r, (long)(SIZE/2));
995 <        r = m.searchValuesSequentially((Long x) -> x.longValue() < 0L ? x : null);
995 >        r = m.searchValues(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null);
996          assertNull(r);
997      }
998  
# Line 903 | Line 1003 | public class ConcurrentHashMap8Test exte
1003      public void testSearchSequentially() {
1004          ConcurrentHashMap<Long, Long> m = longMap();
1005          Long r;
1006 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1006 >        r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1007          assertEquals((long)r, (long)(SIZE/2));
1008 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() < 0L ? x : null);
1008 >        r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() < 0L ? x : null);
1009          assertNull(r);
1010      }
1011  
# Line 916 | Line 1016 | public class ConcurrentHashMap8Test exte
1016      public void testSearchEntriesSequentially() {
1017          ConcurrentHashMap<Long, Long> m = longMap();
1018          Long r;
1019 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1019 >        r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1020          assertEquals((long)r, (long)(SIZE/2));
1021 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1021 >        r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1022          assertNull(r);
1023      }
1024  
# Line 929 | Line 1029 | public class ConcurrentHashMap8Test exte
1029      public void testSearchKeysInParallel() {
1030          ConcurrentHashMap<Long, Long> m = longMap();
1031          Long r;
1032 <        r = m.searchKeysInParallel((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1032 >        r = m.searchKeys(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1033          assertEquals((long)r, (long)(SIZE/2));
1034 <        r = m.searchKeysInParallel((Long x) -> x.longValue() < 0L ? x : null);
1034 >        r = m.searchKeys(1L, (Long x) -> x.longValue() < 0L ? x : null);
1035          assertNull(r);
1036      }
1037  
# Line 942 | Line 1042 | public class ConcurrentHashMap8Test exte
1042      public void testSearchValuesInParallel() {
1043          ConcurrentHashMap<Long, Long> m = longMap();
1044          Long r;
1045 <        r = m.searchValuesInParallel((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1045 >        r = m.searchValues(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
1046          assertEquals((long)r, (long)(SIZE/2));
1047 <        r = m.searchValuesInParallel((Long x) -> x.longValue() < 0L ? x : null);
1047 >        r = m.searchValues(1L, (Long x) -> x.longValue() < 0L ? x : null);
1048          assertNull(r);
1049      }
1050  
# Line 955 | Line 1055 | public class ConcurrentHashMap8Test exte
1055      public void testSearchInParallel() {
1056          ConcurrentHashMap<Long, Long> m = longMap();
1057          Long r;
1058 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1058 >        r = m.search(1L, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
1059          assertEquals((long)r, (long)(SIZE/2));
1060 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() < 0L ? x : null);
1060 >        r = m.search(1L, (Long x, Long y) -> x.longValue() < 0L ? x : null);
1061          assertNull(r);
1062      }
1063  
# Line 968 | Line 1068 | public class ConcurrentHashMap8Test exte
1068      public void testSearchEntriesInParallel() {
1069          ConcurrentHashMap<Long, Long> m = longMap();
1070          Long r;
1071 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1071 >        r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
1072          assertEquals((long)r, (long)(SIZE/2));
1073 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1073 >        r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
1074          assertNull(r);
1075      }
1076  
977    /**
978     * Invoking task versions of bulk methods has same effect as
979     * parallel methods
980     */
981    public void testForkJoinTasks() {
982        LongAdder adder = new LongAdder();
983        ConcurrentHashMap<Long, Long> m = longMap();
984        ConcurrentHashMap.ForkJoinTasks.forEachKey
985            (m, (Long x) -> adder.add(x.longValue())).invoke();
986        assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
987        adder.reset();
988        ConcurrentHashMap.ForkJoinTasks.forEachValue
989            (m, (Long x) -> adder.add(x.longValue())).invoke();
990        assertEquals(adder.sum(), SIZE * (SIZE - 1));
991        adder.reset();
992        ConcurrentHashMap.ForkJoinTasks.forEach
993            (m, (Long x, Long y) -> adder.add(x.longValue() + y.longValue())).invoke();
994        assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
995        adder.reset();
996        ConcurrentHashMap.ForkJoinTasks.forEachEntry
997            (m,
998             (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue())).invoke();
999        assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
1000        adder.reset();
1001        ConcurrentHashMap.ForkJoinTasks.forEachKey
1002            (m, (Long x) -> Long.valueOf(4 * x.longValue()),
1003             (Long x) -> adder.add(x.longValue())).invoke();
1004        assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
1005        adder.reset();
1006        ConcurrentHashMap.ForkJoinTasks.forEachValue
1007            (m, (Long x) -> Long.valueOf(4 * x.longValue()),
1008             (Long x) -> adder.add(x.longValue())).invoke();
1009        assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
1010        adder.reset();
1011        ConcurrentHashMap.ForkJoinTasks.forEach
1012            (m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
1013             (Long x) -> adder.add(x.longValue())).invoke();
1014        assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
1015        adder.reset();
1016        ConcurrentHashMap.ForkJoinTasks.forEachEntry
1017            (m, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
1018             (Long x) -> adder.add(x.longValue())).invoke();
1019        assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
1020        adder.reset();
1021
1022        Long r; long lr; int ir; double dr;
1023        r = ConcurrentHashMap.ForkJoinTasks.reduceKeys
1024            (m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1025        assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
1026        r = ConcurrentHashMap.ForkJoinTasks.reduceValues
1027            (m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1028        assertEquals((long)r, (long)SIZE * (SIZE - 1));
1029        r = ConcurrentHashMap.ForkJoinTasks.reduce
1030            (m, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
1031             (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1032        assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
1033        r = ConcurrentHashMap.ForkJoinTasks.reduceEntries
1034            (m, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
1035             (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1036        assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
1037        r = ConcurrentHashMap.ForkJoinTasks.reduceKeys
1038            (m, (Long x) -> Long.valueOf(4 * x.longValue()),
1039             (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1040        assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
1041        lr = ConcurrentHashMap.ForkJoinTasks.reduceKeysToLong
1042            (m, (Long x) -> x.longValue(), 0L, Long::sum).invoke();
1043        assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
1044        ir = ConcurrentHashMap.ForkJoinTasks.reduceKeysToInt
1045            (m, (Long x) -> x.intValue(), 0, Integer::sum).invoke();
1046        assertEquals(ir, SIZE * (SIZE - 1) / 2);
1047        dr = ConcurrentHashMap.ForkJoinTasks.reduceKeysToDouble
1048            (m, (Long x) -> x.doubleValue(), 0.0, Double::sum).invoke();
1049        assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
1050        r = ConcurrentHashMap.ForkJoinTasks.reduceValues
1051            (m, (Long x) -> Long.valueOf(4 * x.longValue()),
1052             (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())).invoke();
1053        assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
1054        lr = ConcurrentHashMap.ForkJoinTasks.reduceValuesToLong
1055            (m, (Long x) -> x.longValue(), 0L, Long::sum).invoke();
1056        assertEquals(lr, (long)SIZE * (SIZE - 1));
1057        ir = ConcurrentHashMap.ForkJoinTasks.reduceValuesToInt
1058            (m, (Long x) -> x.intValue(), 0, Integer::sum).invoke();
1059        assertEquals(ir, SIZE * (SIZE - 1));
1060        dr = ConcurrentHashMap.ForkJoinTasks.reduceValuesToDouble
1061            (m, (Long x) -> x.doubleValue(), 0.0, Double::sum).invoke();
1062        assertEquals(dr, (double)SIZE * (SIZE - 1));
1063        r = ConcurrentHashMap.ForkJoinTasks.searchKeys
1064            (m, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null).invoke();
1065        assertEquals((long)r, (long)(SIZE/2));
1066        r = ConcurrentHashMap.ForkJoinTasks.searchValues
1067            (m, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null).invoke();
1068        assertEquals((long)r, (long)(SIZE/2));
1069        r = ConcurrentHashMap.ForkJoinTasks.search
1070            (m, (Long x, Long y) -> x.longValue() == (long)(SIZE/2)? x : null).invoke();
1071        assertEquals((long)r, (long)(SIZE/2));
1072        r = ConcurrentHashMap.ForkJoinTasks.searchEntries
1073            (m, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2)? e.getKey() : null).invoke();
1074        assertEquals((long)r, (long)(SIZE/2));
1075    }
1077   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines