Package org.n52.janmayen.function
Class Functions
java.lang.Object
org.n52.janmayen.function.Functions
Utility functions for
Function.-
Method Summary
Modifier and TypeMethodDescriptionstatic <T,U extends T>
Function<T, U> Returns aFunctionthat casts it's input argument to any type.static <T,U extends T>
Ucast(T t) Casts it's input argument to any type.castIfInstanceOf(Class<? extends U> clazz) Returns aFunctionthat casts it'S input argument to the specified type if it's the right type.static <T,U> Function <T, U> constant(U u) Creates a function returning the same result for each invocation.static <T,R> Supplier <R> Curries the parameter of theFunctionand creates aConsumer.static <T1,T2, R>
Function<T2, R> curryFirst(BiFunction<T1, T2, R> bifunction, T1 t1) Curries the first parameter of theBiFunctionand creates aFunction.static <T1,T2, R>
Function<T1, R> currySecond(BiFunction<T1, T2, R> bifunction, T2 t2) Curries the second parameter of theBiFunctionand creates aFunction.errorWrapper(ThrowingFunction<S, T, X> fun) Wraps anThrowingFunctioninto anFunctionthat throws anErrorif the function throws anException.static <T,U> Function <T, U> forSupplier(Supplier<U> supplier) Create a function for the the supplier, ignoring any supplied input.keySetWhereValues(Predicate<? super V> predicate) keyStreamWhereValues(Predicate<? super V> predicate) static <T> BinaryOperator<T> mergeLeft(BiConsumer<T, T> merger) static <T> BinaryOperator<T> mergeRight(BiConsumer<T, T> merger) static <K,V> BinaryOperator <Map<K, V>> mergeToLeftMap(BinaryOperator<V> valueMerger) static <K,V> BinaryOperator <Map<K, V>> mergeToRightMap(BinaryOperator<V> valueMerger) static <T> Function<T, T>
-
Method Details
-
cast
Casts it's input argument to any type.- Type Parameters:
T- The input type.U- The output type.- Parameters:
t- The object to be casted.- Returns:
- The casted object.
- Throws:
ClassCastException- if the object can not be casted.
-
cast
Returns aFunctionthat casts it's input argument to any type.- Type Parameters:
T- The input type.U- The output type.- Parameters:
clazz- The class the input should be casted to.- Returns:
- The casting function.
- See Also:
-
castIfInstanceOf
public static <T,U extends T> Function<T,Optional<U>> castIfInstanceOf(@Nonnull Class<? extends U> clazz) Returns aFunctionthat casts it'S input argument to the specified type if it's the right type. The returnedOptionaleither contains the casted input arguemnt or is empty.- Type Parameters:
T- The input type.U- The output type.- Parameters:
clazz- The class to- Returns:
- An
Optionalcontaining the input
-
forSupplier
Create a function for the the supplier, ignoring any supplied input.- Type Parameters:
T- the type of the input to the functionU- the type of the result to the function- Parameters:
supplier- the supplier- Returns:
- the function wrapping the supplier
-
constant
Creates a function returning the same result for each invocation.- Type Parameters:
T- the type of the input to the functionU- the type of the result to the function- Parameters:
u- the constant result- Returns:
- the function
-
curry
Curries the parameter of theFunctionand creates aConsumer.- Type Parameters:
T- the parameter typeR- the return type- Parameters:
function- the functiont- the curried parameter- Returns:
- the curried function
-
curryFirst
Curries the first parameter of theBiFunctionand creates aFunction.- Type Parameters:
T1- the first parameter typeT2- the second parameter typeR- the return type- Parameters:
bifunction- the functiont1- the curried parameter- Returns:
- the curried function
-
currySecond
public static <T1,T2, Function<T1,R> R> currySecond(@Nonnull BiFunction<T1, T2, R> bifunction, T2 t2) Curries the second parameter of theBiFunctionand creates aFunction.- Type Parameters:
T1- the first parameter typeT2- the second parameter typeR- the return type- Parameters:
bifunction- the functiont2- the curried parameter- Returns:
- the curried function
-
mergeLeft
-
mergeRight
-
mergeToLeftMap
public static <K,V> BinaryOperator<Map<K,V>> mergeToLeftMap(@Nonnull BinaryOperator<V> valueMerger) -
mergeToRightMap
public static <K,V> BinaryOperator<Map<K,V>> mergeToRightMap(@Nonnull BinaryOperator<V> valueMerger) -
keySetWhereValues
-
keyStreamWhereValues
-
mutate
- Type Parameters:
T- The consumed element's type.- Parameters:
action- The consumer.- Returns:
- A function that applies the consumer and returns it's input.
-
errorWrapper
public static <S,T, Function<S,X extends Exception> T> errorWrapper(@Nonnull ThrowingFunction<S, T, X> fun) Wraps anThrowingFunctioninto anFunctionthat throws anErrorif the function throws anException.- Type Parameters:
S- the function's input type.T- the function's output type.X- the type of the the exception that might be thrown.- Parameters:
fun- the function.- Returns:
- the wrapped function.
-