Class AutoEnumCollectors
java.lang.Object
ru.progrm_jarvis.javacommons.util.stream.AutoEnumCollectors
Collectors for use with enums with automatic type inference.
This delegates its logic to the corresponding methods of EnumCollectors
but infers enum types via type hints
this leads to insignificant overhead due to empty-array allocation cost
thus it is recommended to provide types explicitly in critical sections.-
Method Summary
Modifier and TypeMethodDescriptiontoEnumMap(@NonNull Function<E, V> valueMapper, @NonNull BinaryOperator<V> merger, @Nullable E @NonNull ... typeHint) toEnumMap(@NonNull Function<T, E> keyMapper, @NonNull Function<T, V> valueMapper, @NonNull BinaryOperator<V> merger, @Nullable E @NonNull ... typeHint) toEnumSet(@Nullable E @NonNull ... typeHint)
-
Method Details
-
toEnumMap
@SafeVarargs @NotNull public static <T,E extends Enum<E>, @NotNull Collector<T,V> ?, toEnumMap@NotNull Map<E, V>> (@NonNull @NonNull Function<T, E> keyMapper, @NonNull @NonNull Function<T, V> valueMapper, @NonNull @NonNull BinaryOperator<V> merger, @Nullable @Nullable E @NonNull ... typeHint) - Type Parameters:
T- type of the input elementsE- type of the enumV- type of map values- Parameters:
keyMapper- mapping function used to convert the elements into enum-keysvalueMapper- mapping function used to convert the elements into valuesmerger- function used to handle duplicate valuestypeHint- array used for enum-type discovery- Returns:
- a collector collecting al its elements into an enum-map
-
toEnumMap
@SafeVarargs @NotNull public static <E extends Enum<E>,V> @NotNull Collector<E,?, toEnumMap@NotNull Map<E, V>> (@NonNull @NonNull Function<E, V> valueMapper, @NonNull @NonNull BinaryOperator<V> merger, @Nullable @Nullable E @NonNull ... typeHint) - Type Parameters:
E- type of the enumV- type of map values- Parameters:
valueMapper- mapping function used to convert the elements into valuesmerger- function used to handle duplicate valuestypeHint- array used for enum-type discovery- Returns:
- a collector collecting al its elements into an enum-map
-
toEnumSet
@SafeVarargs public static <E extends Enum<E>> Collector<E,?, toEnumSetSet<E>> (@Nullable @Nullable E @NonNull ... typeHint) - Type Parameters:
E- type of the enum- Parameters:
typeHint- array used for enum-type discovery- Returns:
- a collector collecting al its elements into an enum-set
-