Refactor PCE network analyzer PceOtnNode step 6 73/99873/2
authorguillaume.lambert <guillaume.lambert@orange.com>
Fri, 25 Feb 2022 11:04:19 +0000 (12:04 +0100)
committerguillaume.lambert <guillaume.lambert@orange.com>
Mon, 28 Feb 2022 10:57:50 +0000 (11:57 +0100)
Add 2 new methods to decrease checkSwPool cyclomatic complexity
currently warned by Sonar

JIRA: TRNSPRTPCE-572
Signed-off-by: guillaume.lambert <guillaume.lambert@orange.com>
Change-Id: Id5e4f4ee7f5f0204fe191e8c17255054c4a9adf4

pce/src/main/java/org/opendaylight/transportpce/pce/networkanalyzer/PceOtnNode.java

index 3ef3cf2fbb37a30e4fa7682e21403f9b881b5225..2e61eb4bcb01596ec23ad5d7a10daca03fe0b77c 100644 (file)
@@ -240,39 +240,14 @@ public class PceOtnNode implements PceNode {
         switch (modeType) {
 
             case "intermediate":
-                for (NonBlockingList nbl: nblList) {
-                    for (TpId nwTp : netwTps) {
-                        if (nbl.getTpList().contains(nwTp)) {
-                            usableXpdrNWTps.add(nwTp);
-                        }
-                        if (usableXpdrNWTps.size() >= 2) {
-                            return true;
-                        }
-                    }
-                }
-                return false;
+                return checkIntermediateSwPool(nblList, netwTps);
 
             case "AZ":
                 if (clientTps == null) {
                     return false;
                 }
                 clientTps.sort(Comparator.comparing(TpId::getValue));
-                for (NonBlockingList nbl: nblList) {
-                    for (TpId nwTp : netwTps) {
-                        for (TpId clTp : clientTps) {
-                            if (nbl.getTpList().contains(clTp) && nbl.getTpList().contains(nwTp)) {
-                                usableXpdrClientTps.add(clTp);
-                                usableXpdrNWTps.add(nwTp);
-                            }
-                            if (usableXpdrClientTps.size() >= 1 && usableXpdrNWTps.size() >= 1
-                                    && (this.clientPort == null || this.clientPort.equals(clTp.getValue()))) {
-                                clientPerNwTp.put(nwTp.getValue(), clTp.getValue());
-                                return true;
-                            }
-                        }
-                    }
-                }
-                return false;
+                return checkAzSwPool(nblList, netwTps, clientTps);
 
             default:
                 LOG.error("Unsupported mode type {}", modeType);
@@ -280,6 +255,41 @@ public class PceOtnNode implements PceNode {
         }
     }
 
+
+    private boolean checkIntermediateSwPool(List<NonBlockingList> nblList, List<TpId> netwTps) {
+        for (NonBlockingList nbl: nblList) {
+            for (TpId nwTp : netwTps) {
+                if (nbl.getTpList().contains(nwTp)) {
+                    usableXpdrNWTps.add(nwTp);
+                }
+                if (usableXpdrNWTps.size() >= 2) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+
+    private boolean checkAzSwPool(List<NonBlockingList> nblList, List<TpId> netwTps, List<TpId> clientTps) {
+        for (NonBlockingList nbl: nblList) {
+            for (TpId nwTp : netwTps) {
+                for (TpId clTp : clientTps) {
+                    if (nbl.getTpList().contains(clTp) && nbl.getTpList().contains(nwTp)) {
+                        usableXpdrClientTps.add(clTp);
+                        usableXpdrNWTps.add(nwTp);
+                    }
+                    if (usableXpdrClientTps.size() >= 1 && usableXpdrNWTps.size() >= 1
+                            && (this.clientPort == null || this.clientPort.equals(clTp.getValue()))) {
+                        clientPerNwTp.put(nwTp.getValue(), clTp.getValue());
+                        return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
     private boolean checkTpForOdtuTermination(TerminationPoint1 ontTp1) {
         for (SupportedInterfaceCapability sic : ontTp1.getTpSupportedInterfaces().getSupportedInterfaceCapability()
                 .values()) {