Package science.aist.jack.stream
Class FunctionUtil
- java.lang.Object
-
- science.aist.jack.stream.FunctionUtil
-
public final class FunctionUtil extends Object
Util class to provide different helper function for
java.util.function
- Since:
- 2.0
- Author:
- Andreas Pointner
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,U>
BiConsumer<T,U>emptyBiConsumer()
returns an empty bi consumerstatic <T> Consumer<T>
emptyConsumer()
Returns an empty consumerstatic <T> Function<T,T>
identity()
Does the same asFunction.identity()
but does not always create a new lambda object, instead always returns the same onestatic <T,R>
Function<T,R>toFunction(Function<T,R> func)
Some sort of hack to convert a method reference to a Function.
-
-
-
Method Detail
-
emptyConsumer
public static <T> Consumer<T> emptyConsumer()
Returns an empty consumer
This helps to avoid the creation of a huge amount of new consumer objects
- Type Parameters:
T
- of any type- Returns:
- empty consumer, that does basically nothing.
-
emptyBiConsumer
public static <T,U> BiConsumer<T,U> emptyBiConsumer()
returns an empty bi consumer
This helps to avoid the creation of a huge amount of new consumer objects
- Type Parameters:
T
- any typeU
- any type- Returns:
- empty bi-consumer, that does nothing
-
identity
public static <T> Function<T,T> identity()
Does the same as
Function.identity()
but does not always create a new lambda object, instead always returns the same one- Type Parameters:
T
- any type- Returns:
- a function that returns the input value as output
-
toFunction
public static <T,R> Function<T,R> toFunction(Function<T,R> func)
Some sort of hack to convert a method reference to a Function.
So instead of casting anything to use it as a function:
Function<In, Out> func = (Function<In, Out>)obj::method
you can use:Function<In, Out> func = toFunction(obj::method);
This is especially useful when using andThen:Function<In, Out2> func = ((Function<In, Out>)obj::method).andThen(obj2:method2);
simply use:Function<In, Out2> func = toFunction(obj::method).andThen(obj2:method2);
- Type Parameters:
T
- the input typeR
- the result type- Parameters:
func
- the function- Returns:
- the converted function
-
-