Index: lutinutil/src/java/org/codelutin/util/TransformedList.java diff -u /dev/null lutinutil/src/java/org/codelutin/util/TransformedList.java:1.1 --- /dev/null Tue Aug 2 12:54:40 2005 +++ lutinutil/src/java/org/codelutin/util/TransformedList.java Tue Aug 2 12:54:35 2005 @@ -0,0 +1,110 @@ +/* *##% + * Copyright (C) 2005 + * Code Lutin, Cédric Pineau, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +/* * + * TransformedList.java + * + * Created: 2 août 2005 02:12:42 CEST + * + * @author Benjamin POUSSIN + * @version $Revision: 1.1 $ + * + * Last update: $Date: 2005/08/02 12:54:35 $ + * by : $Author: bpoussin $ + */ + +package org.codelutin.util; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.AbstractList; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class TransformedList extends AbstractList implements Serializable { // TransformedList + + // private static final long serialVersionUID = ; + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(TransformedList.class); + + protected Transformer transformer = null; + protected List inner = null; + + public TransformedList(Transformer transformer){ + if(transformer == null){ + throw new IllegalArgumentException("Transformer must not be null"); + } else { + this.transformer = transformer; + this.inner = new ArrayList(); + } + } + + public TransformedList(Transformer transformer, Collection c){ + this(transformer); + addAll(c); + } + + public int size(){ + return inner.size(); + } + + public E get(int index){ + Object f = inner.get(index); + E result = (E)transformer.untranform(f); + return result; + } + + public E set(int index, E element){ + Object f = transformer.transform(element); + f = inner.set(index, f); + E result = (E)transformer.untranform(f); + return result; + } + + public void add(int index, E element){ + Object f = transformer.transform(element); + inner.add(index, f); + } + + public E remove(int index) { + Object f = inner.remove(index); + E result = (E)transformer.untranform(f); + return result; + } + + private void writeObject(ObjectOutputStream out) throws IOException { + out.defaultWriteObject(); + out.writeObject(transformer); + out.writeObject(inner); + } + + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + in.defaultReadObject(); + transformer = (Transformer)in.readObject(); + inner = (List)in.readObject(); + } + +} // TransformedList + Index: lutinutil/src/java/org/codelutin/util/Transformer.java diff -u /dev/null lutinutil/src/java/org/codelutin/util/Transformer.java:1.1 --- /dev/null Tue Aug 2 12:54:41 2005 +++ lutinutil/src/java/org/codelutin/util/Transformer.java Tue Aug 2 12:54:35 2005 @@ -0,0 +1,45 @@ +/* *##% + * Copyright (C) 2005 + * Code Lutin, Cédric Pineau, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +/* * + * Transformer.java + * + * Created: 2 août 2005 02:55:41 CEST + * + * @author Benjamin POUSSIN + * @version $Revision: 1.1 $ + * + * Last update: $Date: 2005/08/02 12:54:35 $ + * by : $Author: bpoussin $ + */ + +package org.codelutin.util; + +import java.io.Serializable; + +/** +* Permet de transformer un objet en un autre et inversement +*/ +public interface Transformer implements Serializable { // Transformer + + public F transform(E e); + public E untransform(F f); + +} // Transformer +