From d42baa009f97e1bd51b646edc1c247657b976685 Mon Sep 17 00:00:00 2001 From: Ryan Moats Date: Sun, 3 Nov 2013 09:47:24 -0600 Subject: [PATCH] Refactor if/else with dead branch to explain corner case better 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 --- .../networkconfig/neutron/NeutronSubnet.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/opendaylight/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet.java b/opendaylight/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet.java index 1072a344b0..d791939486 100644 --- a/opendaylight/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet.java +++ b/opendaylight/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet.java @@ -341,15 +341,18 @@ public class NeutronSubnet { List newList = new ArrayList(); // we have to modify a separate list while (i.hasNext()) { NeutronSubnet_IPAllocationPool pool = i.next(); - if (pool.getPoolEnd().equalsIgnoreCase(ipAddress) && - pool.getPoolStart().equalsIgnoreCase(ipAddress)) - ; // do nothing, i.e. don't add the current pool to the new list - else + /* if the pool contains a single address element and we are allocating it + * then we don't need to copy the pool over. Otherwise, we need to possibly + * split the pool and add both pieces to the new list + */ + if (!(pool.getPoolEnd().equalsIgnoreCase(ipAddress) && + pool.getPoolStart().equalsIgnoreCase(ipAddress))) { if (pool.contains(ipAddress)) { List pools = pool.splitPool(ipAddress); newList.addAll(pools); } else newList.add(pool); + } } allocationPools = newList; } -- 2.36.6