You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Carsten Ziegeler <cz...@apache.org> on 2007/10/01 15:06:11 UTC

Re: Avoiding Enumerations

Felix Meschberger wrote:
> java.util.Enumeration is only used in Servlet API environment situations
> (because the Servlet API declares them). Otherwise I try to use
> java.lang.Iterator. I know, this is nit-picking :-)
:)

> 
>> don't like returning enumerations as this makes reusing the returned
>> object difficult and you can't just query how many objects are in the
>> enumeration etc.
>>
>> So I think we sould either return collections or typed arrays. Between
>> these I have no real preference.
> 
> Depends on the use case. If the intended use is mainly enumeration of
> the data, then Iterator is probably ok. It is also easier to prevent
> modification of the collection itself. Otherwise we would probably have
> create copies...
Hmm, yes, it depends on the use case - I think we have some use cases
where we create arrays first and then return an enumeration.

> 
> Additionally, the return type might also stipulate potential
> implementations: Iterator allows for a lazy implementation, whereas
> Collection or Array always require full data sets. We had on use case
> once, where we declared a Set to be returned, which required a complete
> scan of a big data set, whereas having defined it as Iterator would have
> allowed for much faster iterative implementation.
Good point.

> 
> So, I think, there is no global answer to this question ... But each
> case should be identified and discussed.
Yes, you're right - I think I'll wait for our refactorings discussed
recently in the other threads and then see what is left over :)

Carsten

-- 
Carsten Ziegeler
cziegeler@apache.org