Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A function based map decorator should be implemented #325

Closed
gissuebot opened this issue Oct 31, 2014 · 3 comments
Closed

A function based map decorator should be implemented #325

gissuebot opened this issue Oct 31, 2014 · 3 comments

Comments

@gissuebot
Copy link

Original issue created by stephen.kestle on 2010-02-08 at 01:21 AM


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)

@gissuebot
Copy link
Author

Original comment posted by andresrc on 2010-02-08 at 02:55 PM


Why isn't the computing map enough for yor needs?

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

@gissuebot
Copy link
Author

Original comment posted by stephen.kestle on 2010-02-08 at 07:34 PM


Because there's no canonical way to find this information?

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

@gissuebot
Copy link
Author

Original comment posted by kevinb@google.com on 2010-02-08 at 08:25 PM


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.


Status: Invalid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant