commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz" <p...@steitz.com>
Subject Re: [collections] CollectionUtils.index() behavior
Date Sun, 21 Sep 2003 18:09:44 GMT
Stephen Colebourne wrote:
> Although I agree that the definition of using the Iterator is potentially
> dangerous, it often works as iterators generally are consistent.
> 
> This method is one of the originals from this class, and is documented as to
> what it does, so I'm -1 to changing it.

OK, I will leave as is, but I personally see this as bad design -- maps 
are not ordered and what this method does is essentially add a method 
not supported by the data structure.  Test cases look a bit silly (all 
you can test if that index(map, index) returns an entry from the map) 
and the doc needs to be improved a bit to explain exactly what happens 
with maps. Specifically:

1. index(map,index) behaves differently if map contains an Integer key 
with value = index (in which case it returns the corresponding value) 
vs. when there is no Integer key with value = index, in which case the 
indexth *key* is returned.

2. if index(map, index) does not exist, what is returned is an iterator 
over the *keyset* (not the values)) rather than the map.

I will try to clarify the docs (without making things too complicated) 
and add test cases to confirm.

Phil
> 
> Stephen
> 
> ----- Original Message -----
> From: "Phil Steitz" <phil@steitz.com>
> 
>>Currently, if obj is a Map or a Collection (but not a List) and index is
>>an Integer,  CollectionUtils.index(obj,index) will return the index-th
>>object returned by an iterator over the map/collection. Since there is
>>no guaranteed order in these cases, it does not make sense to me for
>>index() to be defined in these cases.
>>
>>Should this be changed to either follow the "default" path (returning
>>obj) or to throw an IllegalArgumentException?
>>
>>Phil
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 




Mime
View raw message