dnrajugade / guava-libraries

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

Addition of a TreeBiMap<K,V> class #1195

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I recently ran into an issue where I needed to sort a BiMap. Ideally I would 
have used a TreeMap, but I required the ability to invert the map.

I noticed a TreeMultimap<K,V> exists, and was wondering is something similar 
could be done for the BiMap to create a TreeBiMap<K,V>.

Current workaround: ImmutableBiMap.copyOf(Maps.newTreeMap(map))
as given by Louis Wasserman on Stack Overflow:    
http://stackoverflow.com/questions/13236927/sorting-a-guava-bimap 
(Thanks Louis!)

Original issue reported on code.google.com by cody.sch...@gmail.com on 6 Nov 2012 at 10:29

GoogleCodeExporter commented 9 years ago
The real question is whether it should be sorted in both directions, how that 
sorting should work...or what.

One possible alternative is a Maps.newBiMap(Map, Map), which would allow for 
custom BiMaps -- but the semantics of the ordering wouldn't be 100% clear here, 
either.

Original comment by lowas...@google.com on 7 Nov 2012 at 5:05

GoogleCodeExporter commented 9 years ago
Presumably in that custom case with Maps.newBiMap(treeMap1, treeMap2) the 
ordering of keys and of values would be independent. Iterating through keySet() 
or values() gives you the first ordering, iterating through reverse().keySet() 
or reverse().values() gives you the second.

Difficulties may arise if the two maps have inconsistent notions of equality 
etc.

Original comment by joe.j.kearney on 7 Nov 2012 at 6:02

GoogleCodeExporter commented 9 years ago
Merging this discussion with the general case of Maps.newBiMap(Map, Map).

Original comment by lowas...@google.com on 7 Nov 2012 at 8:21

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

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08