Sho SHIMIZU
Committed by Gerrit Code Review

Refactor: Simplify method by Stream API

Change-Id: Iac7d43bb4ea4771a85ac10817cc8d25f42829917
...@@ -316,42 +316,18 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu ...@@ -316,42 +316,18 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
316 316
317 OduSignalType oduSignalType = mappingCltSignalTypeToOduSignalType(signalType); 317 OduSignalType oduSignalType = mappingCltSignalTypeToOduSignalType(signalType);
318 318
319 - for (Intent intent : intentService.getIntents()) { 319 + return Tools.stream(intentService.getIntents())
320 - if (!(intent instanceof OpticalConnectivityIntent)) { 320 + .filter(x -> x instanceof OpticalConnectivityIntent)
321 - continue; 321 + .map(x -> (OpticalConnectivityIntent) x)
322 - } 322 + .filter(x -> src.deviceId().equals(x.getSrc().deviceId()))
323 - 323 + .filter(x -> dst.deviceId().equals(x.getDst().deviceId()))
324 - OpticalConnectivityIntent connIntent = (OpticalConnectivityIntent) intent; 324 + .filter(x -> isAllowed(src, x.getSrc()))
325 - 325 + .filter(x -> isAllowed(dst, x.getDst()))
326 - // Ignore if the intents don't have identical src and dst devices 326 + .filter(x -> isAvailable(x.id()))
327 - if (!src.deviceId().equals(connIntent.getSrc().deviceId()) || 327 + .filter(x -> !multiplexingSupported ||
328 - !dst.deviceId().equals(connIntent.getDst().deviceId())) { 328 + isAvailableTributarySlots(x.getSrc(), x.getDst(), oduSignalType.tributarySlots()))
329 - continue; 329 + .findFirst()
330 - } 330 + .orElse(null);
331 -
332 - if (!isAllowed(src, connIntent.getSrc())) {
333 - continue;
334 - }
335 -
336 - if (!isAllowed(dst, connIntent.getDst())) {
337 - continue;
338 - }
339 -
340 - if (!isAvailable(connIntent.id())) {
341 - continue;
342 - }
343 -
344 - if (multiplexingSupported) {
345 - if (!isAvailableTributarySlots(connIntent.getSrc(), connIntent.getDst(),
346 - oduSignalType.tributarySlots())) {
347 - continue;
348 - }
349 - }
350 -
351 - return connIntent;
352 - }
353 -
354 - return null;
355 } 331 }
356 332
357 private boolean isAvailableTributarySlots(ConnectPoint src, ConnectPoint dst, int requestedTsNum) { 333 private boolean isAvailableTributarySlots(ConnectPoint src, ConnectPoint dst, int requestedTsNum) {
......