Class Functions


  • public final class Functions
    extends java.lang.Object
    Utility methods to convert the BiFunction, Function3..Function9 instances to Function of Object array.
    • Field Detail

      • IDENTITY

        static final Function<java.lang.Object,​java.lang.Object> IDENTITY
        A singleton identity function.
      • EMPTY_RUNNABLE

        public static final java.lang.Runnable EMPTY_RUNNABLE
      • EMPTY_ACTION

        public static final Action EMPTY_ACTION
      • EMPTY_CONSUMER

        static final Consumer<java.lang.Object> EMPTY_CONSUMER
      • ERROR_CONSUMER

        public static final Consumer<java.lang.Throwable> ERROR_CONSUMER
      • ON_ERROR_MISSING

        public static final Consumer<java.lang.Throwable> ON_ERROR_MISSING
        Wraps the consumed Throwable into an OnErrorNotImplementedException and signals it to the plugin error handler.
      • EMPTY_LONG_CONSUMER

        public static final LongConsumer EMPTY_LONG_CONSUMER
      • ALWAYS_TRUE

        static final Predicate<java.lang.Object> ALWAYS_TRUE
      • ALWAYS_FALSE

        static final Predicate<java.lang.Object> ALWAYS_FALSE
      • NULL_SUPPLIER

        static final Supplier<java.lang.Object> NULL_SUPPLIER
      • REQUEST_MAX

        public static final Consumer<org.reactivestreams.Subscription> REQUEST_MAX
    • Constructor Detail

      • Functions

        private Functions()
        Utility class.
    • Method Detail

      • identity

        @NonNull
        public static <T> @NonNull Function<T,​T> identity()
        Returns an identity function that simply returns its argument.
        Type Parameters:
        T - the input and output value type
        Returns:
        the identity function
      • emptyConsumer

        public static <T> Consumer<T> emptyConsumer()
        Returns an empty consumer that does nothing.
        Type Parameters:
        T - the consumed value type, the value is ignored
        Returns:
        an empty consumer that does nothing.
      • futureAction

        @NonNull
        public static @NonNull Action futureAction​(@NonNull
                                                   @NonNull java.util.concurrent.Future<?> future)
        Wraps the blocking get call of the Future into an Action.
        Parameters:
        future - the future to call get() on, not null
        Returns:
        the new Action instance
      • justCallable

        @NonNull
        public static <T> @NonNull java.util.concurrent.Callable<T> justCallable​(@NonNull
                                                                                 T value)
        Returns a Callable that returns the given value.
        Type Parameters:
        T - the value type
        Parameters:
        value - the value to return
        Returns:
        the new Callable instance
      • justSupplier

        @NonNull
        public static <T> @NonNull Supplier<T> justSupplier​(@NonNull
                                                            T value)
        Returns a Supplier that returns the given value.
        Type Parameters:
        T - the value type
        Parameters:
        value - the value to return
        Returns:
        the new Callable instance
      • justFunction

        @NonNull
        public static <T,​U> @NonNull Function<T,​U> justFunction​(@NonNull
                                                                            U value)
        Returns a Function that ignores its parameter and returns the given value.
        Type Parameters:
        T - the function's input type
        U - the value and return type of the function
        Parameters:
        value - the value to return
        Returns:
        the new Function instance
      • castFunction

        @NonNull
        public static <T,​U> @NonNull Function<T,​U> castFunction​(@NonNull
                                                                            @NonNull java.lang.Class<U> target)
        Returns a function that cast the incoming values via a Class object.
        Type Parameters:
        T - the input value type
        U - the output and target type
        Parameters:
        target - the target class
        Returns:
        the new Function instance
      • createArrayList

        public static <T> Supplier<java.util.List<T>> createArrayList​(int capacity)
      • equalsWith

        public static <T> Predicate<T> equalsWith​(T value)
      • createHashSet

        public static <T> Supplier<java.util.Set<T>> createHashSet()
      • notificationOnError

        public static <T> Consumer<java.lang.Throwable> notificationOnError​(Consumer<? super Notification<T>> onNotification)
      • actionConsumer

        public static <T> Consumer<T> actionConsumer​(Action action)
      • isInstanceOf

        public static <T,​U> Predicate<T> isInstanceOf​(java.lang.Class<U> clazz)
      • timestampWith

        public static <T> Function<T,​Timed<T>> timestampWith​(java.util.concurrent.TimeUnit unit,
                                                                   Scheduler scheduler)
      • toMapKeySelector

        public static <T,​K> BiConsumer<java.util.Map<K,​T>,​T> toMapKeySelector​(Function<? super T,​? extends K> keySelector)
      • toMapKeyValueSelector

        public static <T,​K,​V> BiConsumer<java.util.Map<K,​V>,​T> toMapKeyValueSelector​(Function<? super T,​? extends K> keySelector,
                                                                                                             Function<? super T,​? extends V> valueSelector)
      • toMultimapKeyValueSelector

        public static <T,​K,​V> BiConsumer<java.util.Map<K,​java.util.Collection<V>>,​T> toMultimapKeyValueSelector​(Function<? super T,​? extends K> keySelector,
                                                                                                                                        Function<? super T,​? extends V> valueSelector,
                                                                                                                                        Function<? super K,​? extends java.util.Collection<? super V>> collectionFactory)
      • naturalComparator

        public static <T> java.util.Comparator<T> naturalComparator()
      • listSorter

        public static <T> Function<java.util.List<T>,​java.util.List<T>> listSorter​(java.util.Comparator<? super T> comparator)
      • boundedConsumer

        public static <T> Consumer<T> boundedConsumer​(int bufferSize)