Made MultiMap key a generic type
diff --git a/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/importer/MultiMap.java b/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/importer/MultiMap.java
index 109d14e..a352cbe 100644
--- a/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/importer/MultiMap.java
+++ b/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/importer/MultiMap.java
@@ -27,17 +27,18 @@
/**
* Minimal implementation of a thread-safe map where each key can have multiple values.
*
- * @param <T> the value type
+ * @param <K> the key type
+ * @param <V> the value type
*/
-public class MultiMap<T> {
+public class MultiMap<K, V> {
- private Map<String, Set<T>> map;
+ private Map<K, Set<V>> map;
public MultiMap() {
map = new ConcurrentHashMap<>();
}
- public void put(String key, T value) {
+ public void put(K key, V value) {
map.compute(key, (k, v) -> {
if (v == null) {
v = new CopyOnWriteArraySet<>();
@@ -47,23 +48,23 @@
});
}
- public Set<T> get(String key) {
- Set<T> values = map.get(key);
+ public Set<V> get(K key) {
+ Set<V> values = map.get(key);
return values == null ? Collections.emptySet() : Collections.unmodifiableSet(values);
}
- public void remove(String key, T value) {
+ public void remove(K key, V value) {
// reminder: returning null from the compute lambda will remove the mapping
map.compute(key, (k, v) -> v != null && v.remove(value) && v.isEmpty() ? null : v);
}
- public void remove(T value) {
- for (String key : map.keySet()) {
+ public void remove(V value) {
+ for (K key : map.keySet()) {
remove(key, value);
}
}
- public Set<String> keySet() {
+ public Set<K> keySet() {
return map.keySet();
}
diff --git a/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/importer/TopologyManagerImport.java b/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/importer/TopologyManagerImport.java
index 244f3db..01f1968 100644
--- a/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/importer/TopologyManagerImport.java
+++ b/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/importer/TopologyManagerImport.java
@@ -56,12 +56,12 @@
/**
* List of Endpoints by matched filter that were reported by the EndpointListener and can be imported
*/
- private final MultiMap<EndpointDescription> importPossibilities = new MultiMap<>();
+ private final MultiMap<String, EndpointDescription> importPossibilities = new MultiMap<>();
/**
* List of already imported Endpoints by their matched filter
*/
- private final MultiMap<ImportRegistration> importedServices = new MultiMap<>();
+ private final MultiMap<String, ImportRegistration> importedServices = new MultiMap<>();
public TopologyManagerImport(BundleContext bc) {
this.rsaSet = new HashSet<>();