Class Functions

java.lang.Object
org.wildfly.clustering.cache.function.Functions

public class Functions extends Object
Reusable function implementations.
Author:
Paul Ferraro
  • Method Details

    • whenNullFunction

      public static <T> UnaryOperator<T> whenNullFunction(T replacement)
      Returns a function that replaces a null with the specified value.
      Type Parameters:
      T - the function type
      Parameters:
      replacement - the value
      Returns:
      a function that replaces a null with the specified value.
    • whenNullFunction

      public static <T> UnaryOperator<T> whenNullFunction(Supplier<T> factory)
      Returns a function that replaces a null with the value provided by the specified factory.
      Type Parameters:
      T - the function type
      Parameters:
      factory - the provider of the replacement value
      Returns:
      a function that replaces a null with the value provided by the specified factory.
    • nullOperator

      public static <R> UnaryOperator<R> nullOperator()
      Returns an operator that always returns null, regardless of input.
      Type Parameters:
      R - the operator type
      Returns:
      an operator that always returns null.
    • constantOperator

      public static <R> UnaryOperator<R> constantOperator(R result)
      Returns an operator that always returns a constant result, regardless of input.
      Type Parameters:
      R - the operator type
      Parameters:
      result - the value returned by the constant operator
      Returns:
      an operator that always returns the specified result
    • nullFunction

      public static <T, R> Function<T,R> nullFunction()
      Returns a function that always returns null, regardless of input.
      Type Parameters:
      T - the function parameter type
      R - the function return type
      Returns:
      a function that always returns null.
    • constantFunction

      public static <T, R> Function<T,R> constantFunction(R result)
      Returns a function that always returns a constant result, regardless of input.
      Type Parameters:
      T - the function parameter type
      R - the function return type
      Parameters:
      result - the value to return by the constant function
      Returns:
      a function that always returns the specified result
    • constantIntFunction

      public static <R> IntFunction<R> constantIntFunction(R result)
      Returns a function that always returns a constant result, regardless of input.
      Type Parameters:
      R - the function return type
      Parameters:
      result - the value to return by the constant function
      Returns:
      a function that always returns the specified result
    • constantLongFunction

      public static <R> LongFunction<R> constantLongFunction(R result)
      Returns a function that always returns a constant result, regardless of input.
      Type Parameters:
      R - the function return type
      Parameters:
      result - the value to return by the constant function
      Returns:
      a function that always returns the specified result
    • constantDoubleFunction

      public static <R> DoubleFunction<R> constantDoubleFunction(R result)
      Returns a function that always returns a constant result, regardless of input.
      Type Parameters:
      R - the function return type
      Parameters:
      result - the value to return by the constant function
      Returns:
      a function that always returns the specified result
    • quiet

      public static <T, R, E extends Exception> Function<T,R> quiet(org.wildfly.common.function.ExceptionFunction<T,R,E> function, BiFunction<T,Exception,RuntimeException> exceptionWrapper)
      Converts an ExceptionFunction to a Function, applying the specified exception wrapper on failure.
      Type Parameters:
      T - the function parameter type
      R - the function return type
      E - the function exception type
      Parameters:
      function - the exception function to quiet
      exceptionWrapper - an exception wrapper
      Returns:
      a function.