You can do this fairly simply like this.
Function<A, Integer> extractBFromA = new Function<A, Integer>() {
@Override public Integer apply(A input) {
return input.b;
}
}
...
Map<String,Integer> res = Maps.transformValues(map, extractBFromA);
Or, without the reusability in mind:
Map<String,Integer> res = Maps.transformValues(map, new Function<A,Integer>() {
@Override public Integer apply(A input) {
return input.b;
}
});
Note: the result is a view on the initial map. You might want to store it in a new HashMap
(or ImmutableMap
or any other Map
).