commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jörg Schaible <Joerg.Schai...@Elsag-Solutions.com>
Subject RE: [Collections] ListUtils.transformedList unaffected by invokerTransformer ?
Date Fri, 31 Aug 2007 11:16:11 GMT
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


Mime
View raw message