You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Stephen Colebourne <sc...@btopenworld.com> on 2002/11/01 10:01:54 UTC

Re: [collections] LoopingIterator

From: "Jonathan Carlson" <jo...@yahoo.com>
> I can add a remove method and test cases unless it's easier
> for you to just add it.  I think it would just use the
> remove method on the Collection.  If the iterator returned
> by the Collection implementer doesn't support it then this
> won't either.

If you could submit the revised code and test case, I think that I'm willing
to commit it to collections.

Stephen


> As for a use-case, I am using it for a displaying a number
> of our banner ads on our e-commerce site.  The round-robin
> task dispatcher mentioned earlier is another one.
>
> Jonathan Carlson
>
>
>
> --- Stephen Colebourne <sc...@joda.org> wrote:
> > [Jonathan, I have sent back to commons-dev mailing list
> > which is the
> > appropriate place for design/code discussions.]
> >
> > I took a quick look, and I believe that the code in the
> > zip will work.
> > However, my main concern is why this would be needed. Is
> > there a use case
> > for an iterator that never ends?
> >
> > I would also like to see the remove method implemented.
> > It should be
> > possible.
> >
> > Stephen
> >
> > ----- Original Message -----
> > From: "Jonathan Carlson" <jo...@yahoo.com>
> > To: <sc...@joda.org>
> > Sent: Friday, October 18, 2002 3:53 PM
> > Subject: LoopingIterator
> >
> >
> > > Hi Stephen,
> > >
> > > Thanks for your work on the IteratorUtils.  I thought
> > this
> > > might be a good addition if it hasn't been added
> > already.
> > > It's an iterator that loops continually.
> > Unfortunately, it
> > > can't just decorate another iterator but has to wrap a
> > > collection due to the fact that iterators cannot be
> > reset
> > > to the beginning of the collection.
> > >
> > > Included is a jUnit test case that shows it works "as
> > > advertised".  Hope this helps.
> > >
> > > Jonathan Carlson
> > > Minneapolis, Minnesota
> > >
> > >
> > > =====
> > > Jonathan Carlson
> > > joncrlsn@users.sf.net
> > > Minneapolis, Minnesota
> > >
> > > __________________________________________________
> > > Do you Yahoo!?
> > > Faith Hill - Exclusive Performances, Videos & More
> > > http://faith.yahoo.com
> >
>
> > ATTACHMENT part 2 application/x-zip-compressed
> name=LoopingIterator.zip
>
>
>
> =====
> Jonathan Carlson
> joncrlsn@users.sf.net
> Minneapolis, Minnesota
>
> __________________________________________________
> Do you Yahoo!?
> HotJobs - Search new jobs daily now
> http://hotjobs.yahoo.com/
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [collections] LoopingIterator

Posted by Stephen Colebourne <sc...@btopenworld.com>.
LoopingItertaor committed with some alterations:
- fixed remove method to handle removing all the elements
- added reset method
- added size method
- javadoc/style etc.
Thanks Jonathan for the code.


I also added TODOs for the missing iterators
- Looping ListIterator
- Array ListIterator

Stephen

----- Original Message -----
From: "Jeff Varszegi" <jv...@yahoo.com>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>;
<jo...@users.sf.net>
Sent: Thursday, November 21, 2002 10:38 PM
Subject: Re: [collections] LoopingIterator


> I agree with you about the protection.  It can be a snapshot view of a
particular collection that
> can be used forever.  The looping ability is the value, not the fail-fast
behaviour, in my book.
> My point was that I was saying it would've been nice to have the thing
fail fast, but it's not as
> important as the looping quality, especially if it's hard to provide!  I
was supporting you.
>
> Can you send me the code?  I think I may've joined the list right after
you posted it.  You may
> want to provide a refresh() method that reinitializes a LoopingIterator
with the contents of an
> array/collection (especially with a saved reference to its parent
collection)-- I could see myself
> using it.  I definitely don't think it should be an inner class of
anything; I wanna be able to
> drop it into a project without using anything else from Collections (for
instance, if I'm
> space-constrained on a project).  I can think of plenty of uses for this
thing in a wireless app,
> for instance.
>
>
> Regards,
>
> Jeff
>
> --- Jonathan Carlson <jo...@yahoo.com> wrote:
> > This was my take on it:
> >
> > Since it uses the iterator provided by the collection, I
> > felt it would be wasteful to try to provide any greater
> > protection than that already provided by the collection's
> > own iterator (other than the stated benefit of allowing one
> > to continually loop over the collection).
> >
> > That seems so reasonable to me that I'm almost afraid I
> > might be missing your point.  If I am, please let me know.
> >
> > Also, I can put the proper license text on it, but I didn't
> > do it originally because I thought it would most likely be
> > an inner class of IteratorUtils or CollectionUtils.
> >
> > Let me know what you want me to do.
> >
> > Thanks!
> >
> > Jonathan
> >
> >
> >
> > --- Jeff Varszegi <jv...@yahoo.com> wrote:
> > > I don't see how to implement this without being horribly
> > > wasteful (checking every value in the
> > > collection backing the Iterator every time something is
> > > returned, getting a new Iterator every
> > > time through the loop, etc.).  The thing is, you can't
> > > even depend on the implementation of
> > > hashCode() when you're dealing with generic collections,
> > > the use of which would be wasteful
> > > anyway.  Jonathan, did you find a solution to this
> > > problem?
> > >
> > > I was going to implement a RandomIterator, but didn't
> > > figure a way around the concurrent-mod
> > > problem for an externally created Iterator.  I think for
> > > situations like this it's acceptable to
> > > just notify users of the class that there are no
> > > guarantees in the face of concurrent
> > > modification.  It's a shame that Sun didn't include a
> > > mod-check hook in the Collection interface,
> > > or even the chance to use Observer, at least as
> > > optionally supported.  I mean, I can understand
> > > the absence of observers, because checking for them would
> > > slow things down a little bit, but every
> > > single collection I've seen that came outta Sun keeps an
> > > incremental count of changes to itself.
> > >
> > > Jeff
> > >
> > > --- Stephen Colebourne <sc...@btopenworld.com>
> > > wrote:
> > > > Jonathan,
> > > > I was going to include your files in the CVS. However,
> > > I discovered that
> > > > they do not cope with the situation where the
> > > collection being wrapped is
> > > > altered. ie. hasNext() always returns the initially
> > > cached value, even if
> > > > the list is clear()ed or it.remove() is called. Can you
> > > sort this?
> > > >
> > > > Also, if resubmitting could you place the code in the
> > > correct package and
> > > > with an Apache licence (from another collections file)
> > > to confirm that this
> > > > is an official donation of code :-)
> > > >
> > > > Thanks
> > > > Stephen
> > > >
> > > > ----- Original Message -----
> > > > From: "Jonathan Carlson" <jo...@yahoo.com>
> > > > > It is attached with updated unit tests.  It was so
> > > easy
> > > > > that I'm surprised I didn't implement the remove() in
> > > the
> > > > > first place.
> > > > >
> > > > > Thanks!
> > > > >
> > > > > Jonathan Carlson
> > > > > Minneapolis, Minnesota
> > > > >
> > > > >
> > > > > --- Stephen Colebourne <sc...@btopenworld.com>
> > > wrote:
> > > > > > From: "Jonathan Carlson" <jo...@yahoo.com>
> > > > > > > I can add a remove method and test cases unless
> > > it's
> > > > > > easier
> > > > > > > for you to just add it.  I think it would just
> > > use the
> > > > > > > remove method on the Collection.  If the iterator
> > > > > > returned
> > > > > > > by the Collection implementer doesn't support it
> > > then
> > > > > > this
> > > > > > > won't either.
> > > > > >
> > > > > > If you could submit the revised code and test case,
> > > I
> > > > > > think that I'm willing
> > > > > > to commit it to collections.
> > > > > >
> > > > > > Stephen
> > > > > >
> > > > > >
> > > > > > > As for a use-case, I am using it for a displaying
> > > a
> > > > > > number
> > > > > > > of our banner ads on our e-commerce site.  The
> > > > > > round-robin
> > > > > > > task dispatcher mentioned earlier is another one.
> > > > > > >
> > > > > > > Jonathan Carlson
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --- Stephen Colebourne <sc...@joda.org>
> > > wrote:
> > > > > > > > [Jonathan, I have sent back to commons-dev
> > > mailing
> > > > > > list
> > > > > > > > which is the
> > > > > > > > appropriate place for design/code discussions.]
> > > > > > > >
> > > > > > > > I took a quick look, and I believe that the
> > > code in
> > > > > > the
> > > > > > > > zip will work.
> > > > > > > > However, my main concern is why this would be
> > > needed.
> > > > > > Is
> > > > > > > > there a use case
> > > > > > > > for an iterator that never ends?
> > > > > > > >
> > > > > > > > I would also like to see the remove method
> > > > > > implemented.
> > > > > > > > It should be
> > > > > > > > possible.
> > > > > > > >
> > > > > > > > Stephen
> > > > > > > >
> > > > > > > > ----- Original Message -----
> > > > > > > > From: "Jonathan Carlson" <jo...@yahoo.com>
> > > > > > > > To: <sc...@joda.org>
> > > > > > > > Sent: Friday, October 18, 2002 3:53 PM
> > > > > > > > Subject: LoopingIterator
> > > > > > > >
> > > > > > > >
> > > > > > > > > Hi Stephen,
> > > > > > > > >
> > > > > > > > > Thanks for your work on the IteratorUtils.  I
> > > > > > thought
> > > > > > > > this
> > > > > > > > > might be a good addition if it hasn't been
> > > added
> > > > > > > > already.
> > > > > > > > > It's an iterator that loops continually.
> > > > > > > > Unfortunately, it
> > > > > > > > > can't just decorate another iterator but has
> > > to
> > > > > > wrap a
> > > > > > > > > collection due to the fact that iterators
> > > cannot be
> > > > > > > > reset
> > > > > > > > > to the beginning of the collection.
> > > > > > > > >
> > > > > > > > > Included is a jUnit test case that shows it
> > > works
> > > > > > "as
> > > > > > > > > advertised".  Hope this helps.
> > > > > > > > >
> > > > > > > > > Jonathan Carlson
> > > > > > > > > Minneapolis, Minnesota
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > =====
> > > > > > > > > Jonathan Carlson
> > > > > > > > > joncrlsn@users.sf.net
> > > > > > > > > Minneapolis, Minnesota
> > > > > > > > >
> > > > > > > > >
> > > __________________________________________________
> > > > > > > > > Do you Yahoo!?
> > > > > > > > > Faith Hill - Exclusive Performances, Videos &
> > > More
> > > > > > > > > http://faith.yahoo.com
> > > > > > > >
> > > > > > >
> > > > > > > > ATTACHMENT part 2 application/x-zip-compressed
> > > > > > > name=LoopingIterator.zip
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > =====
> > > > > > > Jonathan Carlson
> > > > > > > joncrlsn@users.sf.net
> > > > > > > Minneapolis, Minnesota
> > > > > > >
> > > > > > >
> > > __________________________________________________
> > > > > > > Do you Yahoo!?
> > > > > > > HotJobs - Search new jobs daily now
> > > > > > > http://hotjobs.yahoo.com/
> > > > > > >
> > > > > > > --
> > > > > > > To unsubscribe, e-mail:
> > > > > > <ma...@jakarta.apache.org>
> > > > > > > For additional commands, e-mail:
> > > > > > <ma...@jakarta.apache.org>
> > > > > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > > =====
> > > > > Jonathan Carlson
> > > > > joncrlsn@users.sf.net
> > > > > Minneapolis, Minnesota
> > > > >
> > > > > __________________________________________________
> > >
> > === message truncated ===
> >
> >
> > =====
> > Jonathan Carlson
> > joncrlsn@users.sf.net
> > Minneapolis, Minnesota
> >
> > __________________________________________________
> > Do you Yahoo!?
> > Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> > http://mailplus.yahoo.com
> >
> > --
> > To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> > For additional commands, e-mail:
<ma...@jakarta.apache.org>
> >
>
>
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [collections] LoopingIterator

Posted by Jeff Varszegi <jv...@yahoo.com>.
I agree with you about the protection.  It can be a snapshot view of a particular collection that
can be used forever.  The looping ability is the value, not the fail-fast behaviour, in my book. 
My point was that I was saying it would've been nice to have the thing fail fast, but it's not as
important as the looping quality, especially if it's hard to provide!  I was supporting you.

Can you send me the code?  I think I may've joined the list right after you posted it.  You may
want to provide a refresh() method that reinitializes a LoopingIterator with the contents of an
array/collection (especially with a saved reference to its parent collection)-- I could see myself
using it.  I definitely don't think it should be an inner class of anything; I wanna be able to
drop it into a project without using anything else from Collections (for instance, if I'm
space-constrained on a project).  I can think of plenty of uses for this thing in a wireless app,
for instance.


Regards,

Jeff

--- Jonathan Carlson <jo...@yahoo.com> wrote:
> This was my take on it:
> 
> Since it uses the iterator provided by the collection, I
> felt it would be wasteful to try to provide any greater
> protection than that already provided by the collection's
> own iterator (other than the stated benefit of allowing one
> to continually loop over the collection).
> 
> That seems so reasonable to me that I'm almost afraid I
> might be missing your point.  If I am, please let me know.
> 
> Also, I can put the proper license text on it, but I didn't
> do it originally because I thought it would most likely be
> an inner class of IteratorUtils or CollectionUtils.
> 
> Let me know what you want me to do.
> 
> Thanks!
> 
> Jonathan
> 
> 
> 
> --- Jeff Varszegi <jv...@yahoo.com> wrote:
> > I don't see how to implement this without being horribly
> > wasteful (checking every value in the
> > collection backing the Iterator every time something is
> > returned, getting a new Iterator every
> > time through the loop, etc.).  The thing is, you can't
> > even depend on the implementation of
> > hashCode() when you're dealing with generic collections,
> > the use of which would be wasteful
> > anyway.  Jonathan, did you find a solution to this
> > problem?
> > 
> > I was going to implement a RandomIterator, but didn't
> > figure a way around the concurrent-mod
> > problem for an externally created Iterator.  I think for
> > situations like this it's acceptable to
> > just notify users of the class that there are no
> > guarantees in the face of concurrent
> > modification.  It's a shame that Sun didn't include a
> > mod-check hook in the Collection interface,
> > or even the chance to use Observer, at least as
> > optionally supported.  I mean, I can understand
> > the absence of observers, because checking for them would
> > slow things down a little bit, but every
> > single collection I've seen that came outta Sun keeps an
> > incremental count of changes to itself.
> > 
> > Jeff
> > 
> > --- Stephen Colebourne <sc...@btopenworld.com>
> > wrote:
> > > Jonathan,
> > > I was going to include your files in the CVS. However,
> > I discovered that
> > > they do not cope with the situation where the
> > collection being wrapped is
> > > altered. ie. hasNext() always returns the initially
> > cached value, even if
> > > the list is clear()ed or it.remove() is called. Can you
> > sort this?
> > > 
> > > Also, if resubmitting could you place the code in the
> > correct package and
> > > with an Apache licence (from another collections file)
> > to confirm that this
> > > is an official donation of code :-)
> > > 
> > > Thanks
> > > Stephen
> > > 
> > > ----- Original Message -----
> > > From: "Jonathan Carlson" <jo...@yahoo.com>
> > > > It is attached with updated unit tests.  It was so
> > easy
> > > > that I'm surprised I didn't implement the remove() in
> > the
> > > > first place.
> > > >
> > > > Thanks!
> > > >
> > > > Jonathan Carlson
> > > > Minneapolis, Minnesota
> > > >
> > > >
> > > > --- Stephen Colebourne <sc...@btopenworld.com>
> > wrote:
> > > > > From: "Jonathan Carlson" <jo...@yahoo.com>
> > > > > > I can add a remove method and test cases unless
> > it's
> > > > > easier
> > > > > > for you to just add it.  I think it would just
> > use the
> > > > > > remove method on the Collection.  If the iterator
> > > > > returned
> > > > > > by the Collection implementer doesn't support it
> > then
> > > > > this
> > > > > > won't either.
> > > > >
> > > > > If you could submit the revised code and test case,
> > I
> > > > > think that I'm willing
> > > > > to commit it to collections.
> > > > >
> > > > > Stephen
> > > > >
> > > > >
> > > > > > As for a use-case, I am using it for a displaying
> > a
> > > > > number
> > > > > > of our banner ads on our e-commerce site.  The
> > > > > round-robin
> > > > > > task dispatcher mentioned earlier is another one.
> > > > > >
> > > > > > Jonathan Carlson
> > > > > >
> > > > > >
> > > > > >
> > > > > > --- Stephen Colebourne <sc...@joda.org>
> > wrote:
> > > > > > > [Jonathan, I have sent back to commons-dev
> > mailing
> > > > > list
> > > > > > > which is the
> > > > > > > appropriate place for design/code discussions.]
> > > > > > >
> > > > > > > I took a quick look, and I believe that the
> > code in
> > > > > the
> > > > > > > zip will work.
> > > > > > > However, my main concern is why this would be
> > needed.
> > > > > Is
> > > > > > > there a use case
> > > > > > > for an iterator that never ends?
> > > > > > >
> > > > > > > I would also like to see the remove method
> > > > > implemented.
> > > > > > > It should be
> > > > > > > possible.
> > > > > > >
> > > > > > > Stephen
> > > > > > >
> > > > > > > ----- Original Message -----
> > > > > > > From: "Jonathan Carlson" <jo...@yahoo.com>
> > > > > > > To: <sc...@joda.org>
> > > > > > > Sent: Friday, October 18, 2002 3:53 PM
> > > > > > > Subject: LoopingIterator
> > > > > > >
> > > > > > >
> > > > > > > > Hi Stephen,
> > > > > > > >
> > > > > > > > Thanks for your work on the IteratorUtils.  I
> > > > > thought
> > > > > > > this
> > > > > > > > might be a good addition if it hasn't been
> > added
> > > > > > > already.
> > > > > > > > It's an iterator that loops continually.
> > > > > > > Unfortunately, it
> > > > > > > > can't just decorate another iterator but has
> > to
> > > > > wrap a
> > > > > > > > collection due to the fact that iterators
> > cannot be
> > > > > > > reset
> > > > > > > > to the beginning of the collection.
> > > > > > > >
> > > > > > > > Included is a jUnit test case that shows it
> > works
> > > > > "as
> > > > > > > > advertised".  Hope this helps.
> > > > > > > >
> > > > > > > > Jonathan Carlson
> > > > > > > > Minneapolis, Minnesota
> > > > > > > >
> > > > > > > >
> > > > > > > > =====
> > > > > > > > Jonathan Carlson
> > > > > > > > joncrlsn@users.sf.net
> > > > > > > > Minneapolis, Minnesota
> > > > > > > >
> > > > > > > >
> > __________________________________________________
> > > > > > > > Do you Yahoo!?
> > > > > > > > Faith Hill - Exclusive Performances, Videos &
> > More
> > > > > > > > http://faith.yahoo.com
> > > > > > >
> > > > > >
> > > > > > > ATTACHMENT part 2 application/x-zip-compressed
> > > > > > name=LoopingIterator.zip
> > > > > >
> > > > > >
> > > > > >
> > > > > > =====
> > > > > > Jonathan Carlson
> > > > > > joncrlsn@users.sf.net
> > > > > > Minneapolis, Minnesota
> > > > > >
> > > > > >
> > __________________________________________________
> > > > > > Do you Yahoo!?
> > > > > > HotJobs - Search new jobs daily now
> > > > > > http://hotjobs.yahoo.com/
> > > > > >
> > > > > > --
> > > > > > To unsubscribe, e-mail:
> > > > > <ma...@jakarta.apache.org>
> > > > > > For additional commands, e-mail:
> > > > > <ma...@jakarta.apache.org>
> > > > > >
> > > > >
> > > >
> > > >
> > > >
> > > > =====
> > > > Jonathan Carlson
> > > > joncrlsn@users.sf.net
> > > > Minneapolis, Minnesota
> > > >
> > > > __________________________________________________
> > 
> === message truncated ===
> 
> 
> =====
> Jonathan Carlson
> joncrlsn@users.sf.net
> Minneapolis, Minnesota
> 
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus � Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus � Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [collections] LoopingIterator

Posted by Jonathan Carlson <jo...@yahoo.com>.
This was my take on it:

Since it uses the iterator provided by the collection, I
felt it would be wasteful to try to provide any greater
protection than that already provided by the collection's
own iterator (other than the stated benefit of allowing one
to continually loop over the collection).

That seems so reasonable to me that I'm almost afraid I
might be missing your point.  If I am, please let me know.

Also, I can put the proper license text on it, but I didn't
do it originally because I thought it would most likely be
an inner class of IteratorUtils or CollectionUtils.

Let me know what you want me to do.

Thanks!

Jonathan



--- Jeff Varszegi <jv...@yahoo.com> wrote:
> I don't see how to implement this without being horribly
> wasteful (checking every value in the
> collection backing the Iterator every time something is
> returned, getting a new Iterator every
> time through the loop, etc.).  The thing is, you can't
> even depend on the implementation of
> hashCode() when you're dealing with generic collections,
> the use of which would be wasteful
> anyway.  Jonathan, did you find a solution to this
> problem?
> 
> I was going to implement a RandomIterator, but didn't
> figure a way around the concurrent-mod
> problem for an externally created Iterator.  I think for
> situations like this it's acceptable to
> just notify users of the class that there are no
> guarantees in the face of concurrent
> modification.  It's a shame that Sun didn't include a
> mod-check hook in the Collection interface,
> or even the chance to use Observer, at least as
> optionally supported.  I mean, I can understand
> the absence of observers, because checking for them would
> slow things down a little bit, but every
> single collection I've seen that came outta Sun keeps an
> incremental count of changes to itself.
> 
> Jeff
> 
> --- Stephen Colebourne <sc...@btopenworld.com>
> wrote:
> > Jonathan,
> > I was going to include your files in the CVS. However,
> I discovered that
> > they do not cope with the situation where the
> collection being wrapped is
> > altered. ie. hasNext() always returns the initially
> cached value, even if
> > the list is clear()ed or it.remove() is called. Can you
> sort this?
> > 
> > Also, if resubmitting could you place the code in the
> correct package and
> > with an Apache licence (from another collections file)
> to confirm that this
> > is an official donation of code :-)
> > 
> > Thanks
> > Stephen
> > 
> > ----- Original Message -----
> > From: "Jonathan Carlson" <jo...@yahoo.com>
> > > It is attached with updated unit tests.  It was so
> easy
> > > that I'm surprised I didn't implement the remove() in
> the
> > > first place.
> > >
> > > Thanks!
> > >
> > > Jonathan Carlson
> > > Minneapolis, Minnesota
> > >
> > >
> > > --- Stephen Colebourne <sc...@btopenworld.com>
> wrote:
> > > > From: "Jonathan Carlson" <jo...@yahoo.com>
> > > > > I can add a remove method and test cases unless
> it's
> > > > easier
> > > > > for you to just add it.  I think it would just
> use the
> > > > > remove method on the Collection.  If the iterator
> > > > returned
> > > > > by the Collection implementer doesn't support it
> then
> > > > this
> > > > > won't either.
> > > >
> > > > If you could submit the revised code and test case,
> I
> > > > think that I'm willing
> > > > to commit it to collections.
> > > >
> > > > Stephen
> > > >
> > > >
> > > > > As for a use-case, I am using it for a displaying
> a
> > > > number
> > > > > of our banner ads on our e-commerce site.  The
> > > > round-robin
> > > > > task dispatcher mentioned earlier is another one.
> > > > >
> > > > > Jonathan Carlson
> > > > >
> > > > >
> > > > >
> > > > > --- Stephen Colebourne <sc...@joda.org>
> wrote:
> > > > > > [Jonathan, I have sent back to commons-dev
> mailing
> > > > list
> > > > > > which is the
> > > > > > appropriate place for design/code discussions.]
> > > > > >
> > > > > > I took a quick look, and I believe that the
> code in
> > > > the
> > > > > > zip will work.
> > > > > > However, my main concern is why this would be
> needed.
> > > > Is
> > > > > > there a use case
> > > > > > for an iterator that never ends?
> > > > > >
> > > > > > I would also like to see the remove method
> > > > implemented.
> > > > > > It should be
> > > > > > possible.
> > > > > >
> > > > > > Stephen
> > > > > >
> > > > > > ----- Original Message -----
> > > > > > From: "Jonathan Carlson" <jo...@yahoo.com>
> > > > > > To: <sc...@joda.org>
> > > > > > Sent: Friday, October 18, 2002 3:53 PM
> > > > > > Subject: LoopingIterator
> > > > > >
> > > > > >
> > > > > > > Hi Stephen,
> > > > > > >
> > > > > > > Thanks for your work on the IteratorUtils.  I
> > > > thought
> > > > > > this
> > > > > > > might be a good addition if it hasn't been
> added
> > > > > > already.
> > > > > > > It's an iterator that loops continually.
> > > > > > Unfortunately, it
> > > > > > > can't just decorate another iterator but has
> to
> > > > wrap a
> > > > > > > collection due to the fact that iterators
> cannot be
> > > > > > reset
> > > > > > > to the beginning of the collection.
> > > > > > >
> > > > > > > Included is a jUnit test case that shows it
> works
> > > > "as
> > > > > > > advertised".  Hope this helps.
> > > > > > >
> > > > > > > Jonathan Carlson
> > > > > > > Minneapolis, Minnesota
> > > > > > >
> > > > > > >
> > > > > > > =====
> > > > > > > Jonathan Carlson
> > > > > > > joncrlsn@users.sf.net
> > > > > > > Minneapolis, Minnesota
> > > > > > >
> > > > > > >
> __________________________________________________
> > > > > > > Do you Yahoo!?
> > > > > > > Faith Hill - Exclusive Performances, Videos &
> More
> > > > > > > http://faith.yahoo.com
> > > > > >
> > > > >
> > > > > > ATTACHMENT part 2 application/x-zip-compressed
> > > > > name=LoopingIterator.zip
> > > > >
> > > > >
> > > > >
> > > > > =====
> > > > > Jonathan Carlson
> > > > > joncrlsn@users.sf.net
> > > > > Minneapolis, Minnesota
> > > > >
> > > > >
> __________________________________________________
> > > > > Do you Yahoo!?
> > > > > HotJobs - Search new jobs daily now
> > > > > http://hotjobs.yahoo.com/
> > > > >
> > > > > --
> > > > > To unsubscribe, e-mail:
> > > > <ma...@jakarta.apache.org>
> > > > > For additional commands, e-mail:
> > > > <ma...@jakarta.apache.org>
> > > > >
> > > >
> > >
> > >
> > >
> > > =====
> > > Jonathan Carlson
> > > joncrlsn@users.sf.net
> > > Minneapolis, Minnesota
> > >
> > > __________________________________________________
> 
=== message truncated ===


=====
Jonathan Carlson
joncrlsn@users.sf.net
Minneapolis, Minnesota

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus � Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [collections][SUBMIT] class 'RandomCollection'

Posted by Stephen Colebourne <sc...@btopenworld.com>.
I am not currently planning on including RandomCollection in [collections].
As Rodney pointed out, it seems to do the same as Collections.shuffle. If
you want to pursue it, can you specify the differences/benefits and use
cases?

I might be more amenable to a decorator implementation (see the inner
classes in CollectionUtils). As it seems to be the iterator that would be
the only difference. eg. a randomCollection(Collection) method that
decorates the original collection, overriding the iterator method to return
the elements once, but in a shuffled order. LoopingIterator, from
IteratorUtils, could be used on the decorated collection if you want a
looping random collection.

Stephen

----- Original Message -----
From: "Tim O'Brien" <to...@transolutions.net>
> You asked, so I'll reply, this is not junk.  I was previously using the
> RandomIterator from the WASA project on SourceForge, and I'm going to
> immediately switch to this RandomCollection.  I'm using your
> RandomCollection for efficient tree population.
>
> I noticed your previous reply to the question about the LoopingIterator
> where you mentioned that you were trying to implement a RandomIterator but
> there were problems with concurrency, etc.  I assume that on further
> thought you decided to tackle the problem from the collection end of the
> problem.
>
> Thanks
>
> Tim
>
>
>
> On Thu, 21 Nov 2002, Jeff Varszegi wrote:
>
> > It's a place you can dump things and get them back in random order, over
and over again if you
> > wish.  I've used it in the past, and just thought I'd get some javadoc
together and show it to you
> > all in case you think it would be useful.  Includes the Apache software
license-- see, I'm getting
> > better all the time!  :O)  Let me know if it's junk or not.
> >
> > Jeff
> >
> >
> > __________________________________________________
> > Do you Yahoo!?
> > Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> > http://mailplus.yahoo.com
>
> --
> ----------------------
> Tim O'Brien
> Evanston, IL
> (847) 863-7045
> tobrien@discursive.com
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [collections][SUBMIT] class 'RandomCollection'

Posted by Tim O'Brien <to...@transolutions.net>.
Jeff, 

You asked, so I'll reply, this is not junk.  I was previously using the 
RandomIterator from the WASA project on SourceForge, and I'm going to 
immediately switch to this RandomCollection.  I'm using your 
RandomCollection for efficient tree population.

I noticed your previous reply to the question about the LoopingIterator
where you mentioned that you were trying to implement a RandomIterator but
there were problems with concurrency, etc.  I assume that on further
thought you decided to tackle the problem from the collection end of the
problem.

Thanks

Tim



On Thu, 21 Nov 2002, Jeff Varszegi wrote:

> It's a place you can dump things and get them back in random order, over and over again if you
> wish.  I've used it in the past, and just thought I'd get some javadoc together and show it to you
> all in case you think it would be useful.  Includes the Apache software license-- see, I'm getting
> better all the time!  :O)  Let me know if it's junk or not.
> 
> Jeff
> 
> 
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus – Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com

-- 
----------------------
Tim O'Brien
Evanston, IL
(847) 863-7045
tobrien@discursive.com



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


[collections][SUBMIT] class 'RandomCollection'

Posted by Jeff Varszegi <jv...@yahoo.com>.
It's a place you can dump things and get them back in random order, over and over again if you
wish.  I've used it in the past, and just thought I'd get some javadoc together and show it to you
all in case you think it would be useful.  Includes the Apache software license-- see, I'm getting
better all the time!  :O)  Let me know if it's junk or not.

Jeff


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus � Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

Re: [collections] LoopingIterator

Posted by Jeff Varszegi <jv...@yahoo.com>.
I don't see how to implement this without being horribly wasteful (checking every value in the
collection backing the Iterator every time something is returned, getting a new Iterator every
time through the loop, etc.).  The thing is, you can't even depend on the implementation of
hashCode() when you're dealing with generic collections, the use of which would be wasteful
anyway.  Jonathan, did you find a solution to this problem?

I was going to implement a RandomIterator, but didn't figure a way around the concurrent-mod
problem for an externally created Iterator.  I think for situations like this it's acceptable to
just notify users of the class that there are no guarantees in the face of concurrent
modification.  It's a shame that Sun didn't include a mod-check hook in the Collection interface,
or even the chance to use Observer, at least as optionally supported.  I mean, I can understand
the absence of observers, because checking for them would slow things down a little bit, but every
single collection I've seen that came outta Sun keeps an incremental count of changes to itself.

Jeff

--- Stephen Colebourne <sc...@btopenworld.com> wrote:
> Jonathan,
> I was going to include your files in the CVS. However, I discovered that
> they do not cope with the situation where the collection being wrapped is
> altered. ie. hasNext() always returns the initially cached value, even if
> the list is clear()ed or it.remove() is called. Can you sort this?
> 
> Also, if resubmitting could you place the code in the correct package and
> with an Apache licence (from another collections file) to confirm that this
> is an official donation of code :-)
> 
> Thanks
> Stephen
> 
> ----- Original Message -----
> From: "Jonathan Carlson" <jo...@yahoo.com>
> > It is attached with updated unit tests.  It was so easy
> > that I'm surprised I didn't implement the remove() in the
> > first place.
> >
> > Thanks!
> >
> > Jonathan Carlson
> > Minneapolis, Minnesota
> >
> >
> > --- Stephen Colebourne <sc...@btopenworld.com> wrote:
> > > From: "Jonathan Carlson" <jo...@yahoo.com>
> > > > I can add a remove method and test cases unless it's
> > > easier
> > > > for you to just add it.  I think it would just use the
> > > > remove method on the Collection.  If the iterator
> > > returned
> > > > by the Collection implementer doesn't support it then
> > > this
> > > > won't either.
> > >
> > > If you could submit the revised code and test case, I
> > > think that I'm willing
> > > to commit it to collections.
> > >
> > > Stephen
> > >
> > >
> > > > As for a use-case, I am using it for a displaying a
> > > number
> > > > of our banner ads on our e-commerce site.  The
> > > round-robin
> > > > task dispatcher mentioned earlier is another one.
> > > >
> > > > Jonathan Carlson
> > > >
> > > >
> > > >
> > > > --- Stephen Colebourne <sc...@joda.org> wrote:
> > > > > [Jonathan, I have sent back to commons-dev mailing
> > > list
> > > > > which is the
> > > > > appropriate place for design/code discussions.]
> > > > >
> > > > > I took a quick look, and I believe that the code in
> > > the
> > > > > zip will work.
> > > > > However, my main concern is why this would be needed.
> > > Is
> > > > > there a use case
> > > > > for an iterator that never ends?
> > > > >
> > > > > I would also like to see the remove method
> > > implemented.
> > > > > It should be
> > > > > possible.
> > > > >
> > > > > Stephen
> > > > >
> > > > > ----- Original Message -----
> > > > > From: "Jonathan Carlson" <jo...@yahoo.com>
> > > > > To: <sc...@joda.org>
> > > > > Sent: Friday, October 18, 2002 3:53 PM
> > > > > Subject: LoopingIterator
> > > > >
> > > > >
> > > > > > Hi Stephen,
> > > > > >
> > > > > > Thanks for your work on the IteratorUtils.  I
> > > thought
> > > > > this
> > > > > > might be a good addition if it hasn't been added
> > > > > already.
> > > > > > It's an iterator that loops continually.
> > > > > Unfortunately, it
> > > > > > can't just decorate another iterator but has to
> > > wrap a
> > > > > > collection due to the fact that iterators cannot be
> > > > > reset
> > > > > > to the beginning of the collection.
> > > > > >
> > > > > > Included is a jUnit test case that shows it works
> > > "as
> > > > > > advertised".  Hope this helps.
> > > > > >
> > > > > > Jonathan Carlson
> > > > > > Minneapolis, Minnesota
> > > > > >
> > > > > >
> > > > > > =====
> > > > > > Jonathan Carlson
> > > > > > joncrlsn@users.sf.net
> > > > > > Minneapolis, Minnesota
> > > > > >
> > > > > > __________________________________________________
> > > > > > Do you Yahoo!?
> > > > > > Faith Hill - Exclusive Performances, Videos & More
> > > > > > http://faith.yahoo.com
> > > > >
> > > >
> > > > > ATTACHMENT part 2 application/x-zip-compressed
> > > > name=LoopingIterator.zip
> > > >
> > > >
> > > >
> > > > =====
> > > > Jonathan Carlson
> > > > joncrlsn@users.sf.net
> > > > Minneapolis, Minnesota
> > > >
> > > > __________________________________________________
> > > > Do you Yahoo!?
> > > > HotJobs - Search new jobs daily now
> > > > http://hotjobs.yahoo.com/
> > > >
> > > > --
> > > > To unsubscribe, e-mail:
> > > <ma...@jakarta.apache.org>
> > > > For additional commands, e-mail:
> > > <ma...@jakarta.apache.org>
> > > >
> > >
> >
> >
> >
> > =====
> > Jonathan Carlson
> > joncrlsn@users.sf.net
> > Minneapolis, Minnesota
> >
> > __________________________________________________
> > Do you Yahoo!?
> > HotJobs - Search new jobs daily now
> > http://hotjobs.yahoo.com/
> 
> 
> ----------------------------------------------------------------------------
> ----
> 
> 
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus � Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [collections] LoopingIterator

Posted by Stephen Colebourne <sc...@btopenworld.com>.
Jonathan,
I was going to include your files in the CVS. However, I discovered that
they do not cope with the situation where the collection being wrapped is
altered. ie. hasNext() always returns the initially cached value, even if
the list is clear()ed or it.remove() is called. Can you sort this?

Also, if resubmitting could you place the code in the correct package and
with an Apache licence (from another collections file) to confirm that this
is an official donation of code :-)

Thanks
Stephen

----- Original Message -----
From: "Jonathan Carlson" <jo...@yahoo.com>
> It is attached with updated unit tests.  It was so easy
> that I'm surprised I didn't implement the remove() in the
> first place.
>
> Thanks!
>
> Jonathan Carlson
> Minneapolis, Minnesota
>
>
> --- Stephen Colebourne <sc...@btopenworld.com> wrote:
> > From: "Jonathan Carlson" <jo...@yahoo.com>
> > > I can add a remove method and test cases unless it's
> > easier
> > > for you to just add it.  I think it would just use the
> > > remove method on the Collection.  If the iterator
> > returned
> > > by the Collection implementer doesn't support it then
> > this
> > > won't either.
> >
> > If you could submit the revised code and test case, I
> > think that I'm willing
> > to commit it to collections.
> >
> > Stephen
> >
> >
> > > As for a use-case, I am using it for a displaying a
> > number
> > > of our banner ads on our e-commerce site.  The
> > round-robin
> > > task dispatcher mentioned earlier is another one.
> > >
> > > Jonathan Carlson
> > >
> > >
> > >
> > > --- Stephen Colebourne <sc...@joda.org> wrote:
> > > > [Jonathan, I have sent back to commons-dev mailing
> > list
> > > > which is the
> > > > appropriate place for design/code discussions.]
> > > >
> > > > I took a quick look, and I believe that the code in
> > the
> > > > zip will work.
> > > > However, my main concern is why this would be needed.
> > Is
> > > > there a use case
> > > > for an iterator that never ends?
> > > >
> > > > I would also like to see the remove method
> > implemented.
> > > > It should be
> > > > possible.
> > > >
> > > > Stephen
> > > >
> > > > ----- Original Message -----
> > > > From: "Jonathan Carlson" <jo...@yahoo.com>
> > > > To: <sc...@joda.org>
> > > > Sent: Friday, October 18, 2002 3:53 PM
> > > > Subject: LoopingIterator
> > > >
> > > >
> > > > > Hi Stephen,
> > > > >
> > > > > Thanks for your work on the IteratorUtils.  I
> > thought
> > > > this
> > > > > might be a good addition if it hasn't been added
> > > > already.
> > > > > It's an iterator that loops continually.
> > > > Unfortunately, it
> > > > > can't just decorate another iterator but has to
> > wrap a
> > > > > collection due to the fact that iterators cannot be
> > > > reset
> > > > > to the beginning of the collection.
> > > > >
> > > > > Included is a jUnit test case that shows it works
> > "as
> > > > > advertised".  Hope this helps.
> > > > >
> > > > > Jonathan Carlson
> > > > > Minneapolis, Minnesota
> > > > >
> > > > >
> > > > > =====
> > > > > Jonathan Carlson
> > > > > joncrlsn@users.sf.net
> > > > > Minneapolis, Minnesota
> > > > >
> > > > > __________________________________________________
> > > > > Do you Yahoo!?
> > > > > Faith Hill - Exclusive Performances, Videos & More
> > > > > http://faith.yahoo.com
> > > >
> > >
> > > > ATTACHMENT part 2 application/x-zip-compressed
> > > name=LoopingIterator.zip
> > >
> > >
> > >
> > > =====
> > > Jonathan Carlson
> > > joncrlsn@users.sf.net
> > > Minneapolis, Minnesota
> > >
> > > __________________________________________________
> > > Do you Yahoo!?
> > > HotJobs - Search new jobs daily now
> > > http://hotjobs.yahoo.com/
> > >
> > > --
> > > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> > > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> > >
> >
>
>
>
> =====
> Jonathan Carlson
> joncrlsn@users.sf.net
> Minneapolis, Minnesota
>
> __________________________________________________
> Do you Yahoo!?
> HotJobs - Search new jobs daily now
> http://hotjobs.yahoo.com/


----------------------------------------------------------------------------
----


> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [collections] LoopingIterator

Posted by Jonathan Carlson <jo...@yahoo.com>.
It is attached with updated unit tests.  It was so easy
that I'm surprised I didn't implement the remove() in the
first place.

Thanks!

Jonathan Carlson
Minneapolis, Minnesota


--- Stephen Colebourne <sc...@btopenworld.com> wrote:
> From: "Jonathan Carlson" <jo...@yahoo.com>
> > I can add a remove method and test cases unless it's
> easier
> > for you to just add it.  I think it would just use the
> > remove method on the Collection.  If the iterator
> returned
> > by the Collection implementer doesn't support it then
> this
> > won't either.
> 
> If you could submit the revised code and test case, I
> think that I'm willing
> to commit it to collections.
> 
> Stephen
> 
> 
> > As for a use-case, I am using it for a displaying a
> number
> > of our banner ads on our e-commerce site.  The
> round-robin
> > task dispatcher mentioned earlier is another one.
> >
> > Jonathan Carlson
> >
> >
> >
> > --- Stephen Colebourne <sc...@joda.org> wrote:
> > > [Jonathan, I have sent back to commons-dev mailing
> list
> > > which is the
> > > appropriate place for design/code discussions.]
> > >
> > > I took a quick look, and I believe that the code in
> the
> > > zip will work.
> > > However, my main concern is why this would be needed.
> Is
> > > there a use case
> > > for an iterator that never ends?
> > >
> > > I would also like to see the remove method
> implemented.
> > > It should be
> > > possible.
> > >
> > > Stephen
> > >
> > > ----- Original Message -----
> > > From: "Jonathan Carlson" <jo...@yahoo.com>
> > > To: <sc...@joda.org>
> > > Sent: Friday, October 18, 2002 3:53 PM
> > > Subject: LoopingIterator
> > >
> > >
> > > > Hi Stephen,
> > > >
> > > > Thanks for your work on the IteratorUtils.  I
> thought
> > > this
> > > > might be a good addition if it hasn't been added
> > > already.
> > > > It's an iterator that loops continually.
> > > Unfortunately, it
> > > > can't just decorate another iterator but has to
> wrap a
> > > > collection due to the fact that iterators cannot be
> > > reset
> > > > to the beginning of the collection.
> > > >
> > > > Included is a jUnit test case that shows it works
> "as
> > > > advertised".  Hope this helps.
> > > >
> > > > Jonathan Carlson
> > > > Minneapolis, Minnesota
> > > >
> > > >
> > > > =====
> > > > Jonathan Carlson
> > > > joncrlsn@users.sf.net
> > > > Minneapolis, Minnesota
> > > >
> > > > __________________________________________________
> > > > Do you Yahoo!?
> > > > Faith Hill - Exclusive Performances, Videos & More
> > > > http://faith.yahoo.com
> > >
> >
> > > ATTACHMENT part 2 application/x-zip-compressed
> > name=LoopingIterator.zip
> >
> >
> >
> > =====
> > Jonathan Carlson
> > joncrlsn@users.sf.net
> > Minneapolis, Minnesota
> >
> > __________________________________________________
> > Do you Yahoo!?
> > HotJobs - Search new jobs daily now
> > http://hotjobs.yahoo.com/
> >
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> 



=====
Jonathan Carlson
joncrlsn@users.sf.net
Minneapolis, Minnesota

__________________________________________________
Do you Yahoo!?
HotJobs - Search new jobs daily now
http://hotjobs.yahoo.com/