All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fiolino.common.processing.MultiProcessor Maven / Gradle / Ivy

Go to download

General structure to easily create dynamic logic via MethodHandles and others.

There is a newer version: 1.0.10
Show newest version
package org.fiolino.common.processing;

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

/**
 * Created by kuli on 25.11.15.
 */
public class MultiProcessor implements Processor {
    private final List> processors = new ArrayList<>();

    @SafeVarargs
    public MultiProcessor(Processor... initial) {
        for (Processor p : initial) {
            processors.add(p);
        }
    }

    public void addProcessor(Processor processor) {
        processors.add(processor);
    }

    @Override
    public > X find(Class type) {
        for (Processor p : processors) {
            if (type.isInstance(p)) {
                return type.cast(p);
            }
        }
        return null;
    }

    @Override
    public Processor andThen(Processor next) {
        addProcessor(next);
        return this;
    }

    @Override
    public Processor beforeDo(Processor previous) {
        processors.add(0, previous);
        return this;
    }

    @Override
    public void process(S source, T model) throws Exception {
        for (Processor p : processors) {
            p.process(source, model);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy