Class FunctionSupport
- java.lang.Object
-
- net.shibboleth.utilities.java.support.logic.FunctionSupport
-
public final class FunctionSupport extends Object
Helper class for constructing functions that are fully generic, in contrast to the broken, Object-bound types Guava can build.
-
-
Constructor Summary
Constructors Modifier Constructor Description privateFunctionSupport()Constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <A,B,C>
Function<A,C>compose(Function<B,C> g, Function<A,? extends B> f)Returns the composition of two functions.static <T1,T2>
Function<T1,T2>constant(T2 target)Creates a function that returns a constant value, likeFunctions.constant(Object), but with the type of input parameterized as well as the output.static <T> Function<T,Boolean>forPredicate(Predicate<T> predicate)Creates a function that returns the same boolean output as the given predicate for all inputs.
-
-
-
Method Detail
-
constant
@Nonnull public static <T1,T2> Function<T1,T2> constant(@Nonnull @ParameterName(name="target") T2 target)
Creates a function that returns a constant value, likeFunctions.constant(Object), but with the type of input parameterized as well as the output.- Type Parameters:
T1- type of object the function needs to act onT2- type of object being returned- Parameters:
target- the value to return from the function- Returns:
- the constructed function
-
compose
@Nonnull public static <A,B,C> Function<A,C> compose(@Nonnull @ParameterName(name="g") Function<B,C> g, @Nonnull @ParameterName(name="f") Function<A,? extends B> f)
Returns the composition of two functions. Forf: A->Bandg: B->C, composition is defined as the function h such thath(a) == g(f(a))for eacha.- Type Parameters:
A- input to composed functionB- output of inner functionC- output of composed function- Parameters:
g- the second function to applyf- the first function to apply- Returns:
- the composition of
fandg - See Also:
- function composition
-
forPredicate
@Nonnull public static <T> Function<T,Boolean> forPredicate(@Nonnull Predicate<T> predicate)
Creates a function that returns the same boolean output as the given predicate for all inputs.Primarily provided for Spring wiring use cases that can't express a method reference.
- Type Parameters:
T- input type- Parameters:
predicate- input predicate- Returns:
- a corresponding function
-
-