this is what the merge function on maps is for.
map.merge(foo, f, (f1, f2) -> f1 + f2)
this can be reduced even further to
map.merge(foo, f, Double::sum)
it is basically the equivalent of
if(map.contains(foo)){
double x = map.get(foo);
map.put(foo, x + f)
} else {
map.put(foo, f)
}