feat(commons): Add Throwable*.of to create instances from common types
This commit is contained in:
parent
c50bdc95bd
commit
0e15fe3abd
@ -8,6 +8,11 @@ import java.util.function.*;
|
|||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface ThrowingBiConsumer<T, U, TEx extends Throwable> {
|
public interface ThrowingBiConsumer<T, U, TEx extends Throwable> {
|
||||||
|
static <T, U, TEx extends Throwable> @NotNull ThrowingBiConsumer<T, U, TEx> of(@NotNull BiConsumer<T, U> consumer) {
|
||||||
|
Objects.requireNonNull(consumer);
|
||||||
|
return consumer::accept;
|
||||||
|
}
|
||||||
|
|
||||||
void accept(T var1, U var2) throws TEx;
|
void accept(T var1, U var2) throws TEx;
|
||||||
|
|
||||||
@Contract(value = "-> new", pure = true)
|
@Contract(value = "-> new", pure = true)
|
||||||
|
@ -9,6 +9,11 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface ThrowingBiFunction<T, U, R, TEx extends Throwable> {
|
public interface ThrowingBiFunction<T, U, R, TEx extends Throwable> {
|
||||||
|
static <T, U, R, TEx extends Throwable> @NotNull ThrowingBiFunction<T, U, R, TEx> of(@NotNull BiFunction<T, U, R> function) {
|
||||||
|
Objects.requireNonNull(function);
|
||||||
|
return function::apply;
|
||||||
|
}
|
||||||
|
|
||||||
R apply(T var1, U var2) throws TEx;
|
R apply(T var1, U var2) throws TEx;
|
||||||
|
|
||||||
@Contract(value = "-> new", pure = true)
|
@Contract(value = "-> new", pure = true)
|
||||||
|
@ -7,6 +7,11 @@ import java.util.function.*;
|
|||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface ThrowingBooleanSupplier<TEx extends Throwable> {
|
public interface ThrowingBooleanSupplier<TEx extends Throwable> {
|
||||||
|
static <TEx extends Throwable> @NotNull ThrowingBooleanSupplier<TEx> of(@NotNull BooleanSupplier supplier) {
|
||||||
|
Objects.requireNonNull(supplier);
|
||||||
|
return supplier::getAsBoolean;
|
||||||
|
}
|
||||||
|
|
||||||
boolean get() throws TEx;
|
boolean get() throws TEx;
|
||||||
|
|
||||||
@Contract(value = "_ -> new", pure = true)
|
@Contract(value = "_ -> new", pure = true)
|
||||||
|
@ -8,6 +8,11 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface ThrowingConsumer<T, TEx extends Throwable> {
|
public interface ThrowingConsumer<T, TEx extends Throwable> {
|
||||||
|
static <T> @NotNull ThrowingConsumer<T, RuntimeException> of(@NotNull Consumer<T> consumer) {
|
||||||
|
Objects.requireNonNull(consumer);
|
||||||
|
return consumer::accept;
|
||||||
|
}
|
||||||
|
|
||||||
void accept(T var1) throws TEx;
|
void accept(T var1) throws TEx;
|
||||||
|
|
||||||
@Contract(value = "_ -> new", pure = true)
|
@Contract(value = "_ -> new", pure = true)
|
||||||
|
@ -7,6 +7,11 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface ThrowingFunction<T, R, TEx extends Throwable> {
|
public interface ThrowingFunction<T, R, TEx extends Throwable> {
|
||||||
|
static <T, R> @NotNull ThrowingFunction<T, R, RuntimeException> of(@NotNull Function<T, R> function) {
|
||||||
|
Objects.requireNonNull(function);
|
||||||
|
return function::apply;
|
||||||
|
}
|
||||||
|
|
||||||
R apply(T var1) throws TEx;
|
R apply(T var1) throws TEx;
|
||||||
|
|
||||||
@Contract(value = "_ -> new", pure = true)
|
@Contract(value = "_ -> new", pure = true)
|
||||||
|
@ -8,6 +8,11 @@ import java.util.function.Predicate;
|
|||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface ThrowingPredicate<T, TEx extends Throwable> {
|
public interface ThrowingPredicate<T, TEx extends Throwable> {
|
||||||
|
static <T> @NotNull ThrowingPredicate<T, RuntimeException> of(@NotNull Predicate<T> predicate) {
|
||||||
|
Objects.requireNonNull(predicate);
|
||||||
|
return predicate::test;
|
||||||
|
}
|
||||||
|
|
||||||
boolean test(T var1) throws TEx;
|
boolean test(T var1) throws TEx;
|
||||||
|
|
||||||
@Contract(value = "_ -> new", pure = true)
|
@Contract(value = "_ -> new", pure = true)
|
||||||
|
@ -8,6 +8,11 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface ThrowingRunnable<TEx extends Throwable> {
|
public interface ThrowingRunnable<TEx extends Throwable> {
|
||||||
|
static @NotNull ThrowingRunnable<RuntimeException> of(@NotNull Runnable runnable) {
|
||||||
|
Objects.requireNonNull(runnable);
|
||||||
|
return runnable::run;
|
||||||
|
}
|
||||||
|
|
||||||
void run() throws TEx;
|
void run() throws TEx;
|
||||||
|
|
||||||
@Contract(value = "_ -> new", pure = true)
|
@Contract(value = "_ -> new", pure = true)
|
||||||
|
@ -8,6 +8,11 @@ import java.util.function.Supplier;
|
|||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface ThrowingSupplier<T, TEx extends Throwable> {
|
public interface ThrowingSupplier<T, TEx extends Throwable> {
|
||||||
|
static <T> @NotNull ThrowingSupplier<T, RuntimeException> of(@NotNull Supplier<T> supplier) {
|
||||||
|
Objects.requireNonNull(supplier);
|
||||||
|
return supplier::get;
|
||||||
|
}
|
||||||
|
|
||||||
T get() throws TEx;
|
T get() throws TEx;
|
||||||
|
|
||||||
@Contract(value = "_ -> new", pure = true)
|
@Contract(value = "_ -> new", pure = true)
|
||||||
|
Loading…
Reference in New Issue
Block a user