Class Functional


  • public class Functional
    extends java.lang.Object
    Utility 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 a CompletableFuture.
      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 a CompletableFuture.
      static <E> Predicate<E> java8ToGuava​(java.util.function.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.
      static <T> java.util.Set<T> optionalAsSet​(java.util.Optional<T> value)
      Gets the value of an Optional as 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 new Predicate defining whether an Object is contained within the provided Collection.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 accept
        R - 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 accept
        R - 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 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​(java.util.function.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> java.util.Set<T> optionalAsSet​(java.util.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> 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 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> 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 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