Hope, Matthew wrote:
-----Original Message----- From: Phil Steitz [mailto:[EMAIL PROTECTED] Sent: 21 September 2003 19:10 To: Jakarta Commons Developers List Subject: Re: [collections] CollectionUtils.index() behavior
OK, I will leave as is, but I personally see this as bad design -- maps are not ordered
Not so - Maps do not *guarantee order* but implementations are free to do so
(and for an OrderedMap implementation must do so)
The problem is that the method is defined for *any* Map and *any* Collection as well, effectively adding structure where it is not guaranteed to exist. That's what was bothering me, but I am over it now ;-)
Certainly the addition of a unit test on an ordered map would be a good idea
as well...
+1
Grr. Just discovered another wonderful "feature" when implementing a test for this. Since the algorithm for index(map, i) first tries to find Integer(i) as a key in the map, if you use a TreeMap to test, this throws a ClassCastException unless the keys in the map are Integers.
I guess this is more or less implied by the javadoc, which describes the algorithm, but I am thinking now that it might be better to catch the ClassCastException (or maybe even Exception) in the first attempted lookup and let it drop through to the iterator. This would make the method usable for Sorted Maps with non-integer keys. Any objections to this change?
Phil
Matt
**************************************************************************
The information transmitted herewith is sensitive information intended only
for use by the individual or entity to which it is addressed. If the reader
of this message is not the intended recipient, you are hereby notified that
any review, retransmission, dissemination, distribution, copying or other
use of, or taking of any action in reliance upon this information is
strictly prohibited. If you have received this communication in error,
please contact the sender and delete the material from your computer.
--------------------------------------------------------------------- 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]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
