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.9 by dl, Tue May 21 19:11:16 2013 UTC

# Line 34 | Line 34 | public class ConcurrentHashMap8Test exte
34          return map;
35      }
36  
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
37      /**
38       * getOrDefault returns value if present, else default
39       */
# Line 566 | Line 467 | public class ConcurrentHashMap8Test exte
467      public void testForEachKeySequentially() {
468          LongAdder adder = new LongAdder();
469          ConcurrentHashMap<Long, Long> m = longMap();
470 <        m.forEachKeySequentially((Long x) -> adder.add(x.longValue()));
470 >        m.forEachKey(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
471          assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
472      }
473  
# Line 576 | Line 477 | public class ConcurrentHashMap8Test exte
477      public void testForEachValueSequentially() {
478          LongAdder adder = new LongAdder();
479          ConcurrentHashMap<Long, Long> m = longMap();
480 <        m.forEachValueSequentially((Long x) -> adder.add(x.longValue()));
480 >        m.forEachValue(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
481          assertEquals(adder.sum(), SIZE * (SIZE - 1));
482      }
483  
# Line 586 | Line 487 | public class ConcurrentHashMap8Test exte
487      public void testForEachSequentially() {
488          LongAdder adder = new LongAdder();
489          ConcurrentHashMap<Long, Long> m = longMap();
490 <        m.forEachSequentially((Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
490 >        m.forEach(Long.MAX_VALUE, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
491          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
492      }
493  
# Line 596 | Line 497 | public class ConcurrentHashMap8Test exte
497      public void testForEachEntrySequentially() {
498          LongAdder adder = new LongAdder();
499          ConcurrentHashMap<Long, Long> m = longMap();
500 <        m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
500 >        m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
501          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
502      }
503  
# Line 606 | Line 507 | public class ConcurrentHashMap8Test exte
507      public void testForEachKeyInParallel() {
508          LongAdder adder = new LongAdder();
509          ConcurrentHashMap<Long, Long> m = longMap();
510 <        m.forEachKeyInParallel((Long x) -> adder.add(x.longValue()));
510 >        m.forEachKey(1L, (Long x) -> adder.add(x.longValue()));
511          assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
512      }
513  
# Line 616 | Line 517 | public class ConcurrentHashMap8Test exte
517      public void testForEachValueInParallel() {
518          LongAdder adder = new LongAdder();
519          ConcurrentHashMap<Long, Long> m = longMap();
520 <        m.forEachValueInParallel((Long x) -> adder.add(x.longValue()));
520 >        m.forEachValue(1L, (Long x) -> adder.add(x.longValue()));
521          assertEquals(adder.sum(), SIZE * (SIZE - 1));
522      }
523  
# Line 626 | Line 527 | public class ConcurrentHashMap8Test exte
527      public void testForEachInParallel() {
528          LongAdder adder = new LongAdder();
529          ConcurrentHashMap<Long, Long> m = longMap();
530 <        m.forEachInParallel((Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
530 >        m.forEach(1L, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
531          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
532      }
533  
# Line 636 | Line 537 | public class ConcurrentHashMap8Test exte
537      public void testForEachEntryInParallel() {
538          LongAdder adder = new LongAdder();
539          ConcurrentHashMap<Long, Long> m = longMap();
540 <        m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
540 >        m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
541          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
542      }
543  
# Line 647 | Line 548 | public class ConcurrentHashMap8Test exte
548      public void testMappedForEachKeySequentially() {
549          LongAdder adder = new LongAdder();
550          ConcurrentHashMap<Long, Long> m = longMap();
551 <        m.forEachKeySequentially((Long x) -> Long.valueOf(4 * x.longValue()),
551 >        m.forEachKey(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
552                                   (Long x) -> adder.add(x.longValue()));
553          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
554      }
# Line 659 | Line 560 | public class ConcurrentHashMap8Test exte
560      public void testMappedForEachValueSequentially() {
561          LongAdder adder = new LongAdder();
562          ConcurrentHashMap<Long, Long> m = longMap();
563 <        m.forEachValueSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
563 >        m.forEachValue(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
564                                     (Long x) -> adder.add(x.longValue()));
565          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
566      }
# Line 671 | Line 572 | public class ConcurrentHashMap8Test exte
572      public void testMappedForEachSequentially() {
573          LongAdder adder = new LongAdder();
574          ConcurrentHashMap<Long, Long> m = longMap();
575 <        m.forEachSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
575 >        m.forEach(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
576                                (Long x) -> adder.add(x.longValue()));
577          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
578      }
# Line 683 | Line 584 | public class ConcurrentHashMap8Test exte
584      public void testMappedForEachEntrySequentially() {
585          LongAdder adder = new LongAdder();
586          ConcurrentHashMap<Long, Long> m = longMap();
587 <        m.forEachEntrySequentially((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
587 >        m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
588                                     (Long x) -> adder.add(x.longValue()));
589          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
590      }
# Line 695 | Line 596 | public class ConcurrentHashMap8Test exte
596      public void testMappedForEachKeyInParallel() {
597          LongAdder adder = new LongAdder();
598          ConcurrentHashMap<Long, Long> m = longMap();
599 <        m.forEachKeyInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
599 >        m.forEachKey(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
600                                 (Long x) -> adder.add(x.longValue()));
601          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
602      }
# Line 707 | Line 608 | public class ConcurrentHashMap8Test exte
608      public void testMappedForEachValueInParallel() {
609          LongAdder adder = new LongAdder();
610          ConcurrentHashMap<Long, Long> m = longMap();
611 <        m.forEachValueInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
611 >        m.forEachValue(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
612                                   (Long x) -> adder.add(x.longValue()));
613          assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1));
614      }
# Line 719 | Line 620 | public class ConcurrentHashMap8Test exte
620      public void testMappedForEachInParallel() {
621          LongAdder adder = new LongAdder();
622          ConcurrentHashMap<Long, Long> m = longMap();
623 <        m.forEachInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
623 >        m.forEach(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
624                              (Long x) -> adder.add(x.longValue()));
625          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
626      }
# Line 731 | Line 632 | public class ConcurrentHashMap8Test exte
632      public void testMappedForEachEntryInParallel() {
633          LongAdder adder = new LongAdder();
634          ConcurrentHashMap<Long, Long> m = longMap();
635 <        m.forEachEntryInParallel((Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
635 >        m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
636                                   (Long x) -> adder.add(x.longValue()));
637          assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
638      }
# Line 743 | Line 644 | public class ConcurrentHashMap8Test exte
644      public void testReduceKeysSequentially() {
645          ConcurrentHashMap<Long, Long> m = longMap();
646          Long r;
647 <        r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
647 >        r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
648          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
649      }
650  
# Line 753 | Line 654 | public class ConcurrentHashMap8Test exte
654      public void testReduceValuesSequentially() {
655          ConcurrentHashMap<Long, Long> m = longMap();
656          Long r;
657 <        r = m.reduceKeysSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
657 >        r = m.reduceKeys(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
658          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
659      }
660  
# Line 764 | Line 665 | public class ConcurrentHashMap8Test exte
665      public void testReduceEntriesSequentially() {
666          ConcurrentHashMap<Long, Long> m = longMap();
667          Map.Entry<Long,Long> r;
668 <        r = m.reduceEntriesSequentially(new AddKeys());
668 >        r = m.reduceEntries(Long.MAX_VALUE, new AddKeys());
669          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
670      }
671  
# Line 774 | Line 675 | public class ConcurrentHashMap8Test exte
675      public void testReduceKeysInParallel() {
676          ConcurrentHashMap<Long, Long> m = longMap();
677          Long r;
678 <        r = m.reduceKeysInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
678 >        r = m.reduceKeys(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
679          assertEquals((long)r, (long)SIZE * (SIZE - 1) / 2);
680      }
681  
# Line 784 | Line 685 | public class ConcurrentHashMap8Test exte
685      public void testReduceValuesInParallel() {
686          ConcurrentHashMap<Long, Long> m = longMap();
687          Long r;
688 <        r = m.reduceValuesInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
688 >        r = m.reduceValues(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
689          assertEquals((long)r, (long)SIZE * (SIZE - 1));
690      }
691  
# Line 794 | Line 695 | public class ConcurrentHashMap8Test exte
695      public void testReduceEntriesInParallel() {
696          ConcurrentHashMap<Long, Long> m = longMap();
697          Map.Entry<Long,Long> r;
698 <        r = m.reduceEntriesInParallel(new AddKeys());
698 >        r = m.reduceEntries(1L, new AddKeys());
699          assertEquals(r.getKey().longValue(), (long)SIZE * (SIZE - 1) / 2);
700      }
701  
# Line 803 | Line 704 | public class ConcurrentHashMap8Test exte
704       */
705      public void testMapReduceKeysSequentially() {
706          ConcurrentHashMap<Long, Long> m = longMap();
707 <        Long r = m.reduceKeysSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
707 >        Long r = m.reduceKeys(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
708                                       (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
709          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
710      }
# Line 813 | Line 714 | public class ConcurrentHashMap8Test exte
714       */
715      public void testMapReduceValuesSequentially() {
716          ConcurrentHashMap<Long, Long> m = longMap();
717 <        Long r = m.reduceValuesSequentially((Long x) -> Long.valueOf(4 * x.longValue()),
717 >        Long r = m.reduceValues(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()),
718                                         (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
719          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
720      }
# Line 823 | Line 724 | public class ConcurrentHashMap8Test exte
724       */
725      public void testMappedReduceSequentially() {
726          ConcurrentHashMap<Long, Long> m = longMap();
727 <        Long r = m.reduceSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
727 >        Long r = m.reduce(Long.MAX_VALUE, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
728                                   (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
729  
730          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
# Line 834 | Line 735 | public class ConcurrentHashMap8Test exte
735       */
736      public void testMapReduceKeysInParallel() {
737          ConcurrentHashMap<Long, Long> m = longMap();
738 <        Long r = m.reduceKeysInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
738 >        Long r = m.reduceKeys(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
739                                     (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
740          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1) / 2);
741      }
# Line 844 | Line 745 | public class ConcurrentHashMap8Test exte
745       */
746      public void testMapReduceValuesInParallel() {
747          ConcurrentHashMap<Long, Long> m = longMap();
748 <        Long r = m.reduceValuesInParallel((Long x) -> Long.valueOf(4 * x.longValue()),
748 >        Long r = m.reduceValues(1L, (Long x) -> Long.valueOf(4 * x.longValue()),
749                                       (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
750          assertEquals((long)r, (long)4 * SIZE * (SIZE - 1));
751      }
# Line 855 | Line 756 | public class ConcurrentHashMap8Test exte
756      public void testMappedReduceInParallel() {
757          ConcurrentHashMap<Long, Long> m = longMap();
758          Long r;
759 <        r = m.reduceInParallel((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
759 >        r = m.reduce(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()),
760                                 (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()));
761          assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2);
762      }
# Line 866 | Line 767 | public class ConcurrentHashMap8Test exte
767       */
768      public void testReduceKeysToLongSequentially() {
769          ConcurrentHashMap<Long, Long> m = longMap();
770 <        long lr = m.reduceKeysToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum);
770 >        long lr = m.reduceKeysToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum);
771          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
772      }
773  
# Line 875 | Line 776 | public class ConcurrentHashMap8Test exte
776       */
777      public void testReduceKeysToIntSequentially() {
778          ConcurrentHashMap<Long, Long> m = longMap();
779 <        int ir = m.reduceKeysToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
779 >        int ir = m.reduceKeysToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum);
780          assertEquals(ir, SIZE * (SIZE - 1) / 2);
781      }
782  
# Line 884 | Line 785 | public class ConcurrentHashMap8Test exte
785       */
786      public void testReduceKeysToDoubleSequentially() {
787          ConcurrentHashMap<Long, Long> m = longMap();
788 <        double dr = m.reduceKeysToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum);
788 >        double dr = m.reduceKeysToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
789          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
790      }
791  
# Line 893 | Line 794 | public class ConcurrentHashMap8Test exte
794       */
795      public void testReduceValuesToLongSequentially() {
796          ConcurrentHashMap<Long, Long> m = longMap();
797 <        long lr = m.reduceValuesToLongSequentially((Long x) -> x.longValue(), 0L, Long::sum);
797 >        long lr = m.reduceValuesToLong(Long.MAX_VALUE, (Long x) -> x.longValue(), 0L, Long::sum);
798          assertEquals(lr, (long)SIZE * (SIZE - 1));
799      }
800  
# Line 902 | Line 803 | public class ConcurrentHashMap8Test exte
803       */
804      public void testReduceValuesToIntSequentially() {
805          ConcurrentHashMap<Long, Long> m = longMap();
806 <        int ir = m.reduceValuesToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum);
806 >        int ir = m.reduceValuesToInt(Long.MAX_VALUE, (Long x) -> x.intValue(), 0, Integer::sum);
807          assertEquals(ir, SIZE * (SIZE - 1));
808      }
809  
# Line 911 | Line 812 | public class ConcurrentHashMap8Test exte
812       */
813      public void testReduceValuesToDoubleSequentially() {
814          ConcurrentHashMap<Long, Long> m = longMap();
815 <        double dr = m.reduceValuesToDoubleSequentially((Long x) -> x.doubleValue(), 0.0, Double::sum);
815 >        double dr = m.reduceValuesToDouble(Long.MAX_VALUE, (Long x) -> x.doubleValue(), 0.0, Double::sum);
816          assertEquals(dr, (double)SIZE * (SIZE - 1));
817      }
818  
# Line 920 | Line 821 | public class ConcurrentHashMap8Test exte
821       */
822      public void testReduceKeysToLongInParallel() {
823          ConcurrentHashMap<Long, Long> m = longMap();
824 <        long lr = m.reduceKeysToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum);
824 >        long lr = m.reduceKeysToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum);
825          assertEquals(lr, (long)SIZE * (SIZE - 1) / 2);
826      }
827  
# Line 929 | Line 830 | public class ConcurrentHashMap8Test exte
830       */
831      public void testReduceKeysToIntInParallel() {
832          ConcurrentHashMap<Long, Long> m = longMap();
833 <        int ir = m.reduceKeysToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
833 >        int ir = m.reduceKeysToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum);
834          assertEquals(ir, SIZE * (SIZE - 1) / 2);
835      }
836  
# Line 938 | Line 839 | public class ConcurrentHashMap8Test exte
839       */
840      public void testReduceKeysToDoubleInParallel() {
841          ConcurrentHashMap<Long, Long> m = longMap();
842 <        double dr = m.reduceKeysToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum);
842 >        double dr = m.reduceKeysToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
843          assertEquals(dr, (double)SIZE * (SIZE - 1) / 2);
844      }
845  
# Line 947 | Line 848 | public class ConcurrentHashMap8Test exte
848       */
849      public void testReduceValuesToLongInParallel() {
850          ConcurrentHashMap<Long, Long> m = longMap();
851 <        long lr = m.reduceValuesToLongInParallel((Long x) -> x.longValue(), 0L, Long::sum);
851 >        long lr = m.reduceValuesToLong(1L, (Long x) -> x.longValue(), 0L, Long::sum);
852          assertEquals(lr, (long)SIZE * (SIZE - 1));
853      }
854  
# Line 956 | Line 857 | public class ConcurrentHashMap8Test exte
857       */
858      public void testReduceValuesToIntInParallel() {
859          ConcurrentHashMap<Long, Long> m = longMap();
860 <        int ir = m.reduceValuesToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum);
860 >        int ir = m.reduceValuesToInt(1L, (Long x) -> x.intValue(), 0, Integer::sum);
861          assertEquals(ir, SIZE * (SIZE - 1));
862      }
863  
# Line 965 | Line 866 | public class ConcurrentHashMap8Test exte
866       */
867      public void testReduceValuesToDoubleInParallel() {
868          ConcurrentHashMap<Long, Long> m = longMap();
869 <        double dr = m.reduceValuesToDoubleInParallel((Long x) -> x.doubleValue(), 0.0, Double::sum);
869 >        double dr = m.reduceValuesToDouble(1L, (Long x) -> x.doubleValue(), 0.0, Double::sum);
870          assertEquals(dr, (double)SIZE * (SIZE - 1));
871      }
872  
# Line 976 | Line 877 | public class ConcurrentHashMap8Test exte
877      public void testSearchKeysSequentially() {
878          ConcurrentHashMap<Long, Long> m = longMap();
879          Long r;
880 <        r = m.searchKeysSequentially((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
880 >        r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
881          assertEquals((long)r, (long)(SIZE/2));
882 <        r = m.searchKeysSequentially((Long x) -> x.longValue() < 0L ? x : null);
882 >        r = m.searchKeys(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null);
883          assertNull(r);
884      }
885  
# Line 989 | Line 890 | public class ConcurrentHashMap8Test exte
890      public void testSearchValuesSequentially() {
891          ConcurrentHashMap<Long, Long> m = longMap();
892          Long r;
893 <        r = m.searchValuesSequentially((Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
893 >        r = m.searchValues(Long.MAX_VALUE, (Long x) -> x.longValue() == (long)(SIZE/2)? x : null);
894          assertEquals((long)r, (long)(SIZE/2));
895 <        r = m.searchValuesSequentially((Long x) -> x.longValue() < 0L ? x : null);
895 >        r = m.searchValues(Long.MAX_VALUE, (Long x) -> x.longValue() < 0L ? x : null);
896          assertNull(r);
897      }
898  
# Line 1002 | Line 903 | public class ConcurrentHashMap8Test exte
903      public void testSearchSequentially() {
904          ConcurrentHashMap<Long, Long> m = longMap();
905          Long r;
906 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
906 >        r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
907          assertEquals((long)r, (long)(SIZE/2));
908 <        r = m.searchSequentially((Long x, Long y) -> x.longValue() < 0L ? x : null);
908 >        r = m.search(Long.MAX_VALUE, (Long x, Long y) -> x.longValue() < 0L ? x : null);
909          assertNull(r);
910      }
911  
# Line 1015 | Line 916 | public class ConcurrentHashMap8Test exte
916      public void testSearchEntriesSequentially() {
917          ConcurrentHashMap<Long, Long> m = longMap();
918          Long r;
919 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
919 >        r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
920          assertEquals((long)r, (long)(SIZE/2));
921 <        r = m.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
921 >        r = m.searchEntries(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
922          assertNull(r);
923      }
924  
# Line 1028 | Line 929 | public class ConcurrentHashMap8Test exte
929      public void testSearchKeysInParallel() {
930          ConcurrentHashMap<Long, Long> m = longMap();
931          Long r;
932 <        r = m.searchKeysInParallel((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
932 >        r = m.searchKeys(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
933          assertEquals((long)r, (long)(SIZE/2));
934 <        r = m.searchKeysInParallel((Long x) -> x.longValue() < 0L ? x : null);
934 >        r = m.searchKeys(1L, (Long x) -> x.longValue() < 0L ? x : null);
935          assertNull(r);
936      }
937  
# Line 1041 | Line 942 | public class ConcurrentHashMap8Test exte
942      public void testSearchValuesInParallel() {
943          ConcurrentHashMap<Long, Long> m = longMap();
944          Long r;
945 <        r = m.searchValuesInParallel((Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
945 >        r = m.searchValues(1L, (Long x) -> x.longValue() == (long)(SIZE/2) ? x : null);
946          assertEquals((long)r, (long)(SIZE/2));
947 <        r = m.searchValuesInParallel((Long x) -> x.longValue() < 0L ? x : null);
947 >        r = m.searchValues(1L, (Long x) -> x.longValue() < 0L ? x : null);
948          assertNull(r);
949      }
950  
# Line 1054 | Line 955 | public class ConcurrentHashMap8Test exte
955      public void testSearchInParallel() {
956          ConcurrentHashMap<Long, Long> m = longMap();
957          Long r;
958 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
958 >        r = m.search(1L, (Long x, Long y) -> x.longValue() == (long)(SIZE/2) ? x : null);
959          assertEquals((long)r, (long)(SIZE/2));
960 <        r = m.searchInParallel((Long x, Long y) -> x.longValue() < 0L ? x : null);
960 >        r = m.search(1L, (Long x, Long y) -> x.longValue() < 0L ? x : null);
961          assertNull(r);
962      }
963  
# Line 1067 | Line 968 | public class ConcurrentHashMap8Test exte
968      public void testSearchEntriesInParallel() {
969          ConcurrentHashMap<Long, Long> m = longMap();
970          Long r;
971 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
971 >        r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() == (long)(SIZE/2) ? e.getKey() : null);
972          assertEquals((long)r, (long)(SIZE/2));
973 <        r = m.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
973 >        r = m.searchEntries(1L, (Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null);
974          assertNull(r);
975      }
976  
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    }
977   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines