• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bidirectional Maps?

 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a number of situations that call for a mapping between two types, but in every case the mapping goes both ways. It would be nice if there was such a thing as a bidirectional map, but as far as I can see if I want to reverse the direction of the mapping, I need to create another map object. Is that really the way it is?
 
Campbell Ritchie
Sheriff
Pie
Posts: 49841
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First place to look for anything strange like that is Jakarta Commons. I presume you would have to go from the data representing a function to data representing an injective function.
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:First place to look for anything strange like that is Jakarta Commons. I presume you would have to go from the data representing a function to data representing an injective function.


Thanks for the tip, I didn't know about that Jakarta stuff. Anyways, I take your answer a yes. All maps that are part of the java Collections group are one way maps. Hmm, it seems like such a small but useful thing to add, but i guess not.

regards.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49841
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you hover your mouse over the link you find it is indeed a yes. Sun try their hardest and do provide lots of stuff, but there are lots of people who see holes in the provision and (more power to their elbow!) try to fill them. Remember Jakarta Commons is a good place to look for anything peculiar.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15452
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another good extra collections library is Google Collections. It also has a bi-directional map.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic