68 |
|
map.computeIfAbsent(six, (x) -> null); |
69 |
|
assertFalse(map.containsKey(six)); |
70 |
|
} |
71 |
< |
|
71 |
> |
|
72 |
|
/** |
73 |
|
* computeIfPresent does not replace if the key is already present |
74 |
|
*/ |
380 |
|
elements[i] = i; |
381 |
|
Collections.shuffle(Arrays.asList(elements)); |
382 |
|
Collection<Integer> full = populatedSet(elements); |
383 |
< |
|
383 |
> |
|
384 |
|
assertTrue(Arrays.asList(elements).containsAll(Arrays.asList(full.toArray()))); |
385 |
|
assertTrue(full.containsAll(Arrays.asList(full.toArray()))); |
386 |
|
assertSame(Object[].class, full.toArray().getClass()); |
442 |
|
|
443 |
|
static final int SIZE = 10000; |
444 |
|
static ConcurrentHashMap<Long, Long> longMap; |
445 |
< |
|
445 |
> |
|
446 |
|
static ConcurrentHashMap<Long, Long> longMap() { |
447 |
|
if (longMap == null) { |
448 |
|
longMap = new ConcurrentHashMap<Long, Long>(SIZE); |
456 |
|
static class AddKeys implements BiFunction<Map.Entry<Long,Long>, Map.Entry<Long,Long>, Map.Entry<Long,Long>> { |
457 |
|
public Map.Entry<Long,Long> apply(Map.Entry<Long,Long> x, Map.Entry<Long,Long> y) { |
458 |
|
return new AbstractMap.SimpleEntry<Long,Long> |
459 |
< |
(Long.valueOf(x.getKey().longValue() + y.getKey().longValue()), |
459 |
> |
(Long.valueOf(x.getKey().longValue() + y.getKey().longValue()), |
460 |
|
Long.valueOf(1L)); |
461 |
|
} |
462 |
|
} |
726 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
727 |
|
Long r = m.reduceSequentially((Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()), |
728 |
|
(Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue())); |
729 |
< |
|
729 |
> |
|
730 |
|
assertEquals((long)r, (long)3 * SIZE * (SIZE - 1) / 2); |
731 |
|
} |
732 |
|
|
777 |
|
public void testReduceKeysToIntSequentially() { |
778 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
779 |
|
int ir = m.reduceKeysToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum); |
780 |
< |
assertEquals(ir, (int)SIZE * (SIZE - 1) / 2); |
780 |
> |
assertEquals(ir, SIZE * (SIZE - 1) / 2); |
781 |
|
} |
782 |
|
|
783 |
|
/* |
804 |
|
public void testReduceValuesToIntSequentially() { |
805 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
806 |
|
int ir = m.reduceValuesToIntSequentially((Long x) -> x.intValue(), 0, Integer::sum); |
807 |
< |
assertEquals(ir, (int)SIZE * (SIZE - 1)); |
807 |
> |
assertEquals(ir, SIZE * (SIZE - 1)); |
808 |
|
} |
809 |
|
|
810 |
|
/* |
831 |
|
public void testReduceKeysToIntInParallel() { |
832 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
833 |
|
int ir = m.reduceKeysToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum); |
834 |
< |
assertEquals(ir, (int)SIZE * (SIZE - 1) / 2); |
834 |
> |
assertEquals(ir, SIZE * (SIZE - 1) / 2); |
835 |
|
} |
836 |
|
|
837 |
|
/* |
858 |
|
public void testReduceValuesToIntInParallel() { |
859 |
|
ConcurrentHashMap<Long, Long> m = longMap(); |
860 |
|
int ir = m.reduceValuesToIntInParallel((Long x) -> x.intValue(), 0, Integer::sum); |
861 |
< |
assertEquals(ir, (int)SIZE * (SIZE - 1)); |
861 |
> |
assertEquals(ir, SIZE * (SIZE - 1)); |
862 |
|
} |
863 |
|
|
864 |
|
/* |
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.searchKeysSequentially((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.searchKeysSequentially((Long x) -> x.longValue() < 0L ? x : null); |
883 |
|
assertNull(r); |
884 |
|
} |
885 |
|
|
892 |
|
Long r; |
893 |
|
r = m.searchValuesSequentially((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.searchValuesSequentially((Long x) -> x.longValue() < 0L ? x : null); |
896 |
|
assertNull(r); |
897 |
|
} |
898 |
|
|
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.searchSequentially((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.searchSequentially((Long x, Long y) -> x.longValue() < 0L ? x : null); |
909 |
|
assertNull(r); |
910 |
|
} |
911 |
|
|
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.searchEntriesSequentially((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.searchEntriesSequentially((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null); |
922 |
|
assertNull(r); |
923 |
|
} |
924 |
|
|
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.searchKeysInParallel((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.searchKeysInParallel((Long x) -> x.longValue() < 0L ? x : null); |
935 |
|
assertNull(r); |
936 |
|
} |
937 |
|
|
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.searchValuesInParallel((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.searchValuesInParallel((Long x) -> x.longValue() < 0L ? x : null); |
948 |
|
assertNull(r); |
949 |
|
} |
950 |
|
|
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.searchInParallel((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.searchInParallel((Long x, Long y) -> x.longValue() < 0L ? x : null); |
961 |
|
assertNull(r); |
962 |
|
} |
963 |
|
|
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.searchEntriesInParallel((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.searchEntriesInParallel((Map.Entry<Long,Long> e) -> e.getKey().longValue() < 0L ? e.getKey() : null); |
974 |
|
assertNull(r); |
975 |
|
} |
976 |
|
|
994 |
|
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2); |
995 |
|
adder.reset(); |
996 |
|
ConcurrentHashMap.ForkJoinTasks.forEachEntry |
997 |
< |
(m, |
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(); |
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, (int)SIZE * (SIZE - 1) / 2); |
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); |
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, (int)SIZE * (SIZE - 1)); |
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)); |
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 |
< |
} |
1075 |
> |
} |
1076 |
|
} |