Speed up DeviceGroupRegistry.isGroupPresent() 64/94364/2
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 3 Jan 2021 15:13:58 +0000 (16:13 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 3 Jan 2021 15:32:49 +0000 (16:32 +0100)
Sonar is complaining about an explicit 'false' here, fix that warning
by storing the result and having a proper expression. This ends up
being faster, as we perform only a single lookup.

Change-Id: I9c96a3c01be5e01fbb215bc0d86c78f06185fe30
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/DevicesGroupRegistry.java

index a658f7eee63d9f58a16f46811157b81502334389..af0228ad0725e106651eb75a63d9e0cca7d56c15 100644 (file)
@@ -5,7 +5,6 @@
  * 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.applications.frm.impl;
 
 import java.util.ArrayList;
@@ -17,19 +16,20 @@ import org.opendaylight.yangtools.yang.common.Uint32;
 public class DevicesGroupRegistry {
     private final Map<String, List<Uint32>> deviceGroupMapping = new ConcurrentHashMap<>();
 
-    public boolean isGroupPresent(String nodeId, Uint32 groupId) {
-        return deviceGroupMapping.get(nodeId) != null ? deviceGroupMapping.get(nodeId).contains(groupId) : false;
+    public boolean isGroupPresent(final String nodeId, final Uint32 groupId) {
+        final List<Uint32> groups = deviceGroupMapping.get(nodeId);
+        return groups != null && groups.contains(groupId);
     }
 
-    public void storeGroup(String nodeId, Uint32 groupId) {
+    public void storeGroup(final String nodeId, final Uint32 groupId) {
         deviceGroupMapping.computeIfAbsent(nodeId, groupIdList -> new ArrayList<>()).add(groupId);
     }
 
-    public void removeGroup(String nodeId, Uint32 groupId) {
+    public void removeGroup(final String nodeId, final Uint32 groupId) {
         deviceGroupMapping.computeIfPresent(nodeId, (node, groupIds) -> groupIds).remove(groupId);
     }
 
-    public void clearNodeGroups(String nodeId) {
+    public void clearNodeGroups(final String nodeId) {
         deviceGroupMapping.remove(nodeId);
     }
 }
\ No newline at end of file