Migrate Optional.get() callers
[transportpce.git] / common / src / main / java / org / opendaylight / transportpce / common / mapping / PortMappingVersion121.java
index 07578f9ae80971f963d779dfaaac0bd1d3bde5b1..37016acb0aaad253b60d81df9dc1f4ac8a0cb73d 100644 (file)
@@ -119,7 +119,7 @@ public class PortMappingVersion121 {
             LOG.warn(PortMappingUtils.DEVICE_HAS_LOGMSG, nodeId, "no info", "subtree");
             return false;
         }
-        Info deviceInfo = deviceInfoOptional.get();
+        Info deviceInfo = deviceInfoOptional.orElseThrow();
         NodeInfo nodeInfo = createNodeInfo(deviceInfo);
         if (nodeInfo == null) {
             return false;
@@ -174,7 +174,7 @@ public class PortMappingVersion121 {
             .build();
         try {
             Ports port = deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL,
-                portId, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT).get();
+                portId, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT).orElseThrow();
             Mapping newMapping = updateMappingObject(nodeId, port, oldMapping);
             LOG.debug(PortMappingUtils.UPDATE_MAPPING_LOGMSG,
                 nodeId, oldMapping, oldMapping.getLogicalConnectionPoint(), newMapping);
@@ -204,7 +204,7 @@ public class PortMappingVersion121 {
             LOG.error(PortMappingUtils.CANNOT_GET_DEV_CONF_LOGMSG, nodeId);
             return false;
         }
-        OrgOpenroadmDevice device = deviceObject.get();
+        OrgOpenroadmDevice device = deviceObject.orElseThrow();
         if (device.getCircuitPacks() == null) {
             LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, PortMappingUtils.FOUND);
             return false;
@@ -235,7 +235,7 @@ public class PortMappingVersion121 {
             }
         }
 
-        for (ConnectionMap cm : deviceObject.get().nonnullConnectionMap().values()) {
+        for (ConnectionMap cm : deviceObject.orElseThrow().nonnullConnectionMap().values()) {
             String skey = cm.getSource().getCircuitPackName() + "+" + cm.getSource().getPortName();
             Destination destination0 = cm.nonnullDestination().values().iterator().next();
             String dkey = destination0.getCircuitPackName() + "+" + destination0.getPortName();
@@ -292,8 +292,8 @@ public class PortMappingVersion121 {
                 LogicalDatastoreType.OPERATIONAL, srgIID,
                 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
             if (ordmSrgObject.isPresent()) {
-                srgCps.addAll(ordmSrgObject.get().nonnullCircuitPacks().values());
-                cpPerSrg.put(ordmSrgObject.get().getSrgNumber().toJava(), srgCps);
+                srgCps.addAll(ordmSrgObject.orElseThrow().nonnullCircuitPacks().values());
+                cpPerSrg.put(ordmSrgObject.orElseThrow().getSrgNumber().toJava(), srgCps);
             }
         }
         LOG.info(PortMappingUtils.DEVICE_HAS_LOGMSG, deviceId, cpPerSrg.size(), "SRG");
@@ -374,13 +374,13 @@ public class PortMappingVersion121 {
             .getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, port2ID,
                 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
         if (port2Object.isEmpty()
-                || port2Object.get().getPortQual().getIntValue() != Port.PortQual.RoadmExternal.getIntValue()) {
+                || port2Object.orElseThrow().getPortQual().getIntValue() != Port.PortQual.RoadmExternal.getIntValue()) {
             LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG + PortMappingUtils.PARTNERPORT_GET_ERROR_LOGMSG,
                 nodeId, port.getPartnerPort().getPortName(), port.getPartnerPort().getCircuitPackName(),
                 port.getPortName(), circuitPackName);
             return null;
         }
-        Ports port2 = port2Object.get();
+        Ports port2 = port2Object.orElseThrow();
         if (!checkPartnerPort(circuitPackName, port, port2)) {
             LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG + PortMappingUtils.PARTNERPORT_CONF_ERROR_LOGMSG,
                 nodeId, port2.getPortName(), port.getPartnerPort().getCircuitPackName(),
@@ -405,11 +405,11 @@ public class PortMappingVersion121 {
                 nodeId, circuitPackName);
             return new ArrayList<>();
         }
-        if (circuitPackObject.get().getPorts() == null) {
+        if (circuitPackObject.orElseThrow().getPorts() == null) {
             LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, PortMappingUtils.FOUND, circuitPackName);
             return new ArrayList<>();
         }
-        return new ArrayList<>(circuitPackObject.get().nonnullPorts().values());
+        return new ArrayList<>(circuitPackObject.orElseThrow().nonnullPorts().values());
     }
 
     private String createLogicalConnectionPort(Ports port, int index, int portIndex) {
@@ -441,7 +441,7 @@ public class PortMappingVersion121 {
                 LogicalDatastoreType.OPERATIONAL, deviceIID,
                 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
             if (ordmDegreeObject.isPresent()) {
-                degrees.put(degreeCounter, ordmDegreeObject.get());
+                degrees.put(degreeCounter, ordmDegreeObject.orElseThrow());
             }
         }
         LOG.info(PortMappingUtils.DEVICE_HAS_LOGMSG,
@@ -465,12 +465,12 @@ public class PortMappingVersion121 {
         Optional<Protocols> protocolObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
             LogicalDatastoreType.OPERATIONAL, protocoliid, Timeouts.DEVICE_READ_TIMEOUT,
             Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-        if (protocolObject.isEmpty() || protocolObject.get().augmentation(Protocols1.class).getLldp() == null) {
+        if (protocolObject.isEmpty() || protocolObject.orElseThrow().augmentation(Protocols1.class).getLldp() == null) {
             LOG.warn(PortMappingUtils.PROCESSING_DONE_LOGMSG, nodeId, PortMappingUtils.CANNOT_GET_LLDP_CONF_LOGMSG);
             return new HashMap<>();
         }
         Map<String, String> cpToInterfaceMap = new HashMap<>();
-        Lldp lldp = protocolObject.get().augmentation(Protocols1.class).getLldp();
+        Lldp lldp = protocolObject.orElseThrow().augmentation(Protocols1.class).getLldp();
         for (PortConfig portConfig : lldp.nonnullPortConfig().values()) {
             if (!portConfig.getAdminStatus().equals(PortConfig.AdminStatus.Txandrx)) {
                 continue;
@@ -482,10 +482,10 @@ public class PortMappingVersion121 {
             Optional<Interface> interfaceObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
                 LogicalDatastoreType.OPERATIONAL, interfaceIID, Timeouts.DEVICE_READ_TIMEOUT,
                 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-            if (interfaceObject.isEmpty() || interfaceObject.get().getSupportingCircuitPackName() == null) {
+            if (interfaceObject.isEmpty() || interfaceObject.orElseThrow().getSupportingCircuitPackName() == null) {
                 continue;
             }
-            String supportingCircuitPackName = interfaceObject.get().getSupportingCircuitPackName();
+            String supportingCircuitPackName = interfaceObject.orElseThrow().getSupportingCircuitPackName();
             cpToInterfaceMap.put(supportingCircuitPackName, portConfig.getIfName());
             InstanceIdentifier<CircuitPacks> circuitPacksIID = InstanceIdentifier
                 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
@@ -494,10 +494,10 @@ public class PortMappingVersion121 {
             Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(
                 nodeId, LogicalDatastoreType.OPERATIONAL, circuitPacksIID, Timeouts.DEVICE_READ_TIMEOUT,
                 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-            if (circuitPackObject.isEmpty() || circuitPackObject.get().getParentCircuitPack() == null) {
+            if (circuitPackObject.isEmpty() || circuitPackObject.orElseThrow().getParentCircuitPack() == null) {
                 continue;
             }
-            cpToInterfaceMap.put(circuitPackObject.get().getParentCircuitPack().getCircuitPackName(),
+            cpToInterfaceMap.put(circuitPackObject.orElseThrow().getParentCircuitPack().getCircuitPackName(),
                 portConfig.getIfName());
         }
         LOG.info(PortMappingUtils.PROCESSING_DONE_LOGMSG, nodeId, " - success");
@@ -619,8 +619,9 @@ public class PortMappingVersion121 {
                     nodeId, interfaces.getInterfaceName() + "- empty interface");
                 continue;
             }
-            InterfaceType interfaceType = openRoadmInterface.get().getType();
-            LOG.debug(PortMappingUtils.GOT_INTF_LOGMSG, nodeId, openRoadmInterface.get().getName(), interfaceType);
+            InterfaceType interfaceType = openRoadmInterface.orElseThrow().getType();
+            LOG.debug(PortMappingUtils.GOT_INTF_LOGMSG, nodeId, openRoadmInterface.orElseThrow().getName(),
+                    interfaceType);
             // Switch/Case might be more indicated here but is not possible in jdk17 w/o enable-preview
             if (interfaceType.equals(OpenROADMOpticalMultiplex.VALUE)) {
                 mpBldr.setSupportingOms(interfaces.getInterfaceName());
@@ -707,7 +708,7 @@ public class PortMappingVersion121 {
             LOG.error(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, port.getPartnerPort().getCircuitPackName());
             return null;
         }
-        Optional<Ports> poOpt = cpOpt.get().nonnullPorts().values().stream()
+        Optional<Ports> poOpt = cpOpt.orElseThrow().nonnullPorts().values().stream()
             .filter(p -> p.getPortName().equals(port.getPartnerPort().getPortName()))
             .findFirst();
         if (poOpt.isEmpty()) {
@@ -715,8 +716,8 @@ public class PortMappingVersion121 {
                 nodeId, port.getPartnerPort().getPortName(), port.getPartnerPort().getCircuitPackName());
             return null;
         }
-        Ports port2 = poOpt.get();
-        circuitPackName2.append(cpOpt.get().getCircuitPackName());
+        Ports port2 = poOpt.orElseThrow();
+        circuitPackName2.append(cpOpt.orElseThrow().getCircuitPackName());
         if (!checkPartnerPort(circuitPackName, port, port2)) {
             LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
                 nodeId, port2.getPortName(), circuitPackName2, port.getPortName(), circuitPackName);
@@ -905,7 +906,7 @@ public class PortMappingVersion121 {
             LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp.getPortName(), cpName);
             return null;
         }
-        return portObject.get();
+        return portObject.orElseThrow();
     }
 
     private boolean checkPortQual(Ports port, String cpName, String nodeId) {