io.atleon.core.Contextual Maven / Gradle / Ivy
package io.atleon.core;
import java.util.function.Supplier;
/**
* An object that may have some context associated with it.
*/
public interface Contextual {
/**
* Invoke the given {@link Runnable} while managing context around its invocation.
*
* @param runnable The {@link Runnable} to invoke
*/
default void runInContext(Runnable runnable) {
runnable.run();
}
/**
* Invoke the given {@link Supplier} while managing context around its invocation.
*
* @param supplier A {@link Supplier} to invoke
* @param The type of result produced by the {@link Supplier}
* @return The value resulting from invoking the {@link Supplier}
*/
default R supplyInContext(Supplier supplier) {
return supplier.get();
}
}