com.link_intersystems.util.function.FunctionExecutor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lis-commons-util Show documentation
Show all versions of lis-commons-util Show documentation
Link Intersystems Commons Util (lis-commons-util) is collection of reusable software components
that extend the standard java.util components.
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();
}
}