wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Bidirectional Maps? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Bidirectional Maps?" Watch "Bidirectional Maps?" New topic
Author

Bidirectional Maps?

Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
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

Joined: Oct 13, 2005
Posts: 38025
    
  22
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

Joined: May 13, 2009
Posts: 679
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

Joined: Oct 13, 2005
Posts: 38025
    
  22
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

Joined: Aug 16, 2005
Posts: 14074
    
  16

Another good extra collections library is Google Collections. It also has a bi-directional map.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bidirectional Maps?
 
Similar Threads
help me with mapping
Bidirection join broken in one direction?
Problem with one-to-one mapping using discriminator
One-to-many relationship is updating entire child table with new parent id
bidirectional many-to-many association mapping Vs ternary association mapping ?