Hi Paul,
Paul Benedict wrote:
Since we're talking Map, I think a more utility would be gained by
including putIfAbsent (see java.util.concurrent) because I see many
lines of code that do that idiom all the time.
This idiom is especially prevalent when the value is itself a nested collection.
M
I actually don't need closures to accomplish this. Now this solution I
wouldn't recommend for the JDK, but a subclass of Map could
automatically do the management of the inner collections for me.
Paul
Le 26/10/2009 15:56, Paul Benedict a écrit :
Since we're talking Map, I think a more utility would be gained by
including putIfAbsent (see java.util.concurrent) because I see many
lines of code that do that idiom all the time.
This idiom is especially prevalent when the value is itself a nested
Since we're talking Map, I think a more utility would be gained by
including putIfAbsent (see java.util.concurrent) because I see many
lines of code that do that idiom all the time.
This idiom is especially prevalent when the value is itself a nested collection.
Map> map = ...
List collection = m
This isn't one I've seen much use for.
It would also be possible to write it as a decorating wrapper for a
map, rather than as a static utility method.
Stephen
2009/10/25 assembling signals :
> Hello!
>
> I am thinking about a new method getSafe(...) for the "Collections" utility
> class.
>
>
Hello!
I am thinking about a new method getSafe(...) for the "Collections" utility
class.
It would do get(...) on a map, but instead of returning null (when an entry is
not found),
it would throw NoSuchElementException.
@Nonnull
public static V getSafe(Map map, Object key){
if(!map.contains