Package org.spongepowered.api.util
Class Functional
java.lang.Object
org.spongepowered.api.util.Functional
Utility methods to help with function work.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> CompletableFuture<T>
asyncFailableFuture
(Callable<T> call, Executor exec) Execute a callable on the provided executor, capturing the result or any exceptions that may be thrown into aCompletableFuture
.static <L,
R> BiPredicate<L, R> biPredicateAnd
(Iterable<BiPredicate<L, R>> predicates) Perform an AND using an iterable of bi-predicates.static <L,
R> BiPredicate<L, R> biPredicateAnd
(BiPredicate<L, R>... predicates) Perform an AND using an array of bi-predicates.static <T> CompletableFuture<T>
failableFuture
(Callable<T> call) Execute a callable on the current thread, capturing the result or any exceptions that may be thrown into aCompletableFuture
.static <E> Predicate<E>
java8ToGuava
(Predicate<E> predicate) static <T> Set<T>
optionalAsSet
(Optional<T> value) Gets the value of anOptional
as either a zero- or one-element immutable set.static <E> Predicate<E>
predicateAnd
(Iterable<Predicate<E>> predicates) Perform an AND using an iterable of predicates.static <E> Predicate<E>
predicateAnd
(Predicate<E>... predicates) Perform an AND using an array of predicates.static <E> Predicate<E>
predicateIn
(Collection<E> collection)
-
Method Details
-
predicateAnd
Perform an AND using an array of predicates.- Type Parameters:
E
- The type to accept- Parameters:
predicates
- The predicates to AND- Returns:
- The combined predicate
-
predicateAnd
Perform an AND using an iterable of predicates.- Type Parameters:
E
- The type to accept- Parameters:
predicates
- The predicates to and- Returns:
- The combined predicate
-
biPredicateAnd
Perform an AND using an array of bi-predicates.- Type Parameters:
L
- The left type to acceptR
- The right type to accept- Parameters:
predicates
- The bi-predicates to AND- Returns:
- The combined bi-predicate
-
biPredicateAnd
Perform an AND using an iterable of bi-predicates.- Type Parameters:
L
- The left type to acceptR
- The right type to accept- Parameters:
predicates
- The bi-predicates to and- Returns:
- The combined bi-predicate
-
predicateIn
- Type Parameters:
E
- The type of object- Parameters:
collection
- The collection- Returns:
- The predicate
-
java8ToGuava
Creates aPredicate
based on the providedPredicate
, used to transform between Java 8 specific code to those from the guava library.- Type Parameters:
E
- The type of object- Parameters:
predicate
- The predicate- Returns:
- The guava predicate
-
optionalAsSet
Gets the value of anOptional
as either a zero- or one-element immutable set.- Type Parameters:
T
- The type- Parameters:
value
- The value to get as a set- Returns:
- The immutable set containing any value the optional has
-
failableFuture
Execute a callable on the current thread, capturing the result or any exceptions that may be thrown into aCompletableFuture
.- Type Parameters:
T
- The type of value returned- Parameters:
call
- The callable to execute- Returns:
- The future holding the result
-
asyncFailableFuture
Execute a callable on the provided executor, capturing the result or any exceptions that may be thrown into aCompletableFuture
.- Type Parameters:
T
- The type of value returned- Parameters:
call
- The callable to executeexec
- The executor to execute this task on- Returns:
- The future holding the result
-