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

io.virtdata.api.composers.ComposerForFunction Maven / Gradle / Ivy

package io.virtdata.api.composers;

import io.virtdata.api.FunctionType;

import java.util.function.*;

public class ComposerForFunction implements FunctionComposer> {

    private final Function inner;

    public ComposerForFunction(Function inner) {
        this.inner = inner;
    }

    @Override
    public Object getFunctionObject() {
        return inner;
    }

    @Override
    @SuppressWarnings("unchecked")
    public FunctionComposer andThen(Object outer) {
        FunctionType functionType = FunctionType.valueOf(outer);
        switch (functionType) {

            case long_long:
                final Function f1 =
                        (Object o) ->
                                ((LongUnaryOperator) outer).applyAsLong(((Function) inner).apply(o));
                return new ComposerForFunction(f1);
            case long_int:
                final Function f3 =
                        (Object o) ->
                                ((LongToIntFunction)outer).applyAsInt(((Function)inner).apply(o));
                return new ComposerForFunction(f3);
            case long_double:
                final Function f4=
                        (Object o) ->
                                ((LongToDoubleFunction)outer).applyAsDouble(((Function)inner).apply(o));
                return new ComposerForFunction(f4);
            case long_T:
                final Function f2 =
                        (Object o) ->
                                ((LongFunction)outer).apply(((Function)inner).apply(o));
                return new ComposerForFunction(f2);
            case R_T:
                final Function f5=
                        (Object o) ->
                                ((Function)outer).apply(((Function)inner).apply(o));
                return new ComposerForFunction(f5);
            case int_int:
                final Function f6=
                        (Object o) ->
                                ((IntUnaryOperator)outer).applyAsInt(((Function)inner).apply(o));
                return new ComposerForFunction(f6);
            case int_long:
                final Function f7 =
                        (Object o) ->
                                ((IntToLongFunction)outer).applyAsLong(((Function)inner).apply(o));
                return new ComposerForFunction(f7);
            case int_double:
                final Function f8 =
                        (Object o) ->
                                ((IntToDoubleFunction)outer).applyAsDouble(((Function)inner).apply(o));
                return new ComposerForFunction(f8);
            case int_T:
                final Function f9 =
                        (Object o) ->
                                ((IntFunction)outer).apply(((Function)inner).apply(o));
                return new ComposerForFunction(f9);
            case double_double:
                final Function f10 =
                        (Object o) -> ((DoubleUnaryOperator)outer).applyAsDouble(((Function)inner).apply(o));
                return new ComposerForFunction(f10);
            case double_int:
                final Function f11 =
                        (Object o) -> ((DoubleToIntFunction)outer).applyAsInt(((Function)inner).apply(o));
                return new ComposerForFunction(f11);
            case double_long:
                final Function f12 =
                        (Object o) -> ((DoubleToLongFunction)outer).applyAsLong(((Function)inner).apply(o));
                return new ComposerForFunction(f12);
            case double_T:
                final Function f13 =
                        (Object o) -> ((DoubleFunction)outer).apply(((Function)inner).apply(o));
                return new ComposerForFunction(f13);
            default:
                throw new RuntimeException(functionType + " is not recognized");

        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy