Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Please review this code: ArrayList clone

2 views
Skip to first unread message

guptan

unread,
Dec 17, 2009, 8:04:52 AM12/17/09
to

Please review this code as my platform doesnot have array list but
only slow vector.
http://pastesite.com/12249
Hoping to hear your valuable suggestions.

Tom Anderson

unread,
Dec 17, 2009, 8:50:05 AM12/17/09
to

Stop, drop, and use this instead:

http://backport-jsr166.sourceforge.net/index.php

It doesn't have your shrink method, but you can easily add that
externally:

void shrink(List l) {
Iterator it = l.iterator();
while (it.hasNext()) {
if (it.next() == null) it.remove();
}
}

That has the same effect at the array level as your shrink method, which
as you observe is rather inefficient. You can do better with a loop doing
get/set at a pair of advancing indices, but i leave this as an exercise to
the reader.

tom

--
I was eventually persuaded of the need to design programming notations
so as to maximize the number of errors which cannot be made, or if made,
can be reliably detected at compile time. Perhaps this would make the
text of programs longer. Never mind! Wouldnt you be delighted if your
Fairy Godmother offered to wave her wand over your program to remove
all its errors and only made the condition that you should write out
and key in your whole program three times! -- C. A. R, Hoare

Lew

unread,
Dec 17, 2009, 8:59:13 AM12/17/09
to
guptan wrote:
>> Please review this code as my platform doesnot have array list [sic]
>> butonly slow vector [sic].

What platform is that, Java ME?

--
Lew

Roedy Green

unread,
Dec 17, 2009, 11:08:09 AM12/17/09
to
On Thu, 17 Dec 2009 05:04:52 -0800 (PST), guptan <man...@gmail.com>
wrote, quoted or indirectly quoted someone who said :

The source code for ArrayList is part of the JDK. You probably could
just lift it. Is that illegal?
--
Roedy Green Canadian Mind Products
http://mindprod.com
The future has already happened, it just isn�t evenly distributed.
~ William Gibson (born: 1948-03-17 age: 61)

Roedy Green

unread,
Dec 17, 2009, 11:09:33 AM12/17/09
to
On Thu, 17 Dec 2009 08:08:09 -0800, Roedy Green
<see_w...@mindprod.com.invalid> wrote, quoted or indirectly quoted
someone who said :

>The source code for ArrayList is part of the JDK. You probably could


>just lift it. Is that illegal?

surely ArrayList is part of the open source.

Arne Vajhøj

unread,
Dec 17, 2009, 8:29:41 PM12/17/09
to
On 17-12-2009 11:09, Roedy Green wrote:
> On Thu, 17 Dec 2009 08:08:09 -0800, Roedy Green
> <see_w...@mindprod.com.invalid> wrote, quoted or indirectly quoted
> someone who said :
>> The source code for ArrayList is part of the JDK. You probably could
>> just lift it. Is that illegal?
>
> surely ArrayList is part of the open source.

If:
- he gets the code as OpenJDK and not as SUN Java
- he can live with the OpenJDK license
then it should be fine.

Arne

guptan

unread,
Dec 17, 2009, 11:30:55 PM12/17/09
to
On Dec 17, 9:08 pm, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
> On Thu, 17 Dec 2009 05:04:52 -0800 (PST), guptan <mano...@gmail.com>

> wrote, quoted or indirectly quoted someone who said :
>
>
>
> >Please review this code as my platform doesnot have array list but
> >only slow vector.
> >http://pastesite.com/12249
> >Hoping to hear your valuable suggestions.
>
> The source code for ArrayList is part of the JDK.  You probably could
> just lift it.  Is that illegal?
> --
> Roedy Green Canadian Mind Productshttp://mindprod.com

> The future has already happened, it just isn’t evenly distributed.
> ~ William Gibson (born: 1948-03-17 age: 61)

Surely I read OpenJDK ArrayList.
It helped me to design inset at middle of the list and removing from
middle.
But most of the part was designed by reading javadoc.

guptan

unread,
Dec 18, 2009, 12:41:46 AM12/18/09
to

This the code I read.
http://www.docjar.com/html/api/java/util/ArrayList.java.html
And this the code I wrote.
http://pastesite.com/12249
And see if it is a serious violation.

John B. Matthews

unread,
Dec 18, 2009, 2:00:06 PM12/18/09
to
In article
<47c0c2b4-8854-45e5...@u8g2000prd.googlegroups.com>,
guptan <man...@gmail.com> wrote:

> On Dec 18, 9:30 am, guptan <mano...@gmail.com> wrote:
> > On Dec 17, 9:08 pm, Roedy Green <see_webs...@mindprod.com.invalid>
> > wrote:
> >
> > > On Thu, 17 Dec 2009 05:04:52 -0800 (PST), guptan <mano...@gmail.com>
> > > wrote, quoted or indirectly quoted someone who said :

> > [...]


> > > The source code for ArrayList is part of the JDK.  You probably
> > > could just lift it.  Is that illegal?

> > [...]


> > Surely I read OpenJDK ArrayList. It helped me to design inset at
> > middle of the list and removing from middle. But most of the part
> > was designed by reading javadoc.
>
> This the code I read.
> http://www.docjar.com/html/api/java/util/ArrayList.java.html
> And this the code I wrote.
> http://pastesite.com/12249
> And see if it is a serious violation.

Both are array based; inspired, yes; copied, no. JDK, 1094 lines;
guptan, 246 lines; less than 1% verbatim.

JDK 121:
* Constructs an empty list with the specified initial capacity.
guptan 17:
* Constructs an empty list with the specified initial capacity.

JDK 136:
* Constructs an empty list with an initial capacity of ten.
guptan 27:
* Constructs an empty list with the specified initial capacity and
growth

JDK 172-174:
* Increases the capacity of this <tt>ArrayList</tt> instance, if
* necessary, to ensure that it can hold at least the number of elements
* specified by the minimum capacity argument.
guptan 59-62:
* Increases the capacity of this instance, if
* necessary, to ensure that it can hold at
* least the number of elements specified by
* the minimum capacity argument.

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

0 new messages