Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #6960

Re: setSize ArrayList, when will it come?

From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.java.programmer
Subject Re: setSize ArrayList, when will it come?
Date 2011-08-10 10:21 +0200
Message-ID <9aetckFmvmU1@mid.individual.net> (permalink)
References <j1pp1j$3rf$1@news.albasani.net> <j1q1cv$aos$1@dont-email.me> <j1q596$gs8$1@news.albasani.net>

Show all headers | View raw


On 09.08.2011 04:16, Jan Burse wrote:
> Eric Sosman schrieb:
>> Perhaps if you'd explain your use case in more detail
>> someone will have a suggestion you may find helpful.
>
> I have only referted to the meta use case in my post.
> The software refactoring use case, is replacing a synchronized
> Vector by an unsychronized ArrayList in regions where no synchronization
> is necessary.

This can be done in many cases, especially in all cases where Vector 
instances are used through the List interface.

> I actually do use setSize for a kind of sparse Vector.
> Sparse in the sense that my Vector will have a couple
> of holes represented by null value elements. Which
> is eventually abuse of the term "sparse", but the use
> case is there.

If you really need a sparse type then you could use Map<Integer,E> or 
implement your own version of List<E>.

> The missing thought in the reponse is the design goal
> of ArrayList. They are explicitly advertised in the
> class comment as unsynchronized version of Vector. It
> is brainless not to honor such a design goal in a response.

This is not true.  Quote: "This class is roughly equivalent to Vector, 
except that it is unsynchronized."
http://download.oracle.com/javase/6/docs/api/java/util/ArrayList.html

Note the "roughly".  This is the only reference to "Vector" on that doc 
page (apart from the link to Vector's page).

> On the other hand it is very clever to have the possibility
> of turning initial design goals into requests for
> enhancement. Imagine the following situation:
>
> You go into a restaurant and order pizza,
> you get your pizza without cheese, you
> ask the waiter what is wrong, and the waiter
> says, oh this cannot be changed, cheese has
> to be ordered separately.
>
> Brainless are we, who accept this.

Engineers at Sun might be less brainless than you think.  In fact, they 
probably used the chance to clean the interface.  I believe the design 
rationale here is that the size of a collection should only be modified 
by methods which actually add or remove from the collection.

Frankly, all the efforts you spend for ranting about Sun / Oracle not 
"fixing" a bug with prio "low" (and also the erroneous statement about 
"sparse Vectors") could be better spent for any of these solutions:

1. Write your own version of ArrayList by inheriting AbstractList and 
adding all the methods you need.

2. Writing a static helper method which uses ArrayList.ensureCapacity() 
and a loop which invokes add() or removeRange() depending on whether the 
new capacity is larger or smaller.

3. Do nothing.  Synchronization overhead of Vector isn't too bad if it's 
not used by multiple threads.  After all the replacement is more like an 
optimization.  If you want to be sure, do the measurements.

Kind regards

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-09 00:47 +0200
  Re: setSize ArrayList, when will it come? Knute Johnson <september@knutejohnson.com> - 2011-08-08 16:53 -0700
    Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-09 02:30 +0200
  Re: setSize ArrayList, when will it come? Arne Vajhøj <arne@vajhoej.dk> - 2011-08-08 20:50 -0400
  Re: setSize ArrayList, when will it come? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-08 21:09 -0400
    Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-09 04:16 +0200
      Re: setSize ArrayList, when will it come? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-08 21:39 -0500
        Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-09 09:33 +0200
          Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-09 09:42 +0200
        Re: setSize ArrayList, when will it come? Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-09 07:56 +0000
          Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-09 11:18 +0200
          Re: setSize ArrayList, when will it come? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-09 10:36 -0500
            Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-09 18:30 +0200
              Re: setSize ArrayList, when will it come? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-09 16:30 -0500
                Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-10 00:31 +0200
                Re: setSize ArrayList, when will it come? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-09 20:36 -0500
                Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-10 09:04 +0200
                Re: setSize ArrayList, when will it come? Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-10 08:50 +0000
                Re: setSize ArrayList, when will it come? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-10 18:16 -0500
                Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-11 01:55 +0200
      Re: setSize ArrayList, when will it come? Patricia Shanahan <pats@acm.org> - 2011-08-09 01:33 -0700
        Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-09 11:16 +0200
          Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-09 11:32 +0200
            Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-09 11:35 +0200
          Re: setSize ArrayList, when will it come? Patricia Shanahan <pats@acm.org> - 2011-08-09 04:00 -0700
          Re: setSize ArrayList, when will it come? Arne Vajhøj <arne@vajhoej.dk> - 2011-08-09 20:11 -0400
      Re: setSize ArrayList, when will it come? Robert Klemme <shortcutter@googlemail.com> - 2011-08-10 10:21 +0200
        Re: setSize ArrayList, when will it come? Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-10 09:14 +0000
        Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-10 12:29 +0200
          Re: setSize ArrayList, when will it come? Robert Klemme <shortcutter@googlemail.com> - 2011-08-10 19:27 +0200
            Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-10 20:22 +0200
              Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-10 20:37 +0200
                Re: setSize ArrayList, when will it come? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-10 18:22 -0500
                Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-11 01:52 +0200
                Re: setSize ArrayList, when will it come? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-10 21:43 -0500
                Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-11 14:19 +0200
              Re: setSize ArrayList, when will it come? Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-10 22:23 +0000
                Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-11 01:47 +0200
                Re: setSize ArrayList, when will it come? Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-11 00:23 +0000
                Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-11 09:19 +0200
                Re: setSize ArrayList, when will it come? Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-12 15:06 +0000
  Re: setSize ArrayList, when will it come? Roedy Green <see_website@mindprod.com.invalid> - 2011-08-09 09:58 -0700
    Re: setSize ArrayList, when will it come? Patricia Shanahan <pats@acm.org> - 2011-08-09 10:25 -0700
      Re: setSize ArrayList, when will it come? Tom Anderson <twic@urchin.earth.li> - 2011-08-09 22:38 +0100
        Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-10 00:36 +0200
          Re: setSize ArrayList, when will it come? Roedy Green <see_website@mindprod.com.invalid> - 2011-08-09 15:55 -0700
          Re: setSize ArrayList, when will it come? Knute Johnson <september@knutejohnson.com> - 2011-08-09 16:03 -0700
            Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-10 09:18 +0200
              Re: setSize ArrayList, when will it come? Mayeul <mayeul.marguet@free.fr> - 2011-08-10 11:26 +0200
                Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-10 12:35 +0200
              Re: setSize ArrayList, when will it come? Lew <lewbloch@gmail.com> - 2011-08-10 09:33 -0700
                Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-10 20:22 +0200
          Re: setSize ArrayList, when will it come? Patricia Shanahan <pats@acm.org> - 2011-08-09 22:13 -0700
            Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-11 02:01 +0200
              Re: setSize ArrayList, when will it come? Patricia Shanahan <pats@acm.org> - 2011-08-10 18:42 -0700
                Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-11 14:21 +0200
    Re: setSize ArrayList, when will it come? Arne Vajhøj <arne@vajhoej.dk> - 2011-08-09 20:09 -0400
  Re: setSize ArrayList, when will it come? Roedy Green <see_website@mindprod.com.invalid> - 2011-08-09 16:02 -0700
    Re: setSize ArrayList, when will it come? Arne Vajhøj <arne@vajhoej.dk> - 2011-08-09 20:13 -0400

csiph-web