30
30
import static io .vavr .API .Tuple ;
31
31
32
32
/**
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.
34
36
*
35
37
* @param <K> Key type
36
38
* @param <V> Value type
37
- * @param <M> Multimap type
39
+ * @param <M> Concrete Multimap type extending this class
38
40
* @author Ruslan Sennov
39
41
*/
40
42
abstract 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
45
47
protected final SerializableSupplier <Traversable <?>> emptyContainer ;
46
48
private final ContainerType containerType ;
47
49
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
+ */
48
57
AbstractMultimap (Map <K , Traversable <V >> back , ContainerType containerType , SerializableSupplier <Traversable <?>> emptyContainer ) {
49
58
this .back = back ;
50
59
this .containerType = containerType ;
51
60
this .emptyContainer = emptyContainer ;
52
61
}
53
62
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
+ */
54
70
protected abstract <K2 , V2 > Map <K2 , V2 > emptyMapSupplier ();
55
71
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
+ */
56
79
protected abstract <K2 , V2 > Multimap <K2 , V2 > emptyInstance ();
57
80
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
+ */
58
89
protected abstract <K2 , V2 > Multimap <K2 , V2 > createFromMap (Map <K2 , Traversable <V2 >> back );
59
90
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
+ */
60
101
@ SuppressWarnings ("unchecked" )
61
102
private <K2 , V2 > Multimap <K2 , V2 > createFromEntries (Iterable <? extends Tuple2 <? extends K2 , ? extends V2 >> entries ) {
62
103
Map <K2 , Traversable <V2 >> back = emptyMapSupplier ();
0 commit comments