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
What platform is that, Java ME?
--
Lew
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)
>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
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.
> 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>