com.fluxtion.runtime.dataflow.helpers.Tuples Maven / Gradle / Ivy
package com.fluxtion.runtime.dataflow.helpers;
import com.fluxtion.runtime.annotations.builder.AssignToField;
import com.fluxtion.runtime.dataflow.Tuple;
import com.fluxtion.runtime.partition.LambdaReflection.SerializableBiFunction;
import com.fluxtion.runtime.partition.LambdaReflection.SerializableFunction;
import lombok.Value;
public class Tuples {
public static > SerializableFunction>
replaceNull(F first, S second) {
return new ReplaceNull<>(first, second)::replaceNull;
}
public static > SerializableFunction
mapTuple(SerializableBiFunction tupleMapFunction) {
return new MapTuple<>(tupleMapFunction)::mapTuple;
}
public static class ReplaceNull {
private final F firstValue;
private final S secondValue;
public ReplaceNull(
@AssignToField("firstValue")
F firstValue,
@AssignToField("secondValue")
S secondValue) {
this.firstValue = firstValue;
this.secondValue = secondValue;
}
public Tuple replaceNull(Tuple extends F, ? extends S> in) {
F first = in.getFirst() == null ? firstValue : in.getFirst();
S second = in.getSecond() == null ? secondValue : in.getSecond();
return Tuple.build(first, second);
}
}
@Value
public static class MapTuple {
SerializableBiFunction tupleMapFunction;
public R mapTuple(Tuple extends F, ? extends S> tuple) {
return tupleMapFunction.apply(tuple.getFirst(), tuple.getSecond());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy