commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz" <>
Subject Re: [collections] Last call before release 3.0
Date Thu, 04 Sep 2003 17:43:04 GMT
Rodney Waldhoff wrote:
> On Wed, 3 Sep 2003, Phil Steitz wrote:
>>Here is one code change that I would recommend:
>>Currently, CollectionUtils.isProperSubCollection(a,b) returns
>>CollectionUtils.isSubCollection(a,b) &&
>>This is very inefficient, since it is equivalent to
>>(a.size() < b.size()) && CollectionUtils.isSubCollection(a,b);
>>There are currently no tests for this method, but the latter works for
>>the ones that I have coded.
> The latter approach assumes that the size() function returns the total
> number of elements in the collection (i.e., the "length" of the Iterator
> returned by collection.iterator()), whereas the former approach does not.
> For example, a Bag-ish implementation that returns the number of distinct
> elements for size(), but the duplicate elements in the iterator, would
> break the latter implementation.
> This assumption (that size() will return the number elements available in
> iterator()) is probably quite reasonable, and the latter implementation
> will be much more efficient when isProperSubCollection is going to return
> true, so I'd say go for it.  (Though we may want to document the
> assumption.)

I will document the assumption, which is consistent with the Collection 
interface specification

> Also, the latter approach doesn't quite work for extremely large
> collections.  For example, if both a and b contain more than
> Integer.MAX_VALUE elements, this method may fail (since size() will still
> return Integer.MAX_VALUE in that case).  This is probably more of an
> academic concern than an practical one, but again, may be a reasonable
> limitation to note.

I will also document this, which I agree is a real limitation. Are we 
all OK with this? Anyone other problems with this change?


> - Rod <>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message