public final class Functions
extends java.lang.Object
Function.| Modifier and Type | Method and Description |
|---|---|
static <T,U extends T> |
cast(java.lang.Class<? extends U> clazz)
Returns a
Function that casts it's input argument to any type. |
static <T,U extends T> |
cast(T t)
Casts it's input argument to any type.
|
static <T,U extends T> |
castIfInstanceOf(java.lang.Class<? extends U> clazz)
Returns a
Function that casts it'S input argument to the
specified type if it's the right type. |
static <T,U> java.util.function.Function<T,U> |
constant(U u)
Creates a function returning the same result for each invocation.
|
static <T,R> java.util.function.Supplier<R> |
curry(java.util.function.Function<? super T,? extends R> function,
T t)
Curries the parameter of the
Function and creates a
Consumer. |
static <T1,T2,R> java.util.function.Function<T2,R> |
curryFirst(java.util.function.BiFunction<T1,T2,R> bifunction,
T1 t1)
Curries the first parameter of the
BiFunction and creates a
Function. |
static <T1,T2,R> java.util.function.Function<T1,R> |
currySecond(java.util.function.BiFunction<T1,T2,R> bifunction,
T2 t2)
Curries the second parameter of the
BiFunction and creates a
Function. |
static <S,T,X extends java.lang.Exception> |
errorWrapper(ThrowingFunction<S,T,X> fun)
Wraps an
ThrowingFunction into an Function that throws an
Error if the function throws an Exception. |
static <T,U> java.util.function.Function<T,U> |
forSupplier(java.util.function.Supplier<U> supplier)
Create a function for the the supplier, ignoring any supplied input.
|
static <T,U extends T> |
instanceOf(java.lang.Class<? extends U> clazz)
Deprecated.
|
static <K,V> java.util.function.Function<java.util.Map<K,V>,java.util.Set<K>> |
keySetWhereValues(java.util.function.Predicate<? super V> predicate) |
static <K,V> java.util.function.Function<java.util.Map<K,V>,java.util.stream.Stream<K>> |
keyStreamWhereValues(java.util.function.Predicate<? super V> predicate) |
static <T> java.util.function.BinaryOperator<T> |
mergeLeft(java.util.function.BiConsumer<T,T> merger) |
static <T> java.util.function.BinaryOperator<T> |
mergeRight(java.util.function.BiConsumer<T,T> merger) |
static <K,V> java.util.function.BinaryOperator<java.util.Map<K,V>> |
mergeToLeftMap(java.util.function.BinaryOperator<V> valueMerger) |
static <K,V> java.util.function.BinaryOperator<java.util.Map<K,V>> |
mergeToRightMap(java.util.function.BinaryOperator<V> valueMerger) |
static <T> java.util.function.Function<T,T> |
mutate(java.util.function.Consumer<? super T> action)
Wrapps a
Consumer into a Function that returns it's input
argument. |
static <A,B> java.util.function.BiConsumer<B,A> |
reverse(java.util.function.BiConsumer<A,B> consumer)
Deprecated.
|
@Deprecated
public static <T,U extends T> java.util.function.Predicate<T> instanceOf(@Nonnull
java.lang.Class<? extends U> clazz)
Predicates.instanceOf(java.lang.Class)Predicate that checks if it's input is an instance of
clazz.T - The input type.U - The type of which the input has to be an instance of.clazz - The class of which the input has to be an instance of.public static <T,U extends T> U cast(T t)
throws java.lang.ClassCastException
T - The input type.U - The output type.t - The object to be casted.java.lang.ClassCastException - if the object can not be casted.public static <T,U extends T> java.util.function.Function<T,U> cast(@Nonnull
java.lang.Class<? extends U> clazz)
Function that casts it's input argument to any type.T - The input type.U - The output type.clazz - The class the input should be casted to.cast(java.lang.Object)public static <T,U extends T> java.util.function.Function<T,java.util.Optional<U>> castIfInstanceOf(@Nonnull
java.lang.Class<? extends U> clazz)
Function that casts it'S input argument to the
specified type if it's the right type. The returned Optional
either contains the casted input arguemnt or is empty.T - The input type.U - The output type.clazz - The class toOptional containing the inputpublic static <T,U> java.util.function.Function<T,U> forSupplier(@Nonnull
java.util.function.Supplier<U> supplier)
T - the type of the input to the functionU - the type of the result to the functionsupplier - the supplierpublic static <T,U> java.util.function.Function<T,U> constant(@Nullable
U u)
T - the type of the input to the functionU - the type of the result to the functionu - the constant resultpublic static <T,R> java.util.function.Supplier<R> curry(@Nonnull
java.util.function.Function<? super T,? extends R> function,
T t)
Function and creates a
Consumer.T - the parameter typeR - the return typefunction - the functiont - the curried parameterpublic static <T1,T2,R> java.util.function.Function<T2,R> curryFirst(@Nonnull
java.util.function.BiFunction<T1,T2,R> bifunction,
T1 t1)
BiFunction and creates a
Function.T1 - the first parameter typeT2 - the second parameter typeR - the return typebifunction - the functiont1 - the curried parameterpublic static <T1,T2,R> java.util.function.Function<T1,R> currySecond(@Nonnull
java.util.function.BiFunction<T1,T2,R> bifunction,
T2 t2)
BiFunction and creates a
Function.T1 - the first parameter typeT2 - the second parameter typeR - the return typebifunction - the functiont2 - the curried parameter@Deprecated
public static <A,B> java.util.function.BiConsumer<B,A> reverse(@Nonnull
java.util.function.BiConsumer<A,B> consumer)
Consumers.reverse(java.util.function.BiConsumer)A - the first parameter typeB - the second parameter typeconsumer - the consumerpublic static <T> java.util.function.BinaryOperator<T> mergeLeft(@Nonnull
java.util.function.BiConsumer<T,T> merger)
public static <T> java.util.function.BinaryOperator<T> mergeRight(@Nonnull
java.util.function.BiConsumer<T,T> merger)
public static <K,V> java.util.function.BinaryOperator<java.util.Map<K,V>> mergeToLeftMap(@Nonnull
java.util.function.BinaryOperator<V> valueMerger)
public static <K,V> java.util.function.BinaryOperator<java.util.Map<K,V>> mergeToRightMap(@Nonnull
java.util.function.BinaryOperator<V> valueMerger)
public static <K,V> java.util.function.Function<java.util.Map<K,V>,java.util.Set<K>> keySetWhereValues(java.util.function.Predicate<? super V> predicate)
public static <K,V> java.util.function.Function<java.util.Map<K,V>,java.util.stream.Stream<K>> keyStreamWhereValues(java.util.function.Predicate<? super V> predicate)
public static <T> java.util.function.Function<T,T> mutate(@Nonnull
java.util.function.Consumer<? super T> action)
Consumer into a Function that returns it's input
argument.T - The consumed element's type.action - The consumer.public static <S,T,X extends java.lang.Exception> java.util.function.Function<S,T> errorWrapper(@Nonnull
ThrowingFunction<S,T,X> fun)
ThrowingFunction into an Function that throws an
Error if the function throws an Exception.S - the function's input type.T - the function's output type.X - the type of the the exception that might be thrown.fun - the function.Copyright © 2015–2018 52°North Initiative for Geospatial Open Source Software GmbH. All rights reserved.