Sho SHIMIZU
Committed by Gerrit Code Review

Refactor: Reduce use of null

Change-Id: I5b7197481553be38a664568ec1122854c2597989
...@@ -393,7 +393,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu ...@@ -393,7 +393,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
393 return null; 393 return null;
394 } 394 }
395 395
396 - private OchPort findAvailableOchPort(ConnectPoint oduPort, OduSignalType ochPortSignalType) { 396 + private Optional<OchPort> findAvailableOchPort(ConnectPoint oduPort, OduSignalType ochPortSignalType) {
397 // First see if the port mappings are constrained 397 // First see if the port mappings are constrained
398 ConnectPoint ochCP = staticPort(oduPort); 398 ConnectPoint ochCP = staticPort(oduPort);
399 399
...@@ -408,9 +408,9 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu ...@@ -408,9 +408,9 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
408 .findAny(); 408 .findAny();
409 409
410 if (isAvailable(intentId.orElse(null))) { 410 if (isAvailable(intentId.orElse(null))) {
411 - return ochPort; 411 + return Optional.of(ochPort);
412 } 412 }
413 - return null; 413 + return Optional.empty();
414 } 414 }
415 415
416 // No port constraints, so find any port that works 416 // No port constraints, so find any port that works
...@@ -438,11 +438,11 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu ...@@ -438,11 +438,11 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
438 .findAny(); 438 .findAny();
439 439
440 if (isAvailable(intentId.orElse(null))) { 440 if (isAvailable(intentId.orElse(null))) {
441 - return (OchPort) port; 441 + return Optional.of((OchPort) port);
442 } 442 }
443 } 443 }
444 444
445 - return null; 445 + return Optional.empty();
446 } 446 }
447 447
448 private Pair<OchPort, OchPort> findPorts(ConnectPoint src, ConnectPoint dst, CltSignalType signalType) { 448 private Pair<OchPort, OchPort> findPorts(ConnectPoint src, ConnectPoint dst, CltSignalType signalType) {
...@@ -451,31 +451,21 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu ...@@ -451,31 +451,21 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
451 case CLT_1GBE: 451 case CLT_1GBE:
452 case CLT_10GBE: 452 case CLT_10GBE:
453 // First search for OCH ports with OduSignalType of ODU2. If not found - search for those with ODU4 453 // First search for OCH ports with OduSignalType of ODU2. If not found - search for those with ODU4
454 - Pair<OchPort, OchPort> ochPorts = findPorts(src, dst, OduSignalType.ODU2); 454 + return findPorts(src, dst, OduSignalType.ODU2)
455 - if (ochPorts == null) { 455 + .orElse(findPorts(src, dst, OduSignalType.ODU4).orElse(null));
456 - ochPorts = findPorts(src, dst, OduSignalType.ODU4);
457 - }
458 - return ochPorts;
459 case CLT_100GBE: 456 case CLT_100GBE:
460 - return findPorts(src, dst, OduSignalType.ODU4); 457 + return findPorts(src, dst, OduSignalType.ODU4).orElse(null);
461 case CLT_40GBE: 458 case CLT_40GBE:
462 default: 459 default:
463 return null; 460 return null;
464 } 461 }
465 } 462 }
466 463
467 - private Pair<OchPort, OchPort> findPorts(ConnectPoint src, ConnectPoint dst, OduSignalType ochPortSignalType) { 464 + private Optional<Pair<OchPort, OchPort>> findPorts(ConnectPoint src, ConnectPoint dst,
468 - OchPort srcPort = findAvailableOchPort(src, ochPortSignalType); 465 + OduSignalType ochPortSignalType) {
469 - if (srcPort == null) { 466 + return findAvailableOchPort(src, ochPortSignalType)
470 - return null; 467 + .flatMap(srcOch ->
471 - } 468 + findAvailableOchPort(dst, ochPortSignalType).map(dstOch -> Pair.of(srcOch, dstOch)));
472 -
473 - OchPort dstPort = findAvailableOchPort(dst, ochPortSignalType);
474 - if (dstPort == null) {
475 - return null;
476 - }
477 -
478 - return Pair.of(srcPort, dstPort);
479 } 469 }
480 470
481 /** 471 /**
......