I have a Map the String key is nothing but numeric value like \"123\" etc. I\'m getting numeric value because this values are
The short answer is no, Guava does not provide this one out of the box.
The simple way would be something like below. There are some cautions, however.
public static Map transformMap(Map map, Function keyFunction, Function valueFunction) {
Map transformedMap = newHashMap();
for (Entry entry : map.entrySet()) {
transformedMap.put(
keyFunction.apply(entry.getKey()),
valueFunction.apply(entry.getValue()));
}
return transformedMap;
}
public static Map transformKeys(Map map, Function keyFunction) {
return transformMap(map, keyFunction, Functions.identity());
}
Guava's transformers are all "lazy" or view-based. I think to implement a map key transformer, you'd want a two-way function. My understanding is that there is a Converter that is in the works by the Guava team, which would solve that problem.
The other problem you run into is that you'd have to deal with the possibility of duplicates in order to be "Jimmy-proof", another Guava principle. One way to handle that would be to return a Multimap; another would be to throw an exception when you encounter duplicates. What I would not suggest is hiding the problem e.g. by ignoring subsequent entries with duplicate keys, or by overwriting the new entry with the duplicate key.