Class Functions


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

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T,​U>
      java.lang.Runnable
      capturingRunnable​(java.util.function.BiConsumer<T,​U> consumer, T param1, U param2)
      Get a runnable which executes the given consumer with captured values.
      static <T> java.lang.Runnable capturingRunnable​(java.util.function.Consumer<T> consumer, T param)
      Get a runnable which executes the given consumer with captured values.
      static <T,​E extends java.lang.Exception>
      ExceptionSupplier<T,​E>
      constantExceptionSupplier​(T value)
      Get a supplier which always returns the same value.
      static <T> java.util.function.Supplier<T> constantSupplier​(T value)
      Get a supplier which always returns the same value.
      static <T> java.util.function.BiConsumer<java.util.function.Consumer<T>,​T> consumerBiConsumer()
      Get the singleton consumer which accepts a consumer and an argument to hand to it.
      static <T> ExceptionBiConsumer<java.util.function.Consumer<T>,​T,​java.lang.RuntimeException> consumerExceptionBiConsumer()
      Get the singleton consumer which accepts a consumer and an argument to hand to it.
      static <T,​U>
      java.util.function.BiConsumer<T,​U>
      discardingBiConsumer()
      Get a consumer which discards the values it is given.
      static <T> java.util.function.Consumer<T> discardingConsumer()
      Get a consumer which discards the values it is given.
      static <T,​U,​E extends java.lang.Exception>
      ExceptionBiConsumer<T,​U,​E>
      discardingExceptionBiConsumer()
      Get a consumer which discards the values it is given.
      static <T,​E extends java.lang.Exception>
      ExceptionConsumer<T,​E>
      discardingExceptionConsumer()
      Get a consumer which discards the values it is given.
      static <T,​U,​E extends java.lang.Exception>
      ExceptionRunnable<E>
      exceptionCapturingRunnable​(ExceptionBiConsumer<T,​U,​E> consumer, T param1, U param2)
      Get a runnable which executes the given consumer with captured values.
      static <T,​E extends java.lang.Exception>
      ExceptionRunnable<E>
      exceptionCapturingRunnable​(ExceptionConsumer<T,​E> consumer, T param)
      Get a runnable which executes the given consumer with captured values.
      static <T,​E extends java.lang.Exception>
      ExceptionBiConsumer<ExceptionConsumer<T,​E>,​T,​E>
      exceptionConsumerBiConsumer()
      Get the singleton consumer which accepts a consumer and an argument to hand to it.
      static <T,​R,​E extends java.lang.Exception>
      ExceptionBiFunction<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.
      static <E extends java.lang.Exception>
      ExceptionConsumer<ExceptionRunnable<E>,​E>
      exceptionRunnableConsumer()
      Get the singleton exception consumer which accepts and runs exception runnable instances.
      static <R,​E extends java.lang.Exception>
      ExceptionFunction<ExceptionSupplier<R,​E>,​R,​E>
      exceptionSupplierFunction()
      Get the singleton function which accepts a supplier and returns the result of the supplier.
      static <R,​E extends java.lang.Exception>
      ExceptionBiFunction<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.
      static <T,​R>
      java.util.function.BiFunction<java.util.function.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.
      static <T,​R>
      ExceptionBiFunction<java.util.function.Function<T,​R>,​T,​R,​java.lang.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.
      static java.util.function.Consumer<java.lang.Runnable> runnableConsumer()
      Get the singleton consumer which accepts and runs runnable instances.
      static ExceptionConsumer<java.lang.Runnable,​java.lang.RuntimeException> runnableExceptionConsumer()
      Get the singleton exception consumer which accepts and runs runnable instances.
      static <R> ExceptionFunction<java.util.function.Supplier<R>,​R,​java.lang.RuntimeException> supplierExceptionFunction()
      Get the singleton function which accepts a supplier and returns the result of the supplier.
      static <R> java.util.function.Function<java.util.function.Supplier<R>,​R> supplierFunction()
      Get the singleton function which accepts a supplier and returns the result of the supplier.
      static <R> java.util.function.BiFunction<java.util.function.Function<java.util.function.Supplier<R>,​R>,​java.util.function.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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • runnableConsumer

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

        public static <E extends java.lang.Exception> ExceptionConsumer<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<java.lang.Runnable,​java.lang.RuntimeException> runnableExceptionConsumer()
        Get the singleton exception consumer which accepts and runs runnable instances.
        Returns:
        the runnable consumer
      • consumerBiConsumer

        public static <T> java.util.function.BiConsumer<java.util.function.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 java.lang.Exception> ExceptionBiConsumer<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<java.util.function.Consumer<T>,​T,​java.lang.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> java.util.function.Function<java.util.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 java.lang.Exception> ExceptionFunction<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<java.util.function.Supplier<R>,​R,​java.lang.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> java.util.function.BiFunction<java.util.function.Function<java.util.function.Supplier<R>,​R>,​java.util.function.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 java.lang.Exception> ExceptionBiFunction<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> java.util.function.BiFunction<java.util.function.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 java.lang.Exception> ExceptionBiFunction<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<java.util.function.Function<T,​R>,​T,​R,​java.lang.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> java.util.function.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 java.lang.Exception> ExceptionSupplier<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> java.lang.Runnable capturingRunnable​(java.util.function.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> java.lang.Runnable capturingRunnable​(java.util.function.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 java.lang.Exception> ExceptionRunnable<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 java.lang.Exception> ExceptionRunnable<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> java.util.function.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 java.lang.Exception> ExceptionConsumer<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> java.util.function.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 java.lang.Exception> ExceptionBiConsumer<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