org.fiolino.common.processing.sink.FunctionalSink Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons Show documentation
Show all versions of commons Show documentation
General structure to easily create dynamic logic via MethodHandles and others.
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 super U> 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);
}
}