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

com.fluxtion.runtime.dataflow.helpers.Tuples Maven / Gradle / Ivy

There is a newer version: 9.7.4
Show newest version
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 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 tuple) {
            return tupleMapFunction.apply(tuple.getFirst(), tuple.getSecond());
        }

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy