maidh91 / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

A function based map decorator should be implemented #325

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
One of my favourites from commons-collections is sorely lacking from google 
collections: the ability to decorate an underlying map with a function to 
be able to guarantee a not null return for map.get().

LazyMap.get(Object key) is described as follows:

    public Object get(Object key) {
        // create value for key if key is not currently in the map
        if (map.containsKey(key) == false) {
            Object value = factory.transform(key);
            map.put(key, value);
            return value;
        }
        return map.get(key);
    }

This would be utterly awesome to be able to do in google-collections (in a 
type safe way!)

Note that this is not necessarily a case for multimaps - the lazy map can 
be used for any grouped function - summary operations etc; e.g. not just 
the obvious lazymap.get(myKey).add(anotherValue)

Original issue reported on code.google.com by stephen....@gmail.com on 8 Feb 2010 at 1:21

GoogleCodeExporter commented 9 years ago
Why isn't the computing map enough for yor needs?

http://guava-
libraries.googlecode.com/svn/trunk/javadoc/com/google/common/collect/MapMaker.ht
ml#make
ComputingMap(com.google.common.base.Function)

Original comment by andre...@gmail.com on 8 Feb 2010 at 2:55

GoogleCodeExporter commented 9 years ago
Because there's no canonical way to find this information?

http://stackoverflow.com/questions/2224275/wheres-google-collections-lazymap

Original comment by stephen....@gmail.com on 8 Feb 2010 at 7:34

GoogleCodeExporter commented 9 years ago
Thank you for updating that!
One of the things I love about SO is that the more we use it, the more it 
automatically "becomes" our FAQ, without extra separate labor required.

Original comment by kevinb@google.com on 8 Feb 2010 at 8:25

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:10