You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by James Carman <ja...@carmanconsulting.com> on 2005/11/23 14:24:45 UTC

[collections] IndexTransformer in 3.2?

All,

I put in a Bugzilla request for an IndexTransformer class.  Basically, it
just returns the value from the input (input can be List, array, String, or
StringBuffer) at a specified index.  We've used a similar class in our
application when we want to put the values from a query result (Collection
of Object[]) into a map.  We do something like this...

public void populateMap( Map map, Collection objects, Transformer
keyTransformer, Transformer valueTransformer );

And, you'd use it like this (assuming we did something like select x.id,
x.name from SomeClass x)...

populateMap( map, queryResults, new IndexTransformer(0), new
IndexTransformer(1));

Do you think I could also add the populateMap method (there's another flavor
of it that just uses the object itself as the value using a no-op
transformer)?

James



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


Re: [collections] IndexTransformer in 3.2?

Posted by Stephen Colebourne <sc...@btopenworld.com>.
James Carman wrote:
> I put in a Bugzilla request for an IndexTransformer class.  Basically, it
> just returns the value from the input (input can be List, array, String, or
> StringBuffer) at a specified index.
We already have a CollectionUtils method for getting the indexed object 
from a List/Map/Array etc.

>  We've used a similar class in our
> application when we want to put the values from a query result (Collection
> of Object[]) into a map.  We do something like this...
> 
> public void populateMap( Map map, Collection objects, Transformer
> keyTransformer, Transformer valueTransformer );
> 
> And, you'd use it like this (assuming we did something like select x.id,
> x.name from SomeClass x)...
> 
> populateMap( map, queryResults, new IndexTransformer(0), new
> IndexTransformer(1));
> 
> Do you think I could also add the populateMap method (there's another flavor
> of it that just uses the object itself as the value using a no-op
> transformer)?
The populateMap methods definitely look useful and should be added.

The transformer is just one of many, many transformers that could be 
added. The problem is when to stop, see new thread.

Stephen


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