commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <james_strac...@yahoo.co.uk>
Subject Re: [PATCH][Collections] Add empty iterator to CollectionUtils
Date Thu, 22 Nov 2001 08:42:45 GMT
Just a thought. How about doing this...

public class CollectionUtils {

    public static final Iterator EMPTY_ITERATOR
        = Collections.EMPTY_LIST.iterator();

...
}

As the implementation of EmptyList in Collections already contains an
implementation of an EmptyIterator. Though for some reason
EMPTY_LIST.iterator() creates a new instance each time.

James
----- Original Message -----
From: "Christopher Elkins" <chrise@scardini.com>
To: "Jakarta Commons Developers List" <commons-dev@jakarta.apache.org>
Sent: Thursday, November 22, 2001 6:14 AM
Subject: Re: [PATCH][Collections] Add empty iterator to CollectionUtils


> On Wed, Nov 21, 2001 at 11:58:07PM -0500, bayard@generationjava.com wrote:
> >
> > What's your view on making the EmptyIterator class a proper public
class.
> > Is there a strong reason for deciding that all EmptyIterators must be
> > the same instance?
> >
> > It's probably just a style thing, but I wanted to check.
>
> There are a few reasons:
>   - It parallels the set theory notion that all empty sets are really the
>     same empty set.
>   - It parallels Collections.EMPTY_[LIST|MAP|SET].
>   - Because it's immutable it's perfectly valid to return the same
instance.
>     (It also offers a minimal performance gain.)
>
> Ultimately I guess it is a matter of style. Indeed, my local
implementation
> is a proper class; I took the opportunity of contributing it to the
Commons
> as an excuse for implementing it the right way (where "right" is justified
> using the above reasons). :-)
>
> --
> Christopher Elkins
>
> --
> To unsubscribe, e-mail:
<mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:commons-dev-help@jakarta.apache.org>


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message