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

com.link_intersystems.util.function.FunctionRunnable 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.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;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy