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

com.link_intersystems.util.function.FunctionExecutor Maven / Gradle / Ivy

Go to download

There is a newer version: 1.9.7
Show newest version
package com.link_intersystems.util.function;

import java.util.concurrent.Callable;
import java.util.function.*;

public interface FunctionExecutor {

    public void exec(Runnable r);

    public default  R exec(Function function, Supplier paramSupplier) {
        return execAdapter(function).apply(paramSupplier.get());
    }

    public default  Function execAdapter(Function function) {

        return t -> {
            FunctionRunnable functionRunnable = new FunctionRunnable<>(function, t);
            exec(functionRunnable);
            return functionRunnable.getResult();
        };
    }

    public default  R exec(BiFunction function, T arg1, U arg2) {
        BiFunctionRunnable functionRunnable = new BiFunctionRunnable<>(function, arg1, arg2);
        exec(functionRunnable);
        return functionRunnable.getResult();
    }

    public default  void exec(BiConsumer consumer, T arg1, U arg2) {
        exec(() -> consumer.accept(arg1, arg2));
    }

    public default  void exec(Consumer consumer, T arg) {
        exec(() -> consumer.accept(arg));
    }

    public default  V exec(Callable callable) {
        CallableRunnable callableRunnable = new CallableRunnable(callable);
        exec(callableRunnable);
        return callableRunnable.getResult();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy