Package org.opencypher.tools
Class Functions
- java.lang.Object
-
- org.opencypher.tools.Functions
-
public class Functions extends Object
Utilities for working with Java functions.
-
-
Constructor Summary
Constructors Constructor Description Functions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Collector<Optional<T>,List<T>,List<T>>flatList()static <T> Tidentity(T value)A method that is useful as a method reference to implement an identity function.static <K,V>
Map<K,V>map(Collection<V> values, Function<V,K> key)Create aMapby applying a function that extracts the key from a collection of values.static <K,V>
Map<K,V>map(Function<V,K> key, V... values)Create aMapby applying a function that extracts the key from an array of values.static <I,O>
Supplier<O>map(Supplier<I> source, Function<I,O> map)static <T> TrequireNonNull(Class<T> type, T value)Require an instance not to be null, using the (simple) name of the required type as an error message if it is.
-
-
-
Method Detail
-
requireNonNull
public static <T> T requireNonNull(Class<T> type, T value)
Require an instance not to be null, using the (simple) name of the required type as an error message if it is.- Type Parameters:
T- the type.- Parameters:
type- the required type.value- the value that must not be null.- Returns:
- the value, that is guaranteed not to be null.
- See Also:
Objects.requireNonNull(Object, Supplier)
-
map
public static <I,O> Supplier<O> map(Supplier<I> source, Function<I,O> map)
- Type Parameters:
I- the type of the value supplied by the original supplier.O- the type of the value supplied by the resulting supplier.- Parameters:
source- the source supplier that supplies the original value.map- the function that converts the value of the original supplier.- Returns:
- a converting supplier.
-
map
@SafeVarargs public static <K,V> Map<K,V> map(Function<V,K> key, V... values)
Create aMapby applying a function that extracts the key from an array of values.- Type Parameters:
K- the type of the keys.V- the type of the values.- Parameters:
key- the key extraction function.values- the values of the map (from which the keys are extracted).- Returns:
- a
Mapfrom the keys of the values to the values.
-
identity
public static <T> T identity(T value)
A method that is useful as a method reference to implement an identity function.- Type Parameters:
T- the type of the value.- Parameters:
value- the input (and output) value of the function.- Returns:
- the value that was passed in.
-
map
public static <K,V> Map<K,V> map(Collection<V> values, Function<V,K> key)
Create aMapby applying a function that extracts the key from a collection of values.- Type Parameters:
K- the type of the keys.V- the type of the values.- Parameters:
values- the values of the map (from which the keys are extracted).key- the key extraction function.- Returns:
- a
Mapfrom the keys of the values to the values.
-
-