You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Stephen Colebourne <sc...@btopenworld.com> on 2005/07/15 01:15:41 UTC

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

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