class ImmutableMapFactory {

    public static <K, L, V, W> ImmutableMap<L, W> create(
            Map<K, V> baseMap,
            BiFunction<? super K, ? super V, ? extends L> keyCreator,
            BiFunction<? super K, ? super V, ? extends W> valueCreator) {
        return baseMap.entrySet().stream()
                .collect(ImmutableMap.toImmutableMap(
                        e -> keyCreator.apply(e.getKey(), e.getValue()),
                        e -> valueCreator.apply(e.getKey(), e.getValue())));
    }

}