You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Laurent Perez <ha...@gmail.com> on 2007/08/31 13:07:48 UTC
[Collections] ListUtils.transformedList unaffected by invokerTransformer ?
Hi !
Not sure if this is a bug or intended behaviour, given the following code :
Transformer t = TransformerUtils.invokerTransformer("toLowerCase");
List<String> abc = new ArrayList<String>();
abc.add("A");
List<String> tabc = ListUtils.transformedList(abc, t);
System.out.println("tabc:" + tabc);
This will return : tabc:[A] instead of tabc:[a].
A single transform works, String a = (String)t.transform("A"); will
return a lowercase "a".
Is it a bug ?
Thanks
laurent
--
<a href="http://in-pocket.blogspot.com">http://in-pocket.blogspot.com
- Mobile world, technology and more</a>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
RE: [Collections] ListUtils.transformedList unaffected by invokerTransformer ?
Posted by Jörg Schaible <Jo...@Elsag-Solutions.com>.
Hi Laurent,
Laurent Perez wrote on Friday, August 31, 2007 1:08 PM:
> Hi !
>
> Not sure if this is a bug or intended behaviour, given the following
> code :
>
> Transformer t = TransformerUtils.invokerTransformer("toLowerCase");
> List<String> abc = new ArrayList<String>();
> abc.add("A");
> List<String> tabc = ListUtils.transformedList(abc, t);
> System.out.println("tabc:" + tabc);
>
> This will return : tabc:[A] instead of tabc:[a].
>
> A single transform works, String a = (String)t.transform("A"); will
> return a lowercase "a".
>
> Is it a bug ?
It's defined behaviour. A transformer will only transformed new elements, not the ones already available in the collection. This is, because the TransformedList is a decorator for the original. See http://commons.apache.org/collections/api-release/org/apache/commons/collections/list/TransformedList.html#TransformedList(java.util.List,%20org.apache.commons.collections.Transformer)
- Jörg
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org