Package org.spongepowered.api.util
Class Functional
- java.lang.Object
-
- org.spongepowered.api.util.Functional
-
public class Functional extends java.lang.ObjectUtility methods to help with function work.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.util.concurrent.CompletableFuture<T>asyncFailableFuture(java.util.concurrent.Callable<T> call, java.util.concurrent.Executor exec)Execute a callable on the provided executor, capturing the result or any exceptions that may be thrown into aCompletableFuture.static <L,R>
java.util.function.BiPredicate<L,R>biPredicateAnd(java.lang.Iterable<java.util.function.BiPredicate<L,R>> predicates)Perform an AND using an iterable of bi-predicates.static <L,R>
java.util.function.BiPredicate<L,R>biPredicateAnd(java.util.function.BiPredicate<L,R>... predicates)Perform an AND using an array of bi-predicates.static <T> java.util.concurrent.CompletableFuture<T>failableFuture(java.util.concurrent.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(java.util.function.Predicate<E> predicate)Creates aPredicatebased on the providedPredicate, used to transform between Java 8 specific code to those from the guava library.static <T> java.util.Set<T>optionalAsSet(java.util.Optional<T> value)Gets the value of anOptionalas either a zero- or one-element immutable set.static <E> java.util.function.Predicate<E>predicateAnd(java.lang.Iterable<java.util.function.Predicate<E>> predicates)Perform an AND using an iterable of predicates.static <E> java.util.function.Predicate<E>predicateAnd(java.util.function.Predicate<E>... predicates)Perform an AND using an array of predicates.static <E> java.util.function.Predicate<E>predicateIn(java.util.Collection<E> collection)Creates a newPredicatedefining whether anObjectis contained within the providedCollection.
-
-
-
Method Detail
-
predicateAnd
@SafeVarargs public static <E> java.util.function.Predicate<E> predicateAnd(java.util.function.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> java.util.function.Predicate<E> predicateAnd(java.lang.Iterable<java.util.function.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> java.util.function.BiPredicate<L,R> biPredicateAnd(java.util.function.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> java.util.function.BiPredicate<L,R> biPredicateAnd(java.lang.Iterable<java.util.function.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> java.util.function.Predicate<E> predicateIn(java.util.Collection<E> collection)
Creates a newPredicatedefining whether anObjectis contained within the providedCollection.- Type Parameters:
E- The type of object- Parameters:
collection- The collection- Returns:
- The predicate
-
java8ToGuava
public static <E> Predicate<E> java8ToGuava(java.util.function.Predicate<E> predicate)
Creates aPredicatebased 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> java.util.Set<T> optionalAsSet(java.util.Optional<T> value)
Gets the value of anOptionalas 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> java.util.concurrent.CompletableFuture<T> failableFuture(java.util.concurrent.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> java.util.concurrent.CompletableFuture<T> asyncFailableFuture(java.util.concurrent.Callable<T> call, java.util.concurrent.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
-
-