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

org.fiolino.common.processing.sink.FunctionalSink 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.sink;

import org.fiolino.common.container.Container;

import java.util.function.Function;

/**
 * Created by Michael Kuhlmann on 23.12.2015.
 */
public final class FunctionalSink extends ConvertingSink
        implements ThreadsafeSink, CloneableSink> {

    private final Function converter;

    public FunctionalSink(Sink target, Function converter) {
        super(target);
        this.converter = converter;
    }

    @Override
    protected U convert(T element, Container metadata) throws Exception {
        return converter.apply(element);
    }

    @Override
    public void partialCommit(Container metadata) throws Exception {
        if (getTarget() instanceof CloneableSink) {
            ((CloneableSink) getTarget()).partialCommit(metadata);
        }
    }

    @Override
    public FunctionalSink createClone() {
        return new FunctionalSink<>(targetForCloning(getTarget()), converter);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy