Martin Mucha has uploaded a new change for review.

Change subject: core: refactor: renamed variables + extracted creating map
......................................................................

core: refactor: renamed variables + extracted creating map

• Map<String, List<NetworkType>> nicsToNetworks —> Map<String, 
List<NetworkType>> nicNameToNetworkTypesMap
• Entry<String, List<NetworkType>> nicToNetworkTypes —> Entry<String, 
List<NetworkType>> nicNameToNetworkTypes
• extracted code creating map into method createNicNameToNetworkTypesMap

Change-Id: I7e0a7875a3f5356455f132af23d56d62f00d1989
Signed-off-by: Martin Mucha <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkAttachmentsValidator.java
1 file changed, 23 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/45/36145/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkAttachmentsValidator.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkAttachmentsValidator.java
index b7543cf..2e50c20 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkAttachmentsValidator.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkAttachmentsValidator.java
@@ -7,6 +7,7 @@
 import java.util.Map;
 import java.util.Map.Entry;
 
+import org.apache.commons.collections.Bag;
 import org.apache.commons.collections.bag.HashBag;
 import org.ovirt.engine.core.bll.ValidationResult;
 import org.ovirt.engine.core.common.businessentities.BusinessEntityMap;
@@ -32,21 +33,11 @@
     }
 
     public ValidationResult validateNetworkExclusiveOnNics() {
-        Map<String, List<NetworkType>> nicsToNetworks = new HashMap<>();
-        for (NetworkAttachment attachment : attachmentsToConfigure) {
-            String nicName = attachment.getNicName();
-            if (!nicsToNetworks.containsKey(nicName)) {
-                nicsToNetworks.put(nicName, new ArrayList<NetworkType>());
-            }
-
-            Network networkToConfigure = 
networkMap.get(attachment.getNetworkId());
-            
nicsToNetworks.get(nicName).add(determineNetworkType(networkToConfigure));
-        }
-
+        Map<String, List<NetworkType>> nicNameToNetworkTypesMap = 
createNicNameToNetworkTypesMap();
         List<String> violatedNics = new ArrayList<>();
-        for (Entry<String, List<NetworkType>> nicToNetworkTypes : 
nicsToNetworks.entrySet()) {
-            if (!validateNetworkExclusiveOnNic(nicToNetworkTypes.getKey(), 
nicToNetworkTypes.getValue())) {
-                violatedNics.add(nicToNetworkTypes.getKey());
+        for (Entry<String, List<NetworkType>> nicNameToNetworkTypes : 
nicNameToNetworkTypesMap.entrySet()) {
+            if (!validateNetworkExclusiveOnNic(nicNameToNetworkTypes.getKey(), 
nicNameToNetworkTypes.getValue())) {
+                violatedNics.add(nicNameToNetworkTypes.getKey());
             }
         }
 
@@ -57,6 +48,21 @@
         }
     }
 
+    private Map<String, List<NetworkType>> createNicNameToNetworkTypesMap() {
+        Map<String, List<NetworkType>> nicNameToNetworkTypes = new HashMap<>();
+        for (NetworkAttachment attachment : attachmentsToConfigure) {
+            String nicName = attachment.getNicName();
+            if (!nicNameToNetworkTypes.containsKey(nicName)) {
+                nicNameToNetworkTypes.put(nicName, new 
ArrayList<NetworkType>());
+            }
+
+            Network networkToConfigure = 
networkMap.get(attachment.getNetworkId());
+            
nicNameToNetworkTypes.get(nicName).add(determineNetworkType(networkToConfigure));
+        }
+        return nicNameToNetworkTypes;
+    }
+
+    //TODO MM: move to Network?
     private NetworkType determineNetworkType(Network network) {
         return NetworkUtils.isVlan(network)
                 ? NetworkType.VLAN
@@ -73,7 +79,7 @@
             return true;
         }
 
-        HashBag networkTypes = new HashBag(networksOnIface);
+        Bag networkTypes = new HashBag(networksOnIface);
         if (networkTypes.contains(NetworkType.VM) && networkTypes.size() > 1
                 || networkTypes.contains(NetworkType.NON_VM) && 
networkTypes.getCount(NetworkType.NON_VM) > 1) {
             return false;
@@ -82,6 +88,8 @@
         return true;
     }
 
+    /*TODO MM: wouldn't this make more sense on Network class? ~ all existing 
methods can stay, but this can be used in
+    situations like this + for validity checking of all potential permutations 
of flags.*/
     private enum NetworkType {
         VM,
         NON_VM,


-- 
To view, visit http://gerrit.ovirt.org/36145
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7e0a7875a3f5356455f132af23d56d62f00d1989
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Martin Mucha <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to