As Kishore said

org.apache.commons.collections.CollectionUtils

can do what you need. You must use #CollectionUtils.collect(Collection collection, Transformer transformer)#

See below ...

Rafael U. C. Afonso wrote:

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());


CollectionUtils.collect(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
[EMAIL PROTECTED]
---------------------------------
Where is Debug?
Debug is on the Table!

---------- In�cio da mensagem original
-----------

De: "Kishore Senji" [EMAIL PROTECTED]
Para: "Jakarta Commons Users List"
[EMAIL PROTECTED]
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


<[EMAIL PROTECTED]> 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
[EMAIL PROTECTED]
---------------------------------
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:


[EMAIL PROTECTED]


For additional commands, e-mail:


[EMAIL PROTECTED]






----------------------------------------------


To unsubscribe, e-mail:


[EMAIL PROTECTED]


For additional commands, e-mail:


[EMAIL PROTECTED]







__________________________________________________________________________ Acabe com aquelas janelinhas que pulam na sua tela. AntiPop-up UOL - � gr�tis! http://antipopup.uol.com.br/



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



-------------------------------------------------------------------------------------------------------------------
Este correo electr�nico y, en su caso, cualquier fichero anexo al mismo, contiene 
informaci�n de car�cter confidencial exclusivamente dirigida a su destinatario o 
destinatarios. Queda prohibida su divulgaci�n, copia o distribuci�n a terceros sin la 
previa autorizaci�n escrita de Indra. En el caso de haber recibido este correo 
electr�nico por error, se ruega notificar inmediatamente esta circunstancia mediante 
reenv�o a la direcci�n electr�nica del remitente.

The information in this e-mail and in any attachments is confidential and solely for 
the attention and use of the named addressee(s). You are hereby notified that any 
dissemination, distribution or copy of this communication is prohibited without the 
prior written consent of Indra. If you have received this communication in error, 
please, notify the sender by reply e-mail

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to