de.team33.patterns.pooling.ariel.ProviderBase Maven / Gradle / Ivy
Show all versions of pooling-ariel Show documentation
package de.team33.patterns.pooling.ariel;
import de.team33.patterns.exceptional.dione.XConsumer;
import de.team33.patterns.exceptional.dione.XFunction;
import de.team33.patterns.exceptional.dione.XSupplier;
import java.util.function.Consumer;
import java.util.function.Function;
class ProviderBase extends Mutual {
ProviderBase(final XSupplier, RuntimeException> newItem) {
super(newItem);
}
/**
* Runs a given {@link Consumer} with a parameter provided for it. The parameter is kept for future use.
*
* While the {@link Consumer} is being executed, the parameter is exclusively available to it, but must not be
* "hijacked" from the context of the execution or the executing thread!
*/
public final void run(final Consumer super I> consumer) {
accept(consumer::accept);
}
/**
* Runs a given {@link XConsumer} with a parameter provided for it. The parameter is kept for future use.
*
* While the {@link XConsumer} is being executed, the parameter is exclusively available to it, but must not be
* "hijacked" from the context of the execution or the executing thread!
*
* @param A type of exception that may be caused by the given {@link XConsumer}.
* @throws X if the execution of the given {@link XConsumer} causes one.
*/
public final void runEx(final XConsumer super I, X> xConsumer) throws X {
accept(xConsumer);
}
/**
* Calls a given {@link Function} with a parameter provided for it and returns its result.
* The parameter is kept for future use.
*
* While the {@link Function} is being called, the parameter is exclusively available to it, but must not be
* "hijacked" from the context of the call or the executing thread!
*
* @param The result type of the given {@link Function}
*/
public final R get(final Function super I, R> function) {
return apply(function::apply);
}
/**
* Calls a given {@link XFunction} with a parameter provided for it and returns its result.
* The parameter is kept for future use.
*
* While the {@link XFunction} is being called, the parameter is exclusively available to it, but must not be
* "hijacked" from the context of the call or the executing thread!
*
* @param The result type of the given {@link XFunction}
* @param A type of exception that may be caused by the given {@link XFunction}.
* @throws X if the execution of the given {@link XFunction} causes one.
*/
public final R getEx(final XFunction super I, R, X> xFunction) throws X {
return apply(xFunction);
}
}