37 lines
1.8 KiB
Diff
37 lines
1.8 KiB
Diff
# UNDF: UNDF-2026-000000191
|
|
--- a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/DevicesGroupRegistry.java
|
|
+++ b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/DevicesGroupRegistry.java
|
|
@@ -9,26 +9,27 @@
|
|
*/
|
|
package org.opendaylight.openflowplugin.applications.frm.impl;
|
|
|
|
-import java.util.ArrayList;
|
|
-import java.util.List;
|
|
+import java.util.HashSet;
|
|
import java.util.Map;
|
|
+import java.util.Set;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import org.opendaylight.yangtools.yang.common.Uint32;
|
|
|
|
public class DevicesGroupRegistry {
|
|
- private final Map<String, List<Uint32>> deviceGroupMapping = new ConcurrentHashMap<>();
|
|
+ // CWE-407 fix: Set<Uint32> gives O(1) contains() vs O(N) for ArrayList
|
|
+ private final Map<String, Set<Uint32>> deviceGroupMapping = new ConcurrentHashMap<>();
|
|
|
|
public boolean isGroupPresent(final String nodeId, final Uint32 groupId) {
|
|
- final List<Uint32> groups = deviceGroupMapping.get(nodeId);
|
|
+ final Set<Uint32> groups = deviceGroupMapping.get(nodeId);
|
|
return groups != null && groups.contains(groupId);
|
|
}
|
|
|
|
public void storeGroup(final String nodeId, final Uint32 groupId) {
|
|
- deviceGroupMapping.computeIfAbsent(nodeId, groupIdList -> new ArrayList<>()).add(groupId);
|
|
+ deviceGroupMapping.computeIfAbsent(nodeId, groupIdList -> new HashSet<>()).add(groupId);
|
|
}
|
|
|
|
public void removeGroup(final String nodeId, final Uint32 groupId) {
|
|
- deviceGroupMapping.computeIfPresent(nodeId, (node, groupIds) -> groupIds).remove(groupId);
|
|
+ deviceGroupMapping.computeIfPresent(nodeId, (node, groupIds) -> groupIds).remove(groupId); // O(1) with HashSet
|
|
}
|
|
|
|
public void clearNodeGroups(final String nodeId) {
|