Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where's google-collection's LazyMap?

One of my favourites from apache commons-collections was the LazyMap which would use a Transformer to instantiate values on the fly when doing map.get(newKey); // Will not return null!.

Why doesn't google collections have the same?

like image 714
Stephen Avatar asked Feb 08 '10 19:02

Stephen


2 Answers

Hey look! It does!

It's called new MapMaker().makeComputingMap(Function<? super K, ? extends V> computer)

Awesome.

Note that map maker is a factory - you can make one, set all the object reference types, expansion properties (and even object expiration time!), and then go about creating lots of computing maps (or other types) with one line calls.

e.g. like pretty much everything else about the google-collections library, it's really good - once you've figured out where 'it' is

like image 82
Stephen Avatar answered Nov 01 '22 11:11

Stephen


since 10.0, guava have a new class CacheBuilder instead, and it's gwt-compatible.

These are the differences.

like image 20
turtledove Avatar answered Nov 01 '22 11:11

turtledove