3030import static io .vavr .API .Tuple ;
3131
3232/**
33- * An {@link Multimap} implementation (not intended to be public).
33+ * An abstract base implementation of the {@link Multimap} interface that provides
34+ * common functionality for concrete Multimap implementations. This class is not
35+ * intended to be public and serves as a foundation for specialized Multimap types.
3436 *
3537 * @param <K> Key type
3638 * @param <V> Value type
37- * @param <M> Multimap type
39+ * @param <M> Concrete Multimap type extending this class
3840 * @author Ruslan Sennov
3941 */
4042abstract class AbstractMultimap <K , V , M extends Multimap <K , V >> implements Multimap <K , V > {
@@ -45,18 +47,57 @@ abstract class AbstractMultimap<K, V, M extends Multimap<K, V>> implements Multi
4547 protected final SerializableSupplier <Traversable <?>> emptyContainer ;
4648 private final ContainerType containerType ;
4749
50+ /**
51+ * Creates a new AbstractMultimap with the specified backing map, container type, and empty container supplier.
52+ *
53+ * @param back The backing map that stores the key-value pairs
54+ * @param containerType The type of container used to store multiple values for a key
55+ * @param emptyContainer A supplier that creates empty containers for new key entries
56+ */
4857 AbstractMultimap (Map <K , Traversable <V >> back , ContainerType containerType , SerializableSupplier <Traversable <?>> emptyContainer ) {
4958 this .back = back ;
5059 this .containerType = containerType ;
5160 this .emptyContainer = emptyContainer ;
5261 }
5362
63+ /**
64+ * Returns an empty Map instance specific to the implementing class.
65+ *
66+ * @param <K2> Key type of the empty map
67+ * @param <V2> Value type of the empty map
68+ * @return An empty Map instance
69+ */
5470 protected abstract <K2 , V2 > Map <K2 , V2 > emptyMapSupplier ();
5571
72+ /**
73+ * Returns an empty Multimap instance specific to the implementing class.
74+ *
75+ * @param <K2> Key type of the empty multimap
76+ * @param <V2> Value type of the empty multimap
77+ * @return An empty Multimap instance
78+ */
5679 protected abstract <K2 , V2 > Multimap <K2 , V2 > emptyInstance ();
5780
81+ /**
82+ * Creates a new Multimap instance from the given backing map.
83+ *
84+ * @param <K2> Key type of the new multimap
85+ * @param <V2> Value type of the new multimap
86+ * @param back The backing map to create the multimap from
87+ * @return A new Multimap instance containing the entries from the backing map
88+ */
5889 protected abstract <K2 , V2 > Multimap <K2 , V2 > createFromMap (Map <K2 , Traversable <V2 >> back );
5990
91+ /**
92+ * Creates a new Multimap from the given entries by grouping values by their keys.
93+ * For each key, a new container is created using the emptyContainer supplier,
94+ * and values are added using the containerType's add operation.
95+ *
96+ * @param <K2> Key type of the new multimap
97+ * @param <V2> Value type of the new multimap
98+ * @param entries The entries to create the multimap from
99+ * @return A new Multimap containing all the entries with values grouped by keys
100+ */
60101 @ SuppressWarnings ("unchecked" )
61102 private <K2 , V2 > Multimap <K2 , V2 > createFromEntries (Iterable <? extends Tuple2 <? extends K2 , ? extends V2 >> entries ) {
62103 Map <K2 , Traversable <V2 >> back = emptyMapSupplier ();
0 commit comments