ACMNexus / google-collections

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

Maps.index #186

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
It's the same as Multimaps.index - except that is will return a
ImmutableMap<K, V>.

Yes, this could mean that an entry is overwritten if two iterable values
return the same key - but that's what is needed if you want to index a
collection using a primary key for example.

Original issue reported on code.google.com by zeitlin...@gmail.com on 10 Jun 2009 at 7:40

GoogleCodeExporter commented 8 years ago
This is named Maps.uniqueIndex().  Enjoy!

http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/col
lect/Maps.html#uniqueIndex(java.lang.Iterable,%20com.google.common.base.Function
)

Original comment by kevin...@gmail.com on 10 Jun 2009 at 3:45

GoogleCodeExporter commented 8 years ago
Related: I frequently miss functionality to create maps from iterables. It's 
specifically annoying when I already have an iterable of immutable entry or 
pair-like 
objects, and you could simply reuse those. But ok, there are issues with that.
An innocent solution might be to have an index method taking an iterable and 
both a 
key and value function.

Map<K,V> index(Iterable<T> source, Function<T,K> keyFunction, Function<T,V> 
valueFunction)

Original comment by jvdne...@gmail.com on 11 Jun 2009 at 7:11