maidh91 / guava-libraries

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

Allow to create a Map or Multimap from a collection and Function #388

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It would be usefull to create a Map or Multimap from a collection and a 
function that retrieves the key from the objects contained in the collection.

For example: given the the Person Object: 

public class Person {

...

  public String getName() {
    return name;
  }

...

}

And a Collection<Person> I want to build a Map<String, Person> using something 
like:

Map<String, Person> myMap = Maps.create(collection, new Function<Person, 
String>() {
  public String apply(Person p) {
    return p.getName();
  }
);

Thanks in advance,
Martín

Original issue reported on code.google.com by martin.bigio@gmail.com on 28 Jul 2010 at 2:18

GoogleCodeExporter commented 9 years ago
These already exist. They're called Maps.uniqueIndex(Iterable,Function) and 
Multimaps.index(Iterable,Function).

Original comment by cgdec...@gmail.com on 28 Jul 2010 at 2:56

GoogleCodeExporter commented 9 years ago
Thanks cgdecker.

Original comment by kevinb@google.com on 28 Jul 2010 at 3:59

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:09