public final class Functions
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static <A,B,C> java.util.function.Function<A,C> |
compose(java.util.function.Function<B,C> g,
java.util.function.Function<A,? extends B> f)
Returns the composition of two functions.
|
static <E> java.util.function.Function<java.lang.Object,E> |
constant(E value)
Creates a function that returns
value for any input. |
static <K,V> java.util.function.Function<K,V> |
forMap(java.util.Map<K,? extends V> map,
V defaultValue)
Returns a function which performs a map lookup with a default value.
|
static <K,V> java.util.function.Function<K,V> |
forMap(java.util.Map<K,V> map)
Returns a function which performs a map lookup.
|
static <T> java.util.function.Function<T,java.lang.Boolean> |
forPredicate(java.util.function.Predicate<T> predicate)
Creates a function that returns the same boolean output as the given predicate for all inputs.
|
static <T> java.util.function.Function<java.lang.Object,T> |
forSupplier(java.util.function.Supplier<T> supplier)
Returns a function that always returns the result of invoking
Supplier.get() on supplier, regardless of its input. |
static <E> java.util.function.Function<E,E> |
identity()
Returns the identity function.
|
public static <E> java.util.function.Function<E,E> identity()
public static <K,V> java.util.function.Function<K,V> forMap(java.util.Map<K,V> map)
IllegalArgumentException if given a key that does not exist in the map. See also forMap(Map, Object), which returns a default value in this case.public static <K,V> java.util.function.Function<K,V> forMap(java.util.Map<K,? extends V> map,
@Nullable
V defaultValue)
defaultValue for all inputs that do not belong to the map's key
set. See also forMap(Map), which throws an exception in this case.map - source map that determines the function behaviordefaultValue - the value to return for inputs that aren't map keysmap.get(a) when a is a key, or defaultValue otherwisepublic static <A,B,C> java.util.function.Function<A,C> compose(java.util.function.Function<B,C> g,
java.util.function.Function<A,? extends B> f)
f: A->B and g: B->C, composition
is defined as the function h such that h(a) == g(f(a)) for each a.g - the second function to applyf - the first function to applyf and gpublic static <T> java.util.function.Function<T,java.lang.Boolean> forPredicate(java.util.function.Predicate<T> predicate)
The returned function is consistent with equals (as documented at Function.apply(T)) if and only if predicate is itself consistent with equals.
public static <E> java.util.function.Function<java.lang.Object,E> constant(@Nullable
E value)
value for any input.value - the constant value for the function to returnvaluepublic static <T> java.util.function.Function<java.lang.Object,T> forSupplier(java.util.function.Supplier<T> supplier)
Supplier.get() on supplier, regardless of its input.