Class EnumCollectors
java.lang.Object
ru.progrm_jarvis.javacommons.util.stream.EnumCollectors
Collectors for use with enums.
There also are some overloads with automatic type inference.
These methods delegate their logic to the corresponding methods with explicit type parameter
by inferring enum types via type hints.
This approach 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 Class<E> type, @NonNull Function<E, V> valueMapper, @NonNull BinaryOperator<V> merger) toEnumMap(@NonNull Class<E> type, @NonNull Function<T, E> keyMapper, @NonNull Function<T, V> valueMapper) toEnumMap(@NonNull Class<E> type, @NonNull Function<T, E> keyMapper, @NonNull Function<T, V> valueMapper, @NonNull BinaryOperator<V> merger) toEnumMap(@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
@NotNull public static <T,E extends Enum<E>, @NotNull Collector<T,V> ?, toEnumMap@NotNull Map<E, V>> (@NonNull @NonNull Class<E> type, @NonNull @NonNull Function<T, E> keyMapper, @NonNull @NonNull Function<T, V> valueMapper, @NonNull @NonNull BinaryOperator<V> merger) - Type Parameters:
T- type of the input elementsE- type of the enumV- type of map values- Parameters:
type- type object of the enumkeyMapper- mapping function used to convert the elements into enum-keysvalueMapper- mapping function used to convert the elements into valuesmerger- function used to handle duplicate values- Returns:
- a collector collecting al its elements into an enum-map
-
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, @TypeHint @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
@NotNull public static <T,E extends Enum<E>, @NotNull Collector<T,V> ?, toEnumMap@NotNull Map<E, V>> (@NonNull @NonNull Class<E> type, @NonNull @NonNull Function<T, E> keyMapper, @NonNull @NonNull Function<T, V> valueMapper) - Type Parameters:
T- type of the input elementsE- type of the enumV- type of map values- Parameters:
type- type object of the enumkeyMapper- mapping function used to convert the elements into enum-keysvalueMapper- mapping function used to convert the elements into values- Returns:
- a collector collecting al its elements into an enum-map
-
toEnumMap
@NotNull public static <E extends Enum<E>,V> @NotNull Collector<E,?, toEnumMap@NotNull Map<E, V>> (@NonNull @NonNull Class<E> type, @NonNull @NonNull Function<E, V> valueMapper) - Type Parameters:
E- type of the enumV- type of map values- Parameters:
type- type object of the enumvalueMapper- mapping function used to convert the elements into values- Returns:
- a collector collecting al its elements into an enum-map
-
toEnumMap
@NotNull public static <E extends Enum<E>,V> @NotNull Collector<E,?, toEnumMap@NotNull Map<E, V>> (@NonNull @NonNull Class<E> type, @NonNull @NonNull Function<E, V> valueMapper, @NonNull @NonNull BinaryOperator<V> merger) - Type Parameters:
E- type of the enumV- type of map values- Parameters:
type- type object of the enumvalueMapper- mapping function used to convert the elements into valuesmerger- function used to handle duplicate values- 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, @TypeHint @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
- Type Parameters:
E- type of the enum- Parameters:
type- type object of the enum- Returns:
- a collector collecting al its elements into an enum-set
-
toEnumSet
@SafeVarargs public static <E extends Enum<E>> Collector<E,?, toEnumSetSet<E>> (@TypeHint @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
-