Refactor if/else with dead branch to explain corner case better 39/2339/2
authorRyan Moats <rmoats@us.ibm.com>
Sun, 3 Nov 2013 15:47:24 +0000 (09:47 -0600)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 5 Nov 2013 01:33:06 +0000 (01:33 +0000)
Change allocating address from subnet pool path to split the pool
in the main branch rather than the else and explain what happens
if the pool as a single address with a comment.

Change-Id: I3e910aecc2b251da419fc5d8055c2a9ccd975563
Signed-off-by: Ryan Moats <rmoats@us.ibm.com>
opendaylight/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet.java

index 1072a34..d791939 100644 (file)
@@ -341,15 +341,18 @@ public class NeutronSubnet {
         List<NeutronSubnet_IPAllocationPool> newList = new ArrayList<NeutronSubnet_IPAllocationPool>();    // we have to modify a separate list\r
         while (i.hasNext()) {\r
             NeutronSubnet_IPAllocationPool pool = i.next();\r
-            if (pool.getPoolEnd().equalsIgnoreCase(ipAddress) &&\r
-                    pool.getPoolStart().equalsIgnoreCase(ipAddress))\r
-                ; // do nothing, i.e. don't add the current pool to the new list\r
-            else\r
+            /* if the pool contains a single address element and we are allocating it\r
+             * then we don't need to copy the pool over.  Otherwise, we need to possibly\r
+             * split the pool and add both pieces to the new list\r
+             */\r
+            if (!(pool.getPoolEnd().equalsIgnoreCase(ipAddress) &&\r
+                    pool.getPoolStart().equalsIgnoreCase(ipAddress))) {\r
                 if (pool.contains(ipAddress)) {\r
                     List<NeutronSubnet_IPAllocationPool> pools = pool.splitPool(ipAddress);\r
                     newList.addAll(pools);\r
                 } else\r
                     newList.add(pool);\r
+            }\r
         }\r
         allocationPools = newList;\r
     }\r