You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Björn Eickvonder <b....@gmx.net> on 2005/07/13 23:49:34 UTC

collections.list.LazyList set method

Hello,

I use a LazyList within a bean to store indexed properties, having only a
"getList()" and a "setList(list)" method. This works fine as long as I only
set nested properties of the indexed property, i.e. setting something like
list[0].attribute.
But if I try to set the indexed property itself by e.g.
"PropertyUtils.setProperty(bean, "list[0]", "val0")" out of the beanutils
package I get an ArrayIndexOutOfBounds because in the end this call uses the
set-method of the underlying list.
So my suggestion would be to slightly extend the LazyList by overwriting the
set-method (defined in List) in the following way

    public Object set(int index, Object obj) {
      if (index>=size()) get(index);
      return super.set(index, obj);
    }

What do you think about this idea?

Bjoern Eickvonder

____________
Virus checked by G DATA AntiVirusKit
Version: AVK 15.0.6045 from 13.07.2005


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [collections] collections.list.LazyList set method

Posted by Stephen Colebourne <sc...@btopenworld.com>.
Björn Eickvonder wrote:
> I use a LazyList within a bean to store indexed properties, having only a
> "getList()" and a "setList(list)" method. This works fine as long as I only
> set nested properties of the indexed property, i.e. setting something like
> list[0].attribute.
> But if I try to set the indexed property itself by e.g.
> "PropertyUtils.setProperty(bean, "list[0]", "val0")" out of the beanutils
> package I get an ArrayIndexOutOfBounds because in the end this call uses the
> set-method of the underlying list.
> So my suggestion would be to slightly extend the LazyList by overwriting the
> set-method (defined in List) in the following way
> 
>     public Object set(int index, Object obj) {
>       if (index>=size()) get(index);
>       return super.set(index, obj);
>     }
> 
> What do you think about this idea?

See GrowthList in SVN which grows on set() and add(). To achieve a list 
that grows on set(), add() and get() you must use both a Lazylist and a 
GrowthList together.

Stephen

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org