Use ClassToInstanceMap instead of a HashMap 41/80441/4
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 20 Feb 2019 22:58:51 +0000 (23:58 +0100)
committerArunprakash D <d.arunprakash@ericsson.com>
Thu, 7 Mar 2019 06:02:57 +0000 (06:02 +0000)
ClassToInstanceMap provides a type-safe equivalent of what is
being coded up here.

Change-Id: I682a935ba2c255443b4fd4689d0c589bc0c2bac2
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/OpendaylightDirectStatisticsServiceProvider.java

index 303cc2ca0d358d4c0d169b9dd97f23e671c17cb2..0d96e3587d8d49f1910770cd5acc8dc5c5189e1b 100644 (file)
@@ -5,19 +5,17 @@
  * 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.openflowplugin.impl.statistics.services.direct;
 
-import java.util.HashMap;
-import java.util.Map;
+import com.google.common.collect.ClassToInstanceMap;
+import com.google.common.collect.MutableClassToInstanceMap;
 import java.util.Optional;
 
 /**
  * The Opendaylight direct statistics service provider.
  */
 public class OpendaylightDirectStatisticsServiceProvider {
-    private Map<Class<? extends AbstractDirectStatisticsService>, AbstractDirectStatisticsService> services =
-            new HashMap<>();
+    private final ClassToInstanceMap<AbstractDirectStatisticsService> services = MutableClassToInstanceMap.create();
 
     /**
      * Register direct statistics service.
@@ -38,6 +36,6 @@ public class OpendaylightDirectStatisticsServiceProvider {
      */
     public Optional<? extends AbstractDirectStatisticsService>
             lookup(Class<? extends AbstractDirectStatisticsService> type) {
-        return Optional.ofNullable(services.get(type)).map(type::cast);
+        return Optional.ofNullable(services.getInstance(type));
     }
 }