Class HashMultimap<K,V>

java.lang.Object
io.vavr.collection.AbstractMultimap<K, V, HashMultimap<K,V>>
io.vavr.collection.HashMultimap<K,V>
Type Parameters:
K - Key type
V - Value type
All Implemented Interfaces:
Foldable<Tuple2<K,V>>, Multimap<K,V>, Traversable<Tuple2<K,V>>, Function1<K, Traversable<V>>, PartialFunction<K, Traversable<V>>, Value<Tuple2<K,V>>, Serializable, Iterable<Tuple2<K,V>>, Function<K, Traversable<V>>

public final class HashMultimap<K,V> extends AbstractMultimap<K, V, HashMultimap<K,V>> implements Serializable
A HashMap-based implementation of Multimap
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • withSeq

      public static <V> HashMultimap.Builder<V> withSeq()
      Returns a builder for HashMultimap instances where values are stored in a sequence. Values for each key will be stored in a Vavr List, allowing duplicates and preserving insertion order.
      Type Parameters:
      V - The value type
      Returns:
      A new Builder for creating HashMultimap instances with sequence-based value storage
    • withSet

      public static <V> HashMultimap.Builder<V> withSet()
      Returns a builder for HashMultimap instances where values are stored in a set. Values for each key will be stored in a Vavr HashSet, ensuring uniqueness without guaranteed order.
      Type Parameters:
      V - The value type
      Returns:
      A new Builder for creating HashMultimap instances with set-based value storage
    • withSortedSet

      public static <V extends Comparable<?>> HashMultimap.Builder<V> withSortedSet()
      Returns a builder for HashMultimap instances where values are stored in a sorted set. Values for each key will be stored in a Vavr TreeSet, ensuring uniqueness and natural ordering. Value type must be Comparable.
      Type Parameters:
      V - The value type, must extend Comparable
      Returns:
      A new Builder for creating HashMultimap instances with sorted set-based value storage
    • withSortedSet

      public static <V> HashMultimap.Builder<V> withSortedSet(Comparator<? super V> comparator)
      Returns a builder for HashMultimap instances where values are stored in a sorted set with a custom comparator. Values for each key will be stored in a Vavr TreeSet, ensuring uniqueness and ordering based on the provided comparator.
      Type Parameters:
      V - The value type
      Parameters:
      comparator - The comparator used to sort values
      Returns:
      A new Builder for creating HashMultimap instances with sorted set-based value storage using the given comparator
    • narrow

      public static <K,V> HashMultimap<K,V> narrow(HashMultimap<? extends K, ? extends V> map)
      Narrows a HashMultimap<? extends K, ? extends V> to HashMultimap<K, V> via a type-safe cast. Safe here because the multimap is immutable and no elements can be added that would violate the type (covariance)
      Type Parameters:
      K - the target key type
      V - the target value type
      Parameters:
      map - the multimap to narrow
      Returns:
      the same multimap viewed as HashMultimap<K, V>
    • emptyMapSupplier

      protected <K2,V2> Map<K2,V2> emptyMapSupplier()
      Description copied from class: AbstractMultimap
      Returns an empty Map instance specific to the implementing class.
      Specified by:
      emptyMapSupplier in class AbstractMultimap<K, V, HashMultimap<K,V>>
      Type Parameters:
      K2 - Key type of the empty map
      V2 - Value type of the empty map
      Returns:
      An empty Map instance
    • emptyInstance

      protected <K2,V2> HashMultimap<K2,V2> emptyInstance()
      Description copied from class: AbstractMultimap
      Returns an empty Multimap instance specific to the implementing class.
      Specified by:
      emptyInstance in class AbstractMultimap<K, V, HashMultimap<K,V>>
      Type Parameters:
      K2 - Key type of the empty multimap
      V2 - Value type of the empty multimap
      Returns:
      An empty Multimap instance
    • createFromMap

      protected <K2,V2> HashMultimap<K2,V2> createFromMap(Map<K2, Traversable<V2>> back)
      Description copied from class: AbstractMultimap
      Creates a new Multimap instance from the given backing map.
      Specified by:
      createFromMap in class AbstractMultimap<K, V, HashMultimap<K,V>>
      Type Parameters:
      K2 - Key type of the new multimap
      V2 - Value type of the new multimap
      Parameters:
      back - The backing map to create the multimap from
      Returns:
      A new Multimap instance containing the entries from the backing map