ImmutableMapFactory { public static <K, V, W> ImmutableMap<K, W> createWithNewValues( Map<K, V> baseMap, Function<? super V, ? extends W> valueMapper) { return create(baseMap, Function.identity(), valueMapper); }  static ImmutableMap<L, W> create(
            Map<K, V> baseMap,
            BiFunction<? super K, ? super V, ? extends L> keyCreator,
            BiFunction<? super K, ? super V, ? extends W> valueCreator); static ImmutableMap<L, W> create(
            Map<K, V> baseMap,
            Function<? super K, ? extends L> keyMapper,
            Function<? super V, ? extends W> valueMapper); static ImmutableMap<L, W> createAndReduceCollisions(
            Map<K, V> baseMap,
            Function<? super K, ? extends L> keyMapper,
            Function<? super V, ? extends W> valueMapper,
            W valueIdentity,
            BinaryOperator<W> collidingKeysAccumulator); static ImmutableMap<L, V> createWithNewKeys(
            Map<K, V> baseMap,
            Function<? super K, ? extends L> keyMapper); static ImmutableMap<K, W> createWithNewValues(
            Map<K, V> baseMap,
            Function<? super V, ? extends W> valueMapper); static ImmutableMap<K, W> createWithNewValues(
            Map<K, V> baseMap,
            BiFunction<? super K, ? super V, ? extends W> valueMapper); static ImmutableMap<K, V> createFromKeys(
            Collection<K> keys,
            Supplier<V> valueSupplier); static ImmutableMap<K, V> createFromKeys(
            Collection<K> keys,
            Function<K, V> valueCreator); static ImmutableMap<K, V> zip(
            List<K> keys,
            List<V> values); static ImmutableMap<K, V> filter(
            Map<K, V> baseMap,
            BiPredicate<K, V> filter); static ImmutableMap<K, V> filterByKeys(
            Map<K, V> baseMap,
            Predicate<K> keyFilter); static ImmutableMap<K, V> filterByValues(
            Map<K, V> baseMap,
            Predicate<V> valueFilter); static ImmutableMap<K, V> parse(
            String s,
            Function<String, K> keyParser,
            Function<String, V> valueParser); static ImmutableMap<K, V> parseAndFilter(
            String s,
            Function<String, K> keyParser,
            Function<String, V> valueParser,
            BiPredicate<K, V> filter);  }
@Test void testCreateWithNewValuesUsingValueMapperWhichUsesBothKeysAndValues() { ImmutableMap<Integer, Integer> baseMap = ImmutableMap.of( 3, 1, 7, 2, 14, 3, 1, 4); ImmutableMap<Integer, Integer> expected = ImmutableMap.of( 3, 4, 7, 9, 14, 17, 1, 5); ImmutableMap<Integer, Integer> actual = ImmutableMapFactory. createWithNewValues(baseMap, Integer::sum); Assertions.assertEquals(expected, actual); }
@Test void testCreateWithNewValuesUsingValueMapperWhichUsesBothKeysAndValuesToADifferentType() { ImmutableMap<Integer, Integer> baseMap = ImmutableMap.of( 3, 1, 7, 2, 14, 3, 1, 4); ImmutableMap<Integer, String> expected = ImmutableMap.of( 3, "4", 7, "9", 14, "17", 1, "5"); ImmutableMap<Integer, String> actual = ImmutableMapFactory. createWithNewValues(baseMap, (key, value) -> String.valueOf(key + value)); Assertions.assertEquals(expected, actual); }
@Test void testCreateWithNewValuesUsingValueMapperWhichUsesOnlyValues() { ImmutableMap<Integer, Integer> baseMap = ImmutableMap.of( 3, 1, 7, 2, 14, 3, 1, 4); ImmutableMap<Integer, Integer> expected = ImmutableMap.of( 3, 1, 7, 4, 14, 9, 1, 16); ImmutableMap<Integer, Integer> actual = ImmutableMapFactory. createWithNewValues(baseMap, value -> value * value); Assertions.assertEquals(expected, actual); }
@Test void testCreateWithNewValuesUsingValueMapperWhichUsesOnlyValuesToADifferentType() { ImmutableMap<Integer, String> baseMap = ImmutableMap.of( 3, "1", 7, "2", 14, "3", 1, "4"); ImmutableMap<Integer, Integer> expected = ImmutableMap.of( 3, 1, 7, 2, 14, 3, 1, 4); ImmutableMap<Integer, Integer> actual = ImmutableMapFactory. createWithNewValues(baseMap, (Function<String, Integer>) Integer::parseInt); Assertions.assertEquals(expected, actual); }