org.fiolino.common.processing.sink.ConvertingSink 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;
/**
* Created by kuli on 04.01.16.
*/
public abstract class ConvertingSink extends ChainedSink {
public ConvertingSink(Sink super T> target) {
super(new NullFilterSink<>(target));
}
/**
* Converts the element to another type.
*
* @param element The element that should be added
* @return The new element, or null if it shall be skipped
*/
protected abstract T convert(S element, Container metadata) throws Exception;
@Override
public final void accept(S value, Container metadata) throws Exception {
T newOne = convert(value, metadata);
getTarget().accept(newOne, metadata);
}
}