Remove MapDictionary 23/101723/7
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 4 Jul 2022 19:52:29 +0000 (21:52 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 4 Jul 2022 21:43:44 +0000 (23:43 +0200)
We have OSGi R8, which has a FrameworkUtil.asDictionary(Map), hence
we do not need a custom Dictionary implementation.

Change-Id: Idada9d0fd6d7fc24079a91c34c19757cb9b4fd39
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
web/impl-osgi/src/main/java/org/opendaylight/aaa/web/osgi/MapDictionary.java [deleted file]
web/impl-osgi/src/main/java/org/opendaylight/aaa/web/osgi/WhiteboardWebServer.java

diff --git a/web/impl-osgi/src/main/java/org/opendaylight/aaa/web/osgi/MapDictionary.java b/web/impl-osgi/src/main/java/org/opendaylight/aaa/web/osgi/MapDictionary.java
deleted file mode 100644 (file)
index a0aac86..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 2017 Red Hat, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.aaa.web.osgi;
-
-import static com.google.common.collect.Iterators.asEnumeration;
-
-import com.google.common.collect.ImmutableMap;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.Map;
-
-/**
- * Bridge {@link Dictionary} to {@link Map}.
- *
- * <p>
- * Old OSGi APIs use {@link Dictionary}, but the only concrete implementation of
- * Dictionary in the JDK is Hashtable, which both error-prone as well as
- * Modernizer don't like and suggest HashMap - but that is not a Dictionary.
- *
- * @author Michael Vorburger.ch
- */
-class MapDictionary<K, V> extends Dictionary<K, V> {
-    private final Map<K, V> map;
-
-    MapDictionary(final Map<K, ? extends V> map) {
-        this.map = ImmutableMap.copyOf(map);
-    }
-
-    @Override
-    public int size() {
-        return map.size();
-    }
-
-    @Override
-    public boolean isEmpty() {
-        return map.isEmpty();
-    }
-
-    @Override
-    public Enumeration<K> keys() {
-        return asEnumeration(map.keySet().iterator());
-    }
-
-    @Override
-    public Enumeration<V> elements() {
-        return asEnumeration(map.values().iterator());
-    }
-
-    @Override
-    public V get(final Object key) {
-        return map.get(key);
-    }
-
-    @Override
-    public V put(final K key, final V value) {
-        return map.put(key, value);
-    }
-
-    @Override
-    public V remove(final Object key) {
-        return map.remove(key);
-    }
-}
index ad98ae039904df068c37cc35c03816e90b15d77b..a1b3f1626709ec71404e7b85a2ef2c3712765a83 100644 (file)
@@ -26,6 +26,7 @@ import org.opendaylight.aaa.web.WebServer;
 import org.opendaylight.yangtools.concepts.AbstractRegistration;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.component.ComponentContext;
@@ -112,7 +113,7 @@ public final class WhiteboardWebServer implements WebServer {
         final var contextProps = contextProperties(contextName, contextPath, webContext.contextParams());
         LOG.debug("Registering context {} with properties {}", contextName, contextProps);
         builder.add(bundleContext.registerService(ServletContextHelper.class,
-            new WhiteboardServletContextHelper(bundle), new MapDictionary<>(contextProps)));
+            new WhiteboardServletContextHelper(bundle), FrameworkUtil.asDictionary(contextProps)));
 
         // 2. Listeners - because they could set up things that filters and servlets need
         final var contextSelect = "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=" + contextName + ")";
@@ -122,21 +123,23 @@ public final class WhiteboardWebServer implements WebServer {
                 HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER, Boolean.TRUE);
             LOG.debug("Registering listener {} with properties {}", listener, props);
             builder.add(bundleContext.registerService(ServletContextListener.class, listener,
-                new MapDictionary<>(props)));
+                FrameworkUtil.asDictionary(props)));
         }
 
         // 3. Filters - because subsequent servlets should already be covered by the filters
         for (var filter : webContext.filters()) {
             final var props = filterProperties(contextPath, contextSelect, filter);
             LOG.debug("Registering filter {} with properties {}", filter, props);
-            builder.add(bundleContext.registerService(Filter.class, filter.filter(), new MapDictionary<>(props)));
+            builder.add(bundleContext.registerService(Filter.class, filter.filter(),
+                FrameworkUtil.asDictionary(props)));
         }
 
         // 4. Servlets - 'bout time for 'em by now, don't you think? ;)
         for (var servlet : webContext.servlets()) {
             final var props = servletProperties(contextPath, contextSelect, servlet);
             LOG.debug("Registering servlet {} with properties {}", servlet, props);
-            builder.add(bundleContext.registerService(Servlet.class, servlet.servlet(), new MapDictionary<>(props)));
+            builder.add(bundleContext.registerService(Servlet.class, servlet.servlet(),
+                FrameworkUtil.asDictionary(props)));
         }
 
         // 5. Resources
@@ -144,7 +147,7 @@ public final class WhiteboardWebServer implements WebServer {
             final var props = resourceProperties(contextPath, contextSelect, resource);
             LOG.debug("Registering resource {} with properties {}", resource, props);
             builder.add(bundleContext.registerService(Object.class, WhiteboardResource.INSTANCE,
-                new MapDictionary<>(props)));
+                FrameworkUtil.asDictionary(props)));
         }
 
         final var services = builder.build();