Class Functions


  • public class Functions
    extends Object
    Utilities for working with Java functions.
    • Constructor Detail

      • Functions

        public Functions()
    • Method Detail

      • requireNonNull

        public static <T> T requireNonNull​(Class<T> type,
                                           T value)
        Require an instance not to be null, using the (simple) name of the required type as an error message if it is.
        Type Parameters:
        T - the type.
        Parameters:
        type - the required type.
        value - the value that must not be null.
        Returns:
        the value, that is guaranteed not to be null.
        See Also:
        Objects.requireNonNull(Object, Supplier)
      • map

        public static <I,​O> Supplier<O> map​(Supplier<I> source,
                                                  Function<I,​O> map)
        Convert the value supplied by a Supplier by passing it through a Function.
        Type Parameters:
        I - the type of the value supplied by the original supplier.
        O - the type of the value supplied by the resulting supplier.
        Parameters:
        source - the source supplier that supplies the original value.
        map - the function that converts the value of the original supplier.
        Returns:
        a converting supplier.
      • map

        @SafeVarargs
        public static <K,​V> Map<K,​V> map​(Function<V,​K> key,
                                                     V... values)
        Create a Map by applying a function that extracts the key from an array of values.
        Type Parameters:
        K - the type of the keys.
        V - the type of the values.
        Parameters:
        key - the key extraction function.
        values - the values of the map (from which the keys are extracted).
        Returns:
        a Map from the keys of the values to the values.
      • identity

        public static <T> T identity​(T value)
        A method that is useful as a method reference to implement an identity function.
        Type Parameters:
        T - the type of the value.
        Parameters:
        value - the input (and output) value of the function.
        Returns:
        the value that was passed in.
      • map

        public static <K,​V> Map<K,​V> map​(Collection<V> values,
                                                     Function<V,​K> key)
        Create a Map by applying a function that extracts the key from a collection of values.
        Type Parameters:
        K - the type of the keys.
        V - the type of the values.
        Parameters:
        values - the values of the map (from which the keys are extracted).
        key - the key extraction function.
        Returns:
        a Map from the keys of the values to the values.
      • flatList

        public static <T> Collector<Optional<T>,​List<T>,​List<T>> flatList()
        A Collector that collects optional values to a list. The collector only collects values that are present.
        Type Parameters:
        T - the type of values to collect.
        Returns:
        a collector that collects optional values to a list.