commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rafael U. C. Afonso" <r.u.c.afo...@uol.com.br>
Subject Re: Tranformer collection processor
Date Tue, 10 Aug 2004 18:47:58 GMT
Tö complement, It could be like
protected method transform() from
TransfomedCollection:

    protected Collection
transform(Collection coll) {
        List list = new
ArrayList(coll.size());
        for (Iterator it =
coll.iterator(); it.hasNext(); ) {
           
list.add(transform(it.next()));
        }
        return list;
    }


---------- Início da mensagem original
-----------

      De: "Rafael U. C. Afonso"
r.u.c.afonso@uol.com.br
    Para: "commons-user"
commons-user@jakarta.apache.org
      Cc: 
    Data: Tue, 10 Aug 2004 14:48:00 -0300
 Assunto: Re: Tranformer collection
processor

> Hello again:
> 
> I Read CollectionTranfomer API. It
> says: "The add methods are affected by
> this class.". Reading the source code
> I could see that only added elements
> are transformed. But If I have a
> Collection (List, Set, Bag, etc) that
> has elements before? I want that ALL
> it elements be transfomed, not only
> when I add something. For example I
> create this program test that uses
> ListTranformer:
> 
> import org.apache.commons.collections.*;
> import java.util.*;
> 
> public class TestaListTransformer {
> 	static Object[] vector = {"a", "b",
"c"};
> 	
> 	private static class UpperTransformer
> implements Transformer {
> 		public Object transform(Object
input) {
> 			return
input.toString().toUpperCase();
> 		}
> 	}
> 	
> 	public static void main(String
args[]) {
> 		List list1 = Arrays.asList(vector);
> 		System.out.println("Original List: "
> + list1);
> 		
> 		List list2 =
> ListUtils.transformedList(list1, new
> UpperTransformer());
> 		System.out.println("New List: " +
> list2);
> 		
> 		System.out.print("Iteracting over
> New List: ");
> 		for(Iterator it = list2.iterator();
> it.hasNext(); ) {
> 		
> System.out.print(it.next().toString()
> + ", ");
> 		}
> 	}
> 	
> }
> 
> My results were:
> 
> Original List: [a, b, c]
> New List: [a, b, c]
> Iteracting over New List: a, b, c, 
> 
> What I wanted is when I do a
> toString() or iterator() over newList
> I got all its elements tranformed. Im
> this case to get [A, B, C]. So I
> maintain again my proposal to create a
> method that returns a Collection
> (List, Set, Bag, etc) with all
> elements transformed.
> 
> Thanks,
> 
> Rafael Ubiratam Clemente Afonso
> r.u.c.afonso@uol.com.br
> ---------------------------------
> Where is Debug?
> Debug is on the Table!
> 
> ---------- Início da mensagem original
> -----------
> 
>       De: "Kishore Senji"
ksenji@gmail.com
>     Para: "Jakarta Commons Users List"
> commons-user@jakarta.apache.org
>       Cc: 
>     Data: Tue, 3 Aug 2004 22:23:20 -0400
>  Assunto: Re: Tranformer collection
> processor
> 
> > CollectionUtils.transform(Collection
> collection, Transformer
> > transformer); does what you have
> proposed
> > 
> > On Tue,  3 Aug 2004 23:09:30 -0300,
> Rafael U. C. Afonso
> > <r.u.c.afonso@uol.com.br> wrote:
> > > Hello:
> > > 
> > > Is there something in Collections
> that, given a collection
> > > and a Transformer, return a
> collection of transformed
> > > Objects?
> > > It would be like this:
> > > 
> > > class
TransformeProcessorCollection {
> > >    private Transformer transformer;
> > > 
> > >    public
>
TransformeProcessorCollection(Transformer
> trans) {
> > >        transformer = trans;
> > >    }
> > > 
> > >    public Collection
> process(Colletcion col) {
> > >        Collection newCol = new
> ArrayList(col.size); // Or
> > > some other type of Collection
> > >        Iterator it = new
> TransformIterator(col.iterator(),
> > > transformer);
> > >        while(it.hasNext()) {
> > >            newCol.add(it.next());
> > >        }
> > >        return newCol;
> > >    }
> > > 
> > > }
> > > 
> > > If it does not exist, I would like
> suggest it for Commons
> > > Collections. Something similar
> would be done with Closures
> > > and Predicates.
> > > 
> > > Thanks,
> > > 
> > > Rafael Ubiratam Clemente Afonso
> > > r.u.c.afonso@uol.com.br
> > > ---------------------------------
> > > Where is Debug?
> > > Debug is on the Table!
> > > 
> > >
>
_______________________________________________________
> > > Acabe com aquelas janelinhas que
> pulam na sua tela.
> > > AntiPop-up UOL - É grátis!
> > > http://antipopup.uol.com.br/
> > > 
> > >
>
--------------------------------------------------
> > > To unsubscribe, e-mail:
>
commons-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail:
> commons-user-help@jakarta.apache.org
> > > 
> > >
> > 
> >
>
----------------------------------------------
> > To unsubscribe, e-mail:
>
commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> commons-user-help@jakarta.apache.org
> > 
> > 
> 
> 
>  
>
__________________________________________________________________________
> Acabe com aquelas janelinhas que
pulam na sua tela.
> AntiPop-up UOL - É grátis!
> http://antipopup.uol.com.br/
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
commons-user-help@jakarta.apache.org
> 
> 

Rafael Ubiratam Clemente Afonso
r.u.c.afonso@uol.com.br
---------------------------------
Where is Debug?
Debug is on the Table!
 
__________________________________________________________________________
Acabe com aquelas janelinhas que pulam na sua tela.
AntiPop-up UOL - É grátis!
http://antipopup.uol.com.br/



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


Mime
View raw message