I was thinking that the inverseBidiMap() would just return a reference to an inner class which is held inside of the BidiMap implementation.

That way there may not have to be another object created. I'm not sure if this is practical or not.

It all depends on whether we want to be able to call the shortcuts:
        get(value)
        remove(value)

instead of:
        inverseBidiMap().get(value)
        inverseBidiMap().remove(value)

Since BidiMap is an interface, I would suggest against creating the shortcut methods, since it forces all implementations to write them. If we have an abstract implemenation which takes care of it then it's not such a hassle.

I think the shortcuts are convenient, but not necessary, it just depends on where you want to draw the line. I'd be happy to help out either way.




Stephen Colebourne wrote:
I had an inverseBidiMap() to cover the valueMap() case. However I reckon
that since the whole reason for the class is to allow the reverse lookup,
its not unreasonable to be able to access it directly. Having to go via an
inverseBidiMap() method means creating another object, which is quite a
large overhead for these operations (well the get at least).

Maybe we should have just
inverseBidiMap()
getKey(value)
removeKey(value)

The rest could go via the inverse. Maybe.
Stephen

----- Original Message -----
From: "__matthewHawthorne" <[EMAIL PROTECTED]>
To: "Jakarta Commons Developers List" <[EMAIL PROTECTED]>
Sent: Saturday, September 20, 2003 6:57 PM
Subject: Re: [collections] BidiMap / DoubleOrderedMap



In BidiMap, instead of:


Object getKeyForValue(Object value)
Object removeValue(Object value)
Set entrySetByValue()
Set keySetByValue()
Collection valuesByValue()

What about just providing a single method which would return a Map with the keys/values reversed, such as:

Map valueMap()

It would remove the duplication of having to write all these XXXbyValue
methods.


Similarly, in SortedBidiMap, instead of:



subMapByValue()
headMapByValue()
tailMapByValue()

what about (I'm not exactly sure what the return type should be):


Map/SortedMap/BidiMap/SortedBidiMap valueMap()


I haven't looked at the existing code, but I suspect that this way would be easier to write, less lines of code, and more OO.

What do you think?




Stephen Colebourne wrote:


I have been prompted to take a look at DoubleOrderedMap by bugzilla and

been


a little surprised by what I found. Given the history of collections,

what


we have is a single implementation brought in from an external project.
[collections] should do better :-)

A bidirectional map is a relatively standard concept in computing. It is

a


map where you can use a key to find a value, or a value to find a key

with


equal ease. This deserves its own interface in [collections] - BidiMap.

The DoubleOrderedMap class goes beyond this by being Sorted, effectively
holding all entries in a Compared order always. This effectively equates

to


a second interface in [collections] - SortedBidiMap.

BidiMap
----------
Map methods +
BidiMap inverseBidiMap()
Object getKeyForValue(Object value)
Object removeValue(Object value)
Set entrySetByValue()
Set keySetByValue()
Collection valuesByValue()
(these method names are from DoubleOrderedMap, and seem OKish)

SortedBidiMap
----------------
BidiMap + SortedMap +
inverseSortedBidiMap()
subMapByValue()
headMapByValue()
tailMapByValue()

The existing DoubleOrderedMap is an implementation of SortedBidiMap.

However


I would like to rename it to TreeBidiMap.

An alternative implementation of BidiMap would then be needed, which

would


be useful as it would not require objects to be comparable.

With these new interfaces, decorators could then be written as required.

Anything obvious I've missed? Any volunteers?

Stephen



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to