Class Functions


  • public final class Functions
    extends Object
    A set of utility methods which return common functions.
    • Method Detail

      • runnableConsumer

        public static Consumer<Runnable> runnableConsumer()
        Get the singleton consumer which accepts and runs runnable instances.
        Returns:
        the runnable consumer
      • exceptionRunnableConsumer

        public static <E extends ExceptionExceptionConsumer<ExceptionRunnable<E>,​E> exceptionRunnableConsumer()
        Get the singleton exception consumer which accepts and runs exception runnable instances.
        Type Parameters:
        E - the exception type
        Returns:
        the runnable consumer
      • runnableExceptionConsumer

        public static ExceptionConsumer<Runnable,​RuntimeException> runnableExceptionConsumer()
        Get the singleton exception consumer which accepts and runs runnable instances.
        Returns:
        the runnable consumer
      • consumerBiConsumer

        public static <T> BiConsumer<Consumer<T>,​T> consumerBiConsumer()
        Get the singleton consumer which accepts a consumer and an argument to hand to it.
        Type Parameters:
        T - the argument type
        Returns:
        the consumer
      • exceptionConsumerBiConsumer

        public static <T,​E extends ExceptionExceptionBiConsumer<ExceptionConsumer<T,​E>,​T,​E> exceptionConsumerBiConsumer()
        Get the singleton consumer which accepts a consumer and an argument to hand to it.
        Type Parameters:
        T - the argument type
        E - the exception type
        Returns:
        the consumer
      • consumerExceptionBiConsumer

        public static <T> ExceptionBiConsumer<Consumer<T>,​T,​RuntimeException> consumerExceptionBiConsumer()
        Get the singleton consumer which accepts a consumer and an argument to hand to it.
        Type Parameters:
        T - the argument type
        Returns:
        the consumer
      • supplierFunction

        public static <R> Function<Supplier<R>,​R> supplierFunction()
        Get the singleton function which accepts a supplier and returns the result of the supplier.
        Type Parameters:
        R - the result type
        Returns:
        the function
      • exceptionSupplierFunction

        public static <R,​E extends ExceptionExceptionFunction<ExceptionSupplier<R,​E>,​R,​E> exceptionSupplierFunction()
        Get the singleton function which accepts a supplier and returns the result of the supplier.
        Type Parameters:
        R - the result type
        E - the exception type
        Returns:
        the function
      • supplierExceptionFunction

        public static <R> ExceptionFunction<Supplier<R>,​R,​RuntimeException> supplierExceptionFunction()
        Get the singleton function which accepts a supplier and returns the result of the supplier.
        Type Parameters:
        R - the result type
        Returns:
        the function
      • supplierFunctionBiFunction

        public static <R> BiFunction<Function<Supplier<R>,​R>,​Supplier<R>,​R> supplierFunctionBiFunction()
        Get the singleton function which accepts a function which accepts a supplier, all of which return the result of the supplier.
        Type Parameters:
        R - the result type
        Returns:
        the function
      • exceptionSupplierFunctionBiFunction

        public static <R,​E extends ExceptionExceptionBiFunction<ExceptionFunction<ExceptionSupplier<R,​E>,​R,​E>,​ExceptionSupplier<R,​E>,​R,​E> exceptionSupplierFunctionBiFunction()
        Get the singleton function which accepts a function which accepts a supplier, all of which return the result of the supplier.
        Type Parameters:
        R - the result type
        E - the exception type
        Returns:
        the function
      • functionBiFunction

        public static <T,​R> BiFunction<Function<T,​R>,​T,​R> functionBiFunction()
        Get the singleton function which accepts a function and a parameter to pass to the function, and returns the result of the function.
        Type Parameters:
        T - the argument type
        R - the result type
        Returns:
        the function
      • exceptionFunctionBiFunction

        public static <T,​R,​E extends ExceptionExceptionBiFunction<ExceptionFunction<T,​R,​E>,​T,​R,​E> exceptionFunctionBiFunction()
        Get the singleton function which accepts a function and a parameter to pass to the function, and returns the result of the function.
        Type Parameters:
        T - the argument type
        R - the result type
        E - the exception type
        Returns:
        the function
      • functionExceptionBiFunction

        public static <T,​R> ExceptionBiFunction<Function<T,​R>,​T,​R,​RuntimeException> functionExceptionBiFunction()
        Get the singleton function which accepts a function and a parameter to pass to the function, and returns the result of the function.
        Type Parameters:
        T - the argument type
        R - the result type
        Returns:
        the function
      • constantSupplier

        public static <T> Supplier<T> constantSupplier​(T value)
        Get a supplier which always returns the same value.
        Type Parameters:
        T - the value type
        Parameters:
        value - the value to return
        Returns:
        the value supplier
      • constantExceptionSupplier

        public static <T,​E extends ExceptionExceptionSupplier<T,​E> constantExceptionSupplier​(T value)
        Get a supplier which always returns the same value.
        Type Parameters:
        T - the value type
        E - the exception type
        Parameters:
        value - the value to return
        Returns:
        the value supplier
      • capturingRunnable

        public static <T,​U> Runnable capturingRunnable​(BiConsumer<T,​U> consumer,
                                                             T param1,
                                                             U param2)
        Get a runnable which executes the given consumer with captured values.
        Type Parameters:
        T - the first parameter type
        U - the second parameter type
        Parameters:
        consumer - the consumer to run (must not be null)
        param1 - the first parameter to pass
        param2 - the second parameter to pass
        Returns:
        the capturing runnable
      • capturingRunnable

        public static <T> Runnable capturingRunnable​(Consumer<T> consumer,
                                                     T param)
        Get a runnable which executes the given consumer with captured values.
        Type Parameters:
        T - the parameter type
        Parameters:
        consumer - the consumer to run (must not be null)
        param - the parameter to pass
        Returns:
        the capturing runnable
      • exceptionCapturingRunnable

        public static <T,​U,​E extends ExceptionExceptionRunnable<E> exceptionCapturingRunnable​(ExceptionBiConsumer<T,​U,​E> consumer,
                                                                                                            T param1,
                                                                                                            U param2)
        Get a runnable which executes the given consumer with captured values.
        Type Parameters:
        T - the first parameter type
        U - the second parameter type
        E - the exception type
        Parameters:
        consumer - the consumer to run (must not be null)
        param1 - the first parameter to pass
        param2 - the second parameter to pass
        Returns:
        the capturing runnable
      • exceptionCapturingRunnable

        public static <T,​E extends ExceptionExceptionRunnable<E> exceptionCapturingRunnable​(ExceptionConsumer<T,​E> consumer,
                                                                                                    T param)
        Get a runnable which executes the given consumer with captured values.
        Type Parameters:
        T - the parameter type
        E - the exception type
        Parameters:
        consumer - the consumer to run (must not be null)
        param - the parameter to pass
        Returns:
        the capturing runnable
      • discardingConsumer

        public static <T> Consumer<T> discardingConsumer()
        Get a consumer which discards the values it is given.
        Type Parameters:
        T - the parameter type
        Returns:
        the discarding consumer
      • discardingExceptionConsumer

        public static <T,​E extends ExceptionExceptionConsumer<T,​E> discardingExceptionConsumer()
        Get a consumer which discards the values it is given.
        Type Parameters:
        T - the parameter type
        E - the exception type
        Returns:
        the discarding consumer
      • discardingBiConsumer

        public static <T,​U> BiConsumer<T,​U> discardingBiConsumer()
        Get a consumer which discards the values it is given.
        Type Parameters:
        T - the first parameter type
        U - the second parameter type
        Returns:
        the discarding consumer
      • discardingExceptionBiConsumer

        public static <T,​U,​E extends ExceptionExceptionBiConsumer<T,​U,​E> discardingExceptionBiConsumer()
        Get a consumer which discards the values it is given.
        Type Parameters:
        T - the first parameter type
        U - the second parameter type
        E - the exception type
        Returns:
        the discarding consumer