Interface Function<T,R>

Type Parameters:
T - the function parameter type
R - the function return type
All Superinterfaces:
Function<T,R>
All Known Subinterfaces:
UnaryOperator<T>
All Known Implementing Classes:
CacheFactory, SessionAttributeActivationNotifierFactory

public interface Function<T,R> extends Function<T,R>
An enhanced function.
Author:
Paul Ferraro
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Function<?,?>
    An identity function that always returns its parameter
    static final Function<?,?>
    A function that always returns null.
  • Method Summary

    Modifier and Type
    Method
    Description
    default <V> Function<T,V>
    andThen(Function<? super R, ? extends V> after)
     
    default <V> Function<V,R>
    compose(Function<? super V, ? extends T> before)
     
    default <V1,V2> BiFunction<V1,V2,R>
    compose(BiFunction<V1,V2,T> mapper)
    Composes a binary function that invokes this function using result of the specified binary function.
    static <T,R> Function<T,R>
    Returns a function that returns its parameter.
    static <K,V,KR,VR>
    Function<Map.Entry<K,V>, Map.Entry<KR,VR>>
    entry(Function<K,KR> keyFunction, Function<V,VR> valueFunction)
    Returns a Map.Entry function from the specified key and value functions.
    default Function<T,R>
    Returns a new function that delegates to this function using the specified exception handler.
    static <T extends R, R>
    Function<T,R>
    Returns a function that returns its parameter.
    static <T,R> Function<T,R>
    of(Consumer<T> consumer, Supplier<R> supplier)
    Returns a function that accepts its parameter via the specified consumer and returns the value returned by the specified supplier.
    static <T,R> Function<T,R>
    of(R result)
    Returns a function that always returns the specified value, ignoring its parameter.
    Returns an optional function that applies this function to an optional value.
    default Function<T,R>
    orDefault(Predicate<T> predicate, Supplier<R> defaultResult)
    Returns a function that applies this function if its parameter matches the specified predicate, or returns the value provided by the specified supplier otherwise.
    default Function<T,R>
    withDefault(Predicate<T> predicate, Supplier<T> defaultValue)
    Returns a function that applies this function to the value returned by the specified provider if its value does not match the specified predicate.
    default <M> Function<T,R>
    withMonitor(Function<T,M> monitorFunction)
    Returns a new function that applies this function while holding the monitor returned by the specified function.

    Methods inherited from interface Function

    apply
  • Field Details

    • IDENTITY

      static final Function<?,?> IDENTITY
      An identity function that always returns its parameter
    • NULL

      static final Function<?,?> NULL
      A function that always returns null.
  • Method Details

    • compose

      default <V> Function<V,R> compose(Function<? super V, ? extends T> before)
      Specified by:
      compose in interface Function<T,R>
    • compose

      default <V1,V2> BiFunction<V1,V2,R> compose(BiFunction<V1,V2,T> mapper)
      Composes a binary function that invokes this function using result of the specified binary function.
      Type Parameters:
      V1 - the former parameter type
      V2 - the latter parameter type
      Parameters:
      mapper - a mapping function
      Returns:
      a binary function that invokes this function using result of the specified binary function.
    • andThen

      default <V> Function<T,V> andThen(Function<? super R, ? extends V> after)
      Specified by:
      andThen in interface Function<T,R>
    • withDefault

      default Function<T,R> withDefault(Predicate<T> predicate, Supplier<T> defaultValue)
      Returns a function that applies this function to the value returned by the specified provider if its value does not match the specified predicate.
      Parameters:
      predicate - a predicate used to determine the parameter of this function
      defaultValue - a provider of the default parameter value
      Returns:
      a function that applies this function to the value returned by the specified provider if its value does not match the specified predicate.
    • orDefault

      default Function<T,R> orDefault(Predicate<T> predicate, Supplier<R> defaultResult)
      Returns a function that applies this function if its parameter matches the specified predicate, or returns the value provided by the specified supplier otherwise.
      Parameters:
      predicate - a predicate used to determine the parameter of this function
      defaultResult - a provider of the default parameter value
      Returns:
      a function that applies this function if its parameter matches the specified predicate, or returns the value provided by the specified supplier otherwise.
    • handle

      default Function<T,R> handle(BiFunction<T, RuntimeException, R> handler)
      Returns a new function that delegates to this function using the specified exception handler.
      Parameters:
      handler - an exception handler
      Returns:
      a new function that delegates to this function using the specified exception handler.
    • optional

      default Function<Optional<T>, Optional<R>> optional()
      Returns an optional function that applies this function to an optional value.
      Returns:
      an optional function that applies this function to an optional value.
    • withMonitor

      default <M> Function<T,R> withMonitor(Function<T,M> monitorFunction)
      Returns a new function that applies this function while holding the monitor returned by the specified function.
      Type Parameters:
      M - a function returning an object monitor
      Parameters:
      monitorFunction - a function returning an object monitor.
      Returns:
      a new function that applies this function while holding the monitor returned by the specified function.
    • identity

      static <T extends R, R> Function<T,R> identity()
      Returns a function that returns its parameter.
      Type Parameters:
      T - the function parameter type
      R - the function return type
      Returns:
      an identity function
    • empty

      static <T,R> Function<T,R> empty()
      Returns a function that returns its parameter.
      Type Parameters:
      T - the function parameter type
      R - the function return type
      Returns:
      an identity function
    • of

      static <T,R> Function<T,R> of(R result)
      Returns a function that always returns the specified value, ignoring its parameter.
      Type Parameters:
      T - the function parameter type
      R - the function return type
      Parameters:
      result - the function result
      Returns:
      a function that always returns the specified value, ignoring its parameter.
    • of

      static <T,R> Function<T,R> of(Consumer<T> consumer, Supplier<R> supplier)
      Returns a function that accepts its parameter via the specified consumer and returns the value returned by the specified supplier.
      Type Parameters:
      T - the function parameter type
      R - the function return type
      Parameters:
      consumer - the consumer of the function parameter
      supplier - the supplier of the function result
      Returns:
      a function that accepts its parameter via the specified consumer and returns the value returned by the specified supplier.
    • entry

      static <K,V,KR,VR> Function<Map.Entry<K,V>, Map.Entry<KR,VR>> entry(Function<K,KR> keyFunction, Function<V,VR> valueFunction)
      Returns a Map.Entry function from the specified key and value functions.
      Type Parameters:
      K - the entry key type
      V - the entry value type
      KR - the mapped entry key type
      VR - the mapped entry value type
      Parameters:
      keyFunction - an entry key function
      valueFunction - an entry value function
      Returns:
      a Map.Entry function from the specified key and value functions.