public final class Functions extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T,V,R> Function<T,R> |
andThen(Function<T,? extends V> before,
Function<V,R> after)
Returns a composed function that first applies the
before function to its input, and then applies
the after function to the result. |
static <T,R> Function<T,R> |
firstResult(Function<T,R>... fns)
Returns a composed function that invokes the specified functions in iteration order, and returns the first
non-null result.
|
static <T> Function<T,T> |
identity() |
static <T,R,E extends RuntimeException> |
wrap(Function<T,R> fn,
Class<E> exClass,
String fmt,
Object... args) |
static <T,R,E extends RuntimeException> |
wrapFmt(CheckedFunction<T,R> fn,
Class<E> exClass,
String msg)
Wraps the specified function to ensure that if any exception occurs, it is of the specified type and/or with
the specified message.
|
public static <T> Function<T,T> identity()
public static <T,R,E extends RuntimeException> Function<T,R> wrapFmt(CheckedFunction<T,R> fn, Class<E> exClass, String msg)
If fn throws an exception, its type is checked. If it is already of type exClass, that
exception is immediately thrown. If it is not the expected exception type, a message is created with the
specified msg template, and a new exception of the specified type is thrown with the formatted message,
using the original exception as its cause.
T - the function argument typeR - the function's return typeE - type of exception to ensurefn - the function to executeexClass - the exception type expected, if anymsg - the formatted message to use if throwing a new exception, used as the first argument to String.format.public static <T,R,E extends RuntimeException> Function<T,R> wrap(Function<T,R> fn, Class<E> exClass, String fmt, Object... args)
public static <T,V,R> Function<T,R> andThen(Function<T,? extends V> before, Function<V,R> after)
before function to its input, and then applies
the after function to the result. If evaluation of either function throws an exception, it is relayed to
the caller of the composed function.T - type of input to the before function and the resulting composed function.V - the type of output of the before function, and of the input to the after function.R - return type of the after function and the resulting composed function.before - the function to invoke firstafter - the function to invoke second with the output from the firstbefore function and then
applies the after function.IllegalArgumentException - if either before or after are null.@SafeVarargs public static <T,R> Function<T,R> firstResult(Function<T,R>... fns)
T - the type of input of the functions, and of the composed functionR - the type of output of the functions, and of the composed functionfns - the functions to iterateNullPointerException - if after is nullCopyright © 2014–2024 jsonwebtoken.io. All rights reserved.