com.link_intersystems.util.function.FunctionRunnable 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.function.Function;
/**
* Adapts a function call to a {@link Runnable}.
*
* @param
* @param
*/
public class FunctionRunnable implements Runnable {
private R result;
private Function function;
private A argument;
/**
* Constructs a {@link FunctionRunnable} that will call the given function with the provided argument on {@link Runnable#run()}.
*
* @param function the function to be called.
* @param argument the argument to pass.
*/
public FunctionRunnable(Function function, A argument) {
this.function = function;
this.argument = argument;
}
@Override
public void run() {
result = function.apply(argument);
}
/**
* @return the latest result of the called function.
*/
public R getResult() {
return result;
}
}