How's about Collections.getSafe(...) for Map, which wouldn't return null? (original) (raw)
Rémi Forax forax at univ-mlv.fr
Mon Oct 26 15:20:07 UTC 2009
- Previous message: How's about Collections.getSafe(...) for Map, which wouldn't return null?
- Next message: How's about Collections.getSafe(...) for Map, which wouldn't return null?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 collection. Map<Object, List> map = ... List collection = map.get(key); if (collection == null) { collection = new LinkedList(); map.put(key, collection); } collection.add(value); Paul
Paul, you need closures for that one.
Rémi
- Previous message: How's about Collections.getSafe(...) for Map, which wouldn't return null?
- Next message: How's about Collections.getSafe(...) for Map, which wouldn't return null?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]