Class AutoEnumCollectors

java.lang.Object
ru.progrm_jarvis.javacommons.util.stream.AutoEnumCollectors

public final class AutoEnumCollectors extends Object
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 Details

    • toEnumMap

      @SafeVarargs @NotNull public static <T, E extends Enum<E>, V> @NotNull Collector<T,?,@NotNull Map<E,V>> toEnumMap(@NonNull @NonNull Function<T,E> keyMapper, @NonNull @NonNull Function<T,V> valueMapper, @NonNull @NonNull BinaryOperator<V> merger, @Nullable @Nullable E @NonNull ... typeHint)
      Returns a Collector that accumulates the input elements into a new enum-Map.
      Type Parameters:
      T - type of the input elements
      E - type of the enum
      V - type of map values
      Parameters:
      keyMapper - mapping function used to convert the elements into enum-keys
      valueMapper - mapping function used to convert the elements into values
      merger - function used to handle duplicate values
      typeHint - 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,?,@NotNull Map<E,V>> toEnumMap(@NonNull @NonNull Function<E,V> valueMapper, @NonNull @NonNull BinaryOperator<V> merger, @Nullable @Nullable E @NonNull ... typeHint)
      Returns a Collector that accumulates the input elements into a new enum-Map.
      Type Parameters:
      E - type of the enum
      V - type of map values
      Parameters:
      valueMapper - mapping function used to convert the elements into values
      merger - function used to handle duplicate values
      typeHint - 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,?,Set<E>> toEnumSet(@Nullable @Nullable E @NonNull ... typeHint)
      Returns a Collector that accumulates the input elements into a new enum-Set.
      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