Package dev.demeng.pluginbase.delegate
Class Delegates
java.lang.Object
dev.demeng.pluginbase.delegate.Delegates
A collection of utility methods for delegating Java 8 functions.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Supplier<T>callableToSupplier(Callable<T> callable) static <T,U> BiConsumer<T, U> consumerToBiConsumerFirst(Consumer<T> consumer) Wraps aConsumeras aBiConsumerthat applies the consumer to the first argument, ignoring the second.static <T,U> BiConsumer<T, U> consumerToBiConsumerSecond(Consumer<U> consumer) Wraps aConsumeras aBiConsumerthat applies the consumer to the second argument, ignoring the first.static <T,U> Function<T, U> consumerToFunction(Consumer<T> consumer) static <T,U> BiPredicate<T, U> predicateToBiPredicateFirst(Predicate<T> predicate) Wraps aPredicateas aBiPredicatethat tests the first argument, ignoring the second.static <T,U> BiPredicate<T, U> predicateToBiPredicateSecond(Predicate<U> predicate) Wraps aPredicateas aBiPredicatethat tests the second argument, ignoring the first.static <T> Consumer<T>runnableToConsumer(Runnable runnable) static <T,U> Function<T, U> runnableToFunction(Runnable runnable) runnableToSupplier(Runnable runnable) Wraps aRunnableas aSupplier<Void>.
-
Constructor Details
-
Delegates
public Delegates()
-
-
Method Details
-
runnableToConsumer
- Type Parameters:
T- the type of the consumer's argument- Parameters:
runnable- the runnable to wrap- Returns:
- a consumer that delegates to the given runnable
-
runnableToSupplier
- Parameters:
runnable- the runnable to wrap- Returns:
- a supplier that runs the delegate and always returns
null
-
callableToSupplier
Wraps aCallableas aSupplier. Any checked exception thrown by the callable is rethrown wrapped in aBaseException; unchecked exceptions propagate as-is.- Type Parameters:
T- the type of the supplied value- Parameters:
callable- the callable to wrap- Returns:
- a supplier that delegates to the given callable
- Throws:
BaseException- if the callable throws a checked exception
-
consumerToBiConsumerFirst
Wraps aConsumeras aBiConsumerthat applies the consumer to the first argument, ignoring the second.- Type Parameters:
T- the type of the first argumentU- the type of the second argument (ignored)- Parameters:
consumer- the consumer to wrap- Returns:
- a bi-consumer that delegates to the given consumer using the first argument
-
consumerToBiConsumerSecond
Wraps aConsumeras aBiConsumerthat applies the consumer to the second argument, ignoring the first.- Type Parameters:
T- the type of the first argument (ignored)U- the type of the second argument- Parameters:
consumer- the consumer to wrap- Returns:
- a bi-consumer that delegates to the given consumer using the second argument
-
predicateToBiPredicateFirst
Wraps aPredicateas aBiPredicatethat tests the first argument, ignoring the second.- Type Parameters:
T- the type of the first argumentU- the type of the second argument (ignored)- Parameters:
predicate- the predicate to wrap- Returns:
- a bi-predicate that delegates to the given predicate using the first argument
-
predicateToBiPredicateSecond
Wraps aPredicateas aBiPredicatethat tests the second argument, ignoring the first.- Type Parameters:
T- the type of the first argument (ignored)U- the type of the second argument- Parameters:
predicate- the predicate to wrap- Returns:
- a bi-predicate that delegates to the given predicate using the second argument
-
consumerToFunction
- Type Parameters:
T- the type of the function's argumentU- the declared return type of the function (alwaysnullat runtime)- Parameters:
consumer- the consumer to wrap- Returns:
- a function that delegates to the given consumer and always returns
null
-
runnableToFunction
- Type Parameters:
T- the type of the function's argument (ignored)U- the declared return type of the function (alwaysnullat runtime)- Parameters:
runnable- the runnable to wrap- Returns:
- a function that delegates to the given runnable and always returns
null
-