Here, there is an example about HashBiMultimap along with the guava-12.0-SNAPSHOT.jar I have compiled from a version of guava.
To understand what is a HashBiMultimap data structure see
https://code.google.com/p/guava-libraries/wiki/NewCollectionTypesExplained#BiMap
import com.google.common.collect.HashBiMultimap;
public class Test {
public static void main(String[] args) {
HashBiMultimap<Object, Object> t = HashBiMultimap.create();
t.put("country", "peru");
t.put("country", "bolivia");
t.put("city", "lima");
t.put("city", "la paz");
t.put("city", "huanuco");
t.put("region", "peru");
System.out.println(t.inverse().get("peru"));
}
}
public class Test {
public static void main(String[] args) {
HashBiMultimap<Object, Object> t = HashBiMultimap.create();
t.put("country", "peru");
t.put("country", "bolivia");
t.put("city", "lima");
t.put("city", "la paz");
t.put("city", "huanuco");
t.put("region", "peru");
System.out.println(t.inverse().get("peru"));
}
}
The output would be
[region, country]
Links
https://code.google.com/p/guava-libraries/source/browse/guava/src/com/google/common/collect/HashBiMultimap.java?r=637b57166d09a457eb377ca2bfbd436c4870dff4
http://stackoverflow.com/questions/8066109/bidirectional-multi-valued-map-in-java
Attachment | Size |
---|---|
![]() | 1.72 MB |
![]() | 1.9 MB |