From: guillaume.lambert Date: Fri, 27 Nov 2020 20:06:18 +0000 (+0100) Subject: use ternary operators in portmapping X-Git-Tag: 2.2.0~32 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=dc7a551ec0f22fb67a0cbeec06b8b7c8a18c813e;p=transportpce.git use ternary operators in portmapping use ternary operators for conditional assignments rather than if-else-blocks JIRA: TRNSPRTPCE-353 Signed-off-by: guillaume.lambert Change-Id: I5eeb644ee0ecf80ab65872c7562bfa7ce9869431 (cherry picked from commit 853232de9e2c09133ddb7c1b91eda800fcf4d0e4) --- diff --git a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121.java b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121.java index a214d5fdb..5f3ff28c0 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121.java @@ -294,22 +294,16 @@ public class PortMappingVersion121 { Collection connectionMap = deviceObject.get().nonnullConnectionMap().values(); for (ConnectionMap cm : connectionMap) { - String slcp = null; - String dlcp = null; 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) { 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)); @@ -327,14 +321,9 @@ public class PortMappingVersion121 { .CircuitPacks>> getSrgCps(String deviceId, Info ordmInfo) { HashMap> 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 srgCps = new ArrayList<>(); @@ -476,15 +465,10 @@ public class PortMappingVersion121 { private List getDegrees(String deviceId, Info ordmInfo) { List 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); @@ -503,13 +487,8 @@ public class PortMappingVersion121 { private Map> getPerDegreePorts(String deviceId, Info ordmInfo) { Map> 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 deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class) diff --git a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion221.java b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion221.java index 3a099db76..ddd351927 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion221.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion221.java @@ -423,12 +423,8 @@ public class PortMappingVersion221 { } else { Collection connectionMap = deviceObject.get().nonnullConnectionMap().values(); for (ConnectionMap cm : connectionMap) { - String slcp = null; - String dlcp = null; 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 (slcp == null) { @@ -436,9 +432,7 @@ public class PortMappingVersion221 { skey, dkey); continue; } - if (lcpMap.containsKey(dkey)) { - dlcp = lcpMap.get(dkey); - } + 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)); @@ -515,14 +509,9 @@ public class PortMappingVersion221 { .CircuitPacks>> getSrgCps(String deviceId, Info ordmInfo) { HashMap> 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 srgCps = new ArrayList<>(); @@ -650,15 +639,10 @@ public class PortMappingVersion221 { private List getDegrees(String deviceId, Info ordmInfo) { List 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); @@ -678,14 +662,9 @@ public class PortMappingVersion221 { private List getSrgs(String deviceId, Info ordmInfo) { List 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 srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class) .child(SharedRiskGroup.class, new SharedRiskGroupKey(Uint16.valueOf(srgCounter))); @@ -702,13 +681,8 @@ public class PortMappingVersion221 { private Map> getPerDegreePorts(String deviceId, Info ordmInfo) { Map> 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 deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class) diff --git a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion710.java b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion710.java index 362d67e55..f7f7ae7c6 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion710.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion710.java @@ -422,12 +422,8 @@ public class PortMappingVersion710 { } else { Collection connectionMap = deviceObject.get().nonnullConnectionMap().values(); for (ConnectionMap cm : connectionMap) { - String slcp = null; - String dlcp = null; 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 (slcp == null) { @@ -435,9 +431,7 @@ public class PortMappingVersion710 { skey, dkey); continue; } - if (lcpMap.containsKey(dkey)) { - dlcp = lcpMap.get(dkey); - } + 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)); @@ -514,14 +508,9 @@ public class PortMappingVersion710 { .CircuitPacks>> getSrgCps(String deviceId, Info ordmInfo) { HashMap> 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 srgCps = new ArrayList<>(); @@ -666,15 +655,10 @@ public class PortMappingVersion710 { private List getDegrees(String deviceId, Info ordmInfo) { List 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); @@ -694,14 +678,9 @@ public class PortMappingVersion710 { private List getSrgs(String deviceId, Info ordmInfo) { List 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 srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class) .child(SharedRiskGroup.class, new SharedRiskGroupKey(Uint16.valueOf(srgCounter))); @@ -718,13 +697,8 @@ public class PortMappingVersion710 { private Map> getPerDegreePorts(String deviceId, Info ordmInfo) { Map> 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 deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)