File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 40064
    
  28
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: 40064
    
  28
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: 14435
    
  23

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 8 API documentation
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bidirectional Maps?