You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Neil O'Toole <ne...@users.sourceforge.net> on 2002/12/05 20:23:45 UTC

[collections] private member access in o.a.c.collections.iterators

Hi,

I've been using the o.a.c.collections packages for a few months, and I
want to applaud you guys for some fantastic work. 

I do have a question: forgive me if this has been discussed before
(though I couldn't find it in the mail archive), but is there a
particular reason why the member variables in the
o.a.c.collections.iterators classes are private instead of being
protected? In general, why would you want to do this, as it prevents
subclassing? A particular case: I wanted to created an
ArrayListIterator that subclasses ArrayIterator and implements the
ListIterator interface. With protected member access it is a simple and
elegant implementation to subclass ArrayIterator.

Thoughts on the matter?

- Neil O'Toole


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


[collections] [patch] changes for ArrayListIterator was: Re: [collections] private member access in o.a.c.collections.iterators

Posted by Neil O'Toole <ne...@yahoo.com>.
The attached zip includes the following new classes:

- UnmodifiableArrayListIterator: provides a ListIterator impl over an
array. Does not support ListIterator#set, #add, or #remove. Extends
ArrayIterator (which does not support #add or #remove either). 

- ArrayListIterator.java : Extends UnmodifiableArrayListIterator, and
supports #set.

- TestArrayListIterator.java : test cases, extends TestArrayIterator.

- TestArrayListIterator2.java : test cases, extends TestArrayIterator2.



And the following patches:

- ArrayIterator.patch : changes member access from private to
protected, and allows iteration over zero-length array sections.

- TestArrayIterator2.patch : replaces use of the ArrayIterator
constructor with a factory method, to allow subclassing by
TestArrayListIterator2. Also tests that zero-length iteration is
permitted (was prohibited).

- IteratorUtils.patch : added arrayListIterator(...) methods. Actually
they were already present but commented out, so it wasn't that much
work ;)

- TestAll.patch : included TestArrayListIterator and
TestArrayListIterator2 in test suite.


Enjoy ;)

- Neil


--- Stephen Colebourne <sc...@btopenworld.com> wrote:
> Go for it ;-)
> Stephen
> 
> ----- Original Message -----
> From: "Neil O'Toole" <ne...@users.sourceforge.net>
> To: "Jakarta Commons Developers List"
> <co...@jakarta.apache.org>
> Sent: Friday, December 06, 2002 9:51 PM
> Subject: Re: [collections] private member access in
> o.a.c.collections.iterators
> 
> 
> >
> > I've prepared a patch for ArrayIterator, and the ArrayListIterator
> > class is ready to go, with associated test cases. However, there is
> > another issue with ArrayIterator. The ArrayIterator(Object array,
> int
> > start, int end) constructor has the following test:
> >
> >         if(end <= start) {
> >             throw new IllegalArgumentException(
> >
> > My understanding is that this should really be changed to:
> >
> >         if(end < start) {
> >
> > The current behaviour prohibits the creation of an iterator over a
> > zero-length section of array, even though this is a valid thing to
> do.
> > Unless there are objections, I will also include this change in the
> > patch. This will also require changes to TestArrayList, so I guess
> I
> > can create a patch for this as well.
> >
> > Any comments?
> >
> > - Neil
> >
> >
> > --- Stephen Colebourne <sc...@btopenworld.com> wrote:
> > > Perhaps you would like to send a patch for ArrayIterator.
> > > http://jakarta.apache.org/site/source.html#Patches
> > >
> > > Also, an ArrayListIterator would be very welcome for the
> iterators
> > > package.
> > > If you are writing it, perhaps you would consider submitting it
> > > together
> > > with the associated patch to IteratorUtils?
> > >
> > > Thanks
> > > Stephen
> > >
> > > ----- Original Message -----
> > > From: "Neil O'Toole" <ne...@users.sourceforge.net>
> > > > I've been using the o.a.c.collections packages for a few
> months,
> > > and I
> > > > want to applaud you guys for some fantastic work.
> > > >
> > > > I do have a question: forgive me if this has been discussed
> before
> > > > (though I couldn't find it in the mail archive), but is there a
> > > > particular reason why the member variables in the
> > > > o.a.c.collections.iterators classes are private instead of
> being
> > > > protected? In general, why would you want to do this, as it
> > > prevents
> > > > subclassing? A particular case: I wanted to created an
> > > > ArrayListIterator that subclasses ArrayIterator and implements
> the
> > > > ListIterator interface. With protected member access it is a
> simple
> > > and
> > > > elegant implementation to subclass ArrayIterator.
> > > >
> > > > Thoughts on the matter?
> > > >
> > > > - Neil O'Toole
> > > >
> > > >
> > > > --
> > > > 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>
> > >
> >
> >
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> 

Re: [collections] private member access in o.a.c.collections.iterators

Posted by Stephen Colebourne <sc...@btopenworld.com>.
Go for it ;-)
Stephen

----- Original Message -----
From: "Neil O'Toole" <ne...@users.sourceforge.net>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Sent: Friday, December 06, 2002 9:51 PM
Subject: Re: [collections] private member access in
o.a.c.collections.iterators


>
> I've prepared a patch for ArrayIterator, and the ArrayListIterator
> class is ready to go, with associated test cases. However, there is
> another issue with ArrayIterator. The ArrayIterator(Object array, int
> start, int end) constructor has the following test:
>
>         if(end <= start) {
>             throw new IllegalArgumentException(
>
> My understanding is that this should really be changed to:
>
>         if(end < start) {
>
> The current behaviour prohibits the creation of an iterator over a
> zero-length section of array, even though this is a valid thing to do.
> Unless there are objections, I will also include this change in the
> patch. This will also require changes to TestArrayList, so I guess I
> can create a patch for this as well.
>
> Any comments?
>
> - Neil
>
>
> --- Stephen Colebourne <sc...@btopenworld.com> wrote:
> > Perhaps you would like to send a patch for ArrayIterator.
> > http://jakarta.apache.org/site/source.html#Patches
> >
> > Also, an ArrayListIterator would be very welcome for the iterators
> > package.
> > If you are writing it, perhaps you would consider submitting it
> > together
> > with the associated patch to IteratorUtils?
> >
> > Thanks
> > Stephen
> >
> > ----- Original Message -----
> > From: "Neil O'Toole" <ne...@users.sourceforge.net>
> > > I've been using the o.a.c.collections packages for a few months,
> > and I
> > > want to applaud you guys for some fantastic work.
> > >
> > > I do have a question: forgive me if this has been discussed before
> > > (though I couldn't find it in the mail archive), but is there a
> > > particular reason why the member variables in the
> > > o.a.c.collections.iterators classes are private instead of being
> > > protected? In general, why would you want to do this, as it
> > prevents
> > > subclassing? A particular case: I wanted to created an
> > > ArrayListIterator that subclasses ArrayIterator and implements the
> > > ListIterator interface. With protected member access it is a simple
> > and
> > > elegant implementation to subclass ArrayIterator.
> > >
> > > Thoughts on the matter?
> > >
> > > - Neil O'Toole
> > >
> > >
> > > --
> > > 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>
> >
>
>
> --
> 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] private member access in o.a.c.collections.iterators

Posted by Neil O'Toole <ne...@users.sourceforge.net>.
I've prepared a patch for ArrayIterator, and the ArrayListIterator
class is ready to go, with associated test cases. However, there is
another issue with ArrayIterator. The ArrayIterator(Object array, int
start, int end) constructor has the following test:

        if(end <= start) {
            throw new IllegalArgumentException(

My understanding is that this should really be changed to:

        if(end < start) {

The current behaviour prohibits the creation of an iterator over a
zero-length section of array, even though this is a valid thing to do.
Unless there are objections, I will also include this change in the
patch. This will also require changes to TestArrayList, so I guess I
can create a patch for this as well.

Any comments?

- Neil


--- Stephen Colebourne <sc...@btopenworld.com> wrote:
> Perhaps you would like to send a patch for ArrayIterator.
> http://jakarta.apache.org/site/source.html#Patches
> 
> Also, an ArrayListIterator would be very welcome for the iterators
> package.
> If you are writing it, perhaps you would consider submitting it
> together
> with the associated patch to IteratorUtils?
> 
> Thanks
> Stephen
> 
> ----- Original Message -----
> From: "Neil O'Toole" <ne...@users.sourceforge.net>
> > I've been using the o.a.c.collections packages for a few months,
> and I
> > want to applaud you guys for some fantastic work.
> >
> > I do have a question: forgive me if this has been discussed before
> > (though I couldn't find it in the mail archive), but is there a
> > particular reason why the member variables in the
> > o.a.c.collections.iterators classes are private instead of being
> > protected? In general, why would you want to do this, as it
> prevents
> > subclassing? A particular case: I wanted to created an
> > ArrayListIterator that subclasses ArrayIterator and implements the
> > ListIterator interface. With protected member access it is a simple
> and
> > elegant implementation to subclass ArrayIterator.
> >
> > Thoughts on the matter?
> >
> > - Neil O'Toole
> >
> >
> > --
> > 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>
> 


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


Re: [collections] private member access in o.a.c.collections.iterators

Posted by Stephen Colebourne <sc...@btopenworld.com>.
Perhaps you would like to send a patch for ArrayIterator.
http://jakarta.apache.org/site/source.html#Patches

Also, an ArrayListIterator would be very welcome for the iterators package.
If you are writing it, perhaps you would consider submitting it together
with the associated patch to IteratorUtils?

Thanks
Stephen

----- Original Message -----
From: "Neil O'Toole" <ne...@users.sourceforge.net>
> I've been using the o.a.c.collections packages for a few months, and I
> want to applaud you guys for some fantastic work.
>
> I do have a question: forgive me if this has been discussed before
> (though I couldn't find it in the mail archive), but is there a
> particular reason why the member variables in the
> o.a.c.collections.iterators classes are private instead of being
> protected? In general, why would you want to do this, as it prevents
> subclassing? A particular case: I wanted to created an
> ArrayListIterator that subclasses ArrayIterator and implements the
> ListIterator interface. With protected member access it is a simple and
> elegant implementation to subclass ArrayIterator.
>
> Thoughts on the matter?
>
> - Neil O'Toole
>
>
> --
> 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>