Package org.spongepowered.api.util
Class Functional
- java.lang.Object
-
- org.spongepowered.api.util.Functional
-
public class Functional extends Object
Utility methods to help with function work.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <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 Detail
-
predicateAnd
@SafeVarargs public static <E> Predicate<E> predicateAnd(Predicate<E>... predicates)
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
public static <E> Predicate<E> predicateAnd(Iterable<Predicate<E>> predicates)
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
@SafeVarargs public static <L,R> BiPredicate<L,R> biPredicateAnd(BiPredicate<L,R>... predicates)
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
public static <L,R> BiPredicate<L,R> biPredicateAnd(Iterable<BiPredicate<L,R>> predicates)
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
public static <E> Predicate<E> predicateIn(Collection<E> collection)
- Type Parameters:
E
- The type of object- Parameters:
collection
- The collection- Returns:
- The predicate
-
java8ToGuava
public static <E> Predicate<E> java8ToGuava(Predicate<E> predicate)
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
public static <T> Set<T> optionalAsSet(Optional<T> value)
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
public 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
.- Type Parameters:
T
- The type of value returned- Parameters:
call
- The callable to execute- Returns:
- The future holding the result
-
asyncFailableFuture
public static <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
.- 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
-
-