package com.facebook.presto.util;

import com.facebook.presto.sql.analyzer.Symbol;
import com.google.common.base.Function;
import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.Maps;

import java.util.Map;

public class MapTransformer<K, V>
{
    private final Map<K, V> map;

    public static <K, V> MapTransformer<K, V> of(Map<K, V> map)
    {
        return new MapTransformer<>(map);
    }

    public MapTransformer(Map<K, V> map)
    {
        this.map = map;
    }

    public <V1> MapTransformer<K, V1> transformValues(Function<V, V1> function)
    {
        return new MapTransformer<>(Maps.transformValues(map, function));
    }

    public Map<K, V> map()
    {
        return map;
    }

    public MapTransformer<V, K> inverse()
    {
        return new MapTransformer<>(ImmutableBiMap.copyOf(map).inverse());
    }

    public BiMap<K, V> biMap()
    {
        return ImmutableBiMap.copyOf(map);
    }
}

@@ -32,56 +32,8 @@
 l;%0A%0A
-import com.facebook.presto.sql.analyzer.Symbol;%0A
 impo
@@ -153,24 +153,71 @@
 tableBiMap;%0A
+import com.google.common.collect.ImmutableMap;%0A
 import com.g
@@ -976,11 +976,101 @@
 );%0A    %7D
+%0A%0A    public Map%3CK, V%3E immutableMap()%0A    %7B%0A        return ImmutableMap.copyOf(map);%0A    %7D
 %0A%7D%0A

Add MapTransformer.toImmutableMap