Class FunctionsUtil


  • public final class FunctionsUtil
    extends Object
    This class provides utility methods for Java 8 Function objects (and for the corresponding primitive specializations).
    • Method Detail

      • safeDefault

        public static <T,​R> Function<T,​? extends @Nullable R> safeDefault​(@Nullable Function<T,​R> func)
        Returns a default function if the argument is null. The default function's Function#apply(Object) apply method will always return null. If a non-null function is passed to this method, it is returned as-is.
        Parameters:
        func - the function reference (may be null)
        Returns:
        a non-null object identical to the passed function, if it is non-null, or a function object always returning null otherwise
      • safeDefault

        public static <R> IntFunction<? extends @Nullable R> safeDefault​(@Nullable IntFunction<R> func)
        Returns a default function if the argument is null. The default function's apply method will always return null. If a non-null function is passed to this method, it is returned as-is.
        Parameters:
        func - the function reference (may be null)
        Returns:
        a non-null object identical to the passed function, if it is non-null, or a function object always returning null otherwise
      • safeDefault

        public static <R> BiIntFunction<? extends @Nullable R> safeDefault​(@Nullable BiIntFunction<R> func)
        Returns a default function if the argument is null. The default function's apply method will always return null. If a non-null function is passed to this method, it is returned as-is.
        Parameters:
        func - the function reference (may be null)
        Returns:
        a non-null object identical to the passed function, if it is non-null, or a function object always returning null otherwise