Class Functional

java.lang.Object
org.spongepowered.api.util.Functional

public class Functional extends Object
Utility methods to help with function work.
  • Method Details

    • 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 accept
      R - 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 accept
      R - 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)
      Creates a new Predicate defining whether an Object is contained within the provided 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 a Predicate based on the provided Predicate, 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 an Optional 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 a CompletableFuture.
      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 a CompletableFuture.
      Type Parameters:
      T - The type of value returned
      Parameters:
      call - The callable to execute
      exec - The executor to execute this task on
      Returns:
      The future holding the result