Comment #2 by sebdotv:
I keep writing the following method in many projects:
public static <K, V> Map<K, V> hashMapFromFunction(Set<K> keys,
Function<K, V>
function) {
Map<K, V> map = Maps.newHashMapWithExpectedSize(keys.size());
for (K key : keys) {
map.put(key, function.apply(key));
}
return map;
}
A common scenario would be to cache the result of applying the function to
each
element, for example to later sort using the (cached values of the)
function.
Nothing really ugly here, but one could for example forget to set the
initial size of
the map.
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings