use ternary operators in portmapping
[transportpce.git] / common / src / main / java / org / opendaylight / transportpce / common / mapping / PortMappingVersion221.java
index f0467ae02f89162ecfadfac0528f02c0cf369c49..ddd351927713b2e4f952c51dce332e2512570bb8 100644 (file)
@@ -9,13 +9,13 @@
 package org.opendaylight.transportpce.common.mapping;
 
 import com.google.common.util.concurrent.FluentFuture;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Optional;
@@ -418,31 +418,27 @@ public class PortMappingVersion221 {
             }
         }
 
-        if (device.getConnectionMap() != null) {
+        if (device.getConnectionMap() == null) {
+            LOG.warn("No connection-map inside device configuration");
+        } else {
             Collection<ConnectionMap> connectionMap = deviceObject.get().nonnullConnectionMap().values();
-            String slcp = null;
-            String dlcp = null;
             for (ConnectionMap cm : connectionMap) {
                 String skey = cm.getSource().getCircuitPackName() + "+" + cm.getSource().getPortName();
-                if (lcpMap.containsKey(skey)) {
-                    slcp = lcpMap.get(skey);
-                }
+                String slcp = lcpMap.containsKey(skey) ? lcpMap.get(skey) : null;
                 Destination destination0 = cm.nonnullDestination().values().iterator().next();
                 String dkey = destination0.getCircuitPackName() + "+" + destination0.getPortName();
-                if (lcpMap.containsKey(dkey)) {
-                    dlcp = lcpMap.get(dkey);
-                }
-                if (slcp != null) {
-                    Mapping mapping = mappingMap.get(slcp);
-                    mappingMap.remove(slcp);
-                    portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping, dlcp, null));
-                } else {
-                    LOG.error("Error in connection-map analysis");
+                if (slcp == null) {
+                    LOG.error("Error in connection-map analysis for source {} and destination (circuitpack+port) {}",
+                        skey, dkey);
+                    continue;
                 }
+                String dlcp = lcpMap.containsKey(dkey) ? lcpMap.get(dkey) : null;
+                Mapping mapping = mappingMap.get(slcp);
+                mappingMap.remove(slcp);
+                portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping, dlcp, null));
             }
-        } else {
-            LOG.warn("No connection-map inside device configuration");
         }
+
         if (device.getOduSwitchingPools() != null) {
             Collection<OduSwitchingPools> oduSwithcingPools = device.nonnullOduSwitchingPools().values();
             List<SwitchingPoolLcp> switchingPoolList = new ArrayList<>();
@@ -513,14 +509,9 @@ public class PortMappingVersion221 {
         .CircuitPacks>> getSrgCps(String deviceId, Info ordmInfo) {
         HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg
             .CircuitPacks>> cpPerSrg = new HashMap<>();
-        Integer maxSrg;
         // Get value for max Srg from info subtree, required for iteration
         // if not present assume to be 20 (temporary)
-        if (ordmInfo.getMaxSrgs() != null) {
-            maxSrg = ordmInfo.getMaxSrgs().toJava();
-        } else {
-            maxSrg = 20;
-        }
+        Integer maxSrg = ordmInfo.getMaxSrgs() == null ? 20 : ordmInfo.getMaxSrgs().toJava();
         for (int srgCounter = 1; srgCounter <= maxSrg; srgCounter++) {
             List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg.CircuitPacks> srgCps
                 = new ArrayList<>();
@@ -648,15 +639,10 @@ public class PortMappingVersion221 {
 
     private List<Degree> getDegrees(String deviceId, Info ordmInfo) {
         List<Degree> degrees = new ArrayList<>();
-        Integer maxDegree;
 
         // Get value for max degree from info subtree, required for iteration
         // if not present assume to be 20 (temporary)
-        if (ordmInfo.getMaxDegrees() != null) {
-            maxDegree = ordmInfo.getMaxDegrees().toJava();
-        } else {
-            maxDegree = 20;
-        }
+        Integer maxDegree = ordmInfo.getMaxDegrees() == null ? 20 : ordmInfo.getMaxDegrees().toJava();
 
         for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) {
             LOG.info("Getting Connection ports for Degree Number {}", degreeCounter);
@@ -676,14 +662,9 @@ public class PortMappingVersion221 {
     private List<SharedRiskGroup> getSrgs(String deviceId, Info ordmInfo) {
         List<SharedRiskGroup> srgs = new ArrayList<>();
 
-        Integer maxSrg;
         // Get value for max Srg from info subtree, required for iteration
         // if not present assume to be 20 (temporary)
-        if (ordmInfo.getMaxSrgs() != null) {
-            maxSrg = ordmInfo.getMaxSrgs().toJava();
-        } else {
-            maxSrg = 20;
-        }
+        Integer maxSrg = ordmInfo.getMaxSrgs() == null ? 20 : ordmInfo.getMaxSrgs().toJava();
         for (int srgCounter = 1; srgCounter <= maxSrg; srgCounter++) {
             InstanceIdentifier<SharedRiskGroup> srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
                 .child(SharedRiskGroup.class, new SharedRiskGroupKey(Uint16.valueOf(srgCounter)));
@@ -700,13 +681,8 @@ public class PortMappingVersion221 {
 
     private Map<Integer, List<ConnectionPorts>> getPerDegreePorts(String deviceId, Info ordmInfo) {
         Map<Integer, List<ConnectionPorts>> conPortMap = new HashMap<>();
-        Integer maxDegree;
+        Integer maxDegree = ordmInfo.getMaxDegrees() == null ? 20 : ordmInfo.getMaxDegrees().toJava();
 
-        if (ordmInfo.getMaxDegrees() != null) {
-            maxDegree = ordmInfo.getMaxDegrees().toJava();
-        } else {
-            maxDegree = 20;
-        }
         for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) {
             LOG.info("Getting Connection ports for Degree Number {}", degreeCounter);
             InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
@@ -981,9 +957,10 @@ public class PortMappingVersion221 {
             List<Class<? extends org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327
                 .SupportedIfCapability>> supportedIntf = new ArrayList<>();
             for (Class<? extends SupportedIfCapability> sup: port.getSupportedInterfaceCapability()) {
-                Class<? extends org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327
-                    .SupportedIfCapability> sup1 = (Class<? extends org.opendaylight.yang.gen.v1
-                        .http.org.openroadm.port.types.rev200327.SupportedIfCapability>) sup;
+                @SuppressWarnings("unchecked") Class<? extends org.opendaylight.yang.gen.v1
+                    .http.org.openroadm.port.types.rev200327.SupportedIfCapability> sup1 =
+                        (Class<? extends org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327
+                            .SupportedIfCapability>) sup;
                 supportedIntf.add(sup1);
             }
             mpBldr.setSupportedInterfaceCapability(supportedIntf);
@@ -1000,7 +977,6 @@ public class PortMappingVersion221 {
 
     //some LOG messages are too long
     @SuppressWarnings("checkstyle:linelength")
-    @SuppressFBWarnings("DM_CONVERT_CASE")
     private boolean createTtpPortMapping(String nodeId, Info deviceInfo, List<Mapping> portMapList) {
         // Creating mapping data for degree TTP's
         List<Degree> degrees = getDegrees(nodeId, deviceInfo);
@@ -1095,15 +1071,21 @@ public class PortMappingVersion221 {
                                 && port1.getPartnerPort().getPortName().equals(port2.getPortName())
                                 && port2.getPartnerPort().getCircuitPackName().equals(cp1Name)
                                 && port2.getPartnerPort().getPortName().equals(port1.getPortName()))) {
-                            String logicalConnectionPoint1 = new StringBuilder("DEG").append(cpMapEntry.getKey()).append("-TTP-")
-                                .append(port1.getPortDirection().getName().toUpperCase()).toString();
+                            String logicalConnectionPoint1 = new StringBuilder("DEG")
+                                .append(cpMapEntry.getKey())
+                                .append("-TTP-")
+                                .append(port1.getPortDirection().getName().toUpperCase(Locale.getDefault()))
+                                .toString();
                             LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId,
                                 connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName(), port1.getPortName(),
                                 logicalConnectionPoint1);
                             portMapList.add(createMappingObject(nodeId, port1, connectionPortMap.get(cpMapEntry.getKey()).get(0)
                                 .getCircuitPackName(), logicalConnectionPoint1));
-                            String logicalConnectionPoint2 = new StringBuilder("DEG").append(cpMapEntry.getKey()).append("-TTP-")
-                                .append(port2.getPortDirection().getName().toUpperCase()).toString();
+                            String logicalConnectionPoint2 = new StringBuilder("DEG")
+                                .append(cpMapEntry.getKey())
+                                .append("-TTP-")
+                                .append(port2.getPortDirection().getName().toUpperCase(Locale.getDefault()))
+                                .toString();
                             LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId,
                                 connectionPortMap.get(cpMapEntry.getKey()).get(1).getCircuitPackName(), port2.getPortName(),
                                 logicalConnectionPoint2);