This question is kind of already posted here:
How to convert Map
I think the answer of CollinD is appropriat
As @CollinD suggests, there's no way to do this in a lazy way. To implement get
, you have to convert all the keys with your transformation function (to ensure any duplicates are discovered).
So applying Function<K,NewK>
to Map<K,V>
is out.
You could safely apply Function<NewK,K>
to the map:
V value = innerMap.get( fn.apply(newK) );
I don't see a Guava shorthand for that--it may just not be useful enough. You could get similar results with:
Function<NewK,V> newFn = Functions.compose(Functions.forMap(map), fn);