Class EnumCollectors

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

public final class EnumCollectors extends Object

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 Details

    • toEnumMap

      @NotNull public static <T, E extends Enum<E>, V> @NotNull Collector<T,?,@NotNull Map<E,V>> toEnumMap(@NonNull @NonNull Class<E> type, @NonNull @NonNull Function<T,E> keyMapper, @NonNull @NonNull Function<T,V> valueMapper, @NonNull @NonNull BinaryOperator<V> merger)
      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:
      type - type object of the enum
      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
      Returns:
      a collector collecting al its elements into an enum-map
    • 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, @TypeHint @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

      @NotNull public static <T, E extends Enum<E>, V> @NotNull Collector<T,?,@NotNull Map<E,V>> toEnumMap(@NonNull @NonNull Class<E> type, @NonNull @NonNull Function<T,E> keyMapper, @NonNull @NonNull Function<T,V> valueMapper)
      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:
      type - type object of the enum
      keyMapper - mapping function used to convert the elements into enum-keys
      valueMapper - 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,?,@NotNull Map<E,V>> toEnumMap(@NonNull @NonNull Class<E> type, @NonNull @NonNull Function<E,V> valueMapper)
      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:
      type - type object of the enum
      valueMapper - 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,?,@NotNull Map<E,V>> toEnumMap(@NonNull @NonNull Class<E> type, @NonNull @NonNull Function<E,V> valueMapper, @NonNull @NonNull BinaryOperator<V> merger)
      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:
      type - type object of the enum
      valueMapper - mapping function used to convert the elements into values
      merger - 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,?,@NotNull Map<E,V>> toEnumMap(@NonNull @NonNull Function<E,V> valueMapper, @NonNull @NonNull BinaryOperator<V> merger, @TypeHint @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

      public static <E extends Enum<E>> Collector<E,?,Set<E>> toEnumSet(@NonNull @NonNull Class<E> type)
      Returns a Collector that accumulates the input elements into a new enum-Set.
      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,?,Set<E>> toEnumSet(@TypeHint @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