package net.sf.kerner.utils.collections.list.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import net.sf.kerner.utils.Transformer;
import net.sf.kerner.utils.collections.list.FactoryList;
import net.sf.kerner.utils.collections.list.TransformerList;

public abstract class AbstractListTransformer<T, V> extends ListWalkerDefault<T> implements Transformer<T, V>,
        TransformerList<T, V> {

    protected final FactoryList<V> factory;

    protected volatile List<V> result;

    protected volatile int currentIndex;

    public AbstractListTransformer() {
        this(new ArrayListFactory<V>());
    }

    public AbstractListTransformer(final FactoryList<V> factory) {
        this.factory = factory;
        super.addVisitor(new DefaultListVisitorImpl<T>() {
            @Override
            public Void visit(final T element, final int index) {
                setCurrentIndex(index);
                result.add(transform(element));
                return null;
            }
        });
    }

    @Override
    public synchronized void beforeWalk() {
        super.beforeWalk();
        result = factory.createCollection();
    }

    protected int getCurrentIndex() {
        return currentIndex;
    }

    private void setCurrentIndex(final int currentIndex) {
        this.currentIndex = currentIndex;
    }

    /**
     * if {@code element == null}, empty list is returned.
     */
    public synchronized List<V> transformCollection(final Collection<? extends T> element) {
        if (element != null)
            walk(new ArrayList<T>(element));
        return result;
    }

}

@@ -1,8 +1,737 @@
+/**********************************************************************%0ACopyright (c) 2013 Alexander Kerner. All rights reserved.%0ALicensed under the Apache License, Version 2.0 (the %22License%22);%0Ayou may not use this file except in compliance with the License.%0AYou may obtain a copy of the License at%0A%0A    http://www.apache.org/licenses/LICENSE-2.0%0A%0AUnless required by applicable law or agreed to in writing, software%0Adistributed under the License is distributed on an %22AS IS%22 BASIS,%0AWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0ASee the License for the specific language governing permissions and%0Alimitations under the License.%0A ***********************************************************************/%0A%0A
 package 
@@ -831,16 +831,46 @@
 ection;%0A
+import java.util.Collections;%0A
 import j
@@ -1044,16 +1044,332 @@
 rList;%0A%0A
+/**%0A * %0A * TODO description%0A * %0A * %3Cp%3E%0A * %3Cb%3EExample:%3C/b%3E%3Cbr%3E%0A * %0A * %3C/p%3E%0A * %3Cp%3E%0A * %0A * %3Cpre%3E%0A * TODO example%0A * %3C/pre%3E%0A * %0A * %3C/p%3E%0A * %3Cp%3E%0A * last reviewed: 0000-00-00%0A * %3C/p%3E%0A * %0A * @author %3Ca href=%22mailto:alexanderkerner24@gmail.com%22%3EAlexander Kerner%3C/a%3E%0A * @version 2013-08-15%0A * %0A * @param %3CT%3E%0A * @param %3CV%3E%0A */%0A
 public a
@@ -2286,24 +2286,24 @@
 ntIndex() %7B%0A
-
         retu
@@ -2322,24 +2322,129 @@
 dex;%0A    %7D%0A%0A
+    public synchronized List%3CV%3E getAgain() %7B%0A        return Collections.unmodifiableList(result);%0A    %7D%0A%0A
     private 

Add AbstractListTransformer#getAgain().