Sho SHIMIZU
Committed by Gerrit Code Review

Refactor: Flip condition to reduce the depth of indentation

Change-Id: I572a989730a8dd93b5ab7ee63b37bc9d728c17e7
...@@ -373,37 +373,39 @@ public class IntentManager ...@@ -373,37 +373,39 @@ public class IntentManager
373 private void applyIntentData(IntentData data, 373 private void applyIntentData(IntentData data,
374 FlowRuleOperations.Builder builder, 374 FlowRuleOperations.Builder builder,
375 Direction direction) { 375 Direction direction) {
376 - if (data != null) { 376 + if (data == null) {
377 - List<Intent> intentsToApply = data.installables(); 377 + return;
378 - if (!intentsToApply.stream().allMatch(x -> x instanceof FlowRuleIntent)) { 378 + }
379 - throw new IllegalStateException("installable intents must be FlowRuleIntent");
380 - }
381 379
382 - if (direction == Direction.ADD) { 380 + List<Intent> intentsToApply = data.installables();
383 - trackerService.addTrackedResources(data.key(), data.intent().resources()); 381 + if (!intentsToApply.stream().allMatch(x -> x instanceof FlowRuleIntent)) {
384 - intentsToApply.forEach(installable -> 382 + throw new IllegalStateException("installable intents must be FlowRuleIntent");
385 - trackerService.addTrackedResources(data.key(), installable.resources())); 383 + }
386 - } else {
387 - trackerService.removeTrackedResources(data.key(), data.intent().resources());
388 - intentsToApply.forEach(installable ->
389 - trackerService.removeTrackedResources(data.intent().key(),
390 - installable.resources()));
391 - }
392 384
393 - // FIXME do FlowRuleIntents have stages??? Can we do uninstall work in parallel? I think so. 385 + if (direction == Direction.ADD) {
394 - builder.newStage(); 386 + trackerService.addTrackedResources(data.key(), data.intent().resources());
387 + intentsToApply.forEach(installable ->
388 + trackerService.addTrackedResources(data.key(), installable.resources()));
389 + } else {
390 + trackerService.removeTrackedResources(data.key(), data.intent().resources());
391 + intentsToApply.forEach(installable ->
392 + trackerService.removeTrackedResources(data.intent().key(),
393 + installable.resources()));
394 + }
395 395
396 - List<Collection<FlowRule>> stages = intentsToApply.stream() 396 + // FIXME do FlowRuleIntents have stages??? Can we do uninstall work in parallel? I think so.
397 - .map(x -> (FlowRuleIntent) x) 397 + builder.newStage();
398 - .map(FlowRuleIntent::flowRules)
399 - .collect(Collectors.toList());
400 398
401 - for (Collection<FlowRule> rules : stages) { 399 + List<Collection<FlowRule>> stages = intentsToApply.stream()
402 - if (direction == Direction.ADD) { 400 + .map(x -> (FlowRuleIntent) x)
403 - rules.forEach(builder::add); 401 + .map(FlowRuleIntent::flowRules)
404 - } else { 402 + .collect(Collectors.toList());
405 - rules.forEach(builder::remove); 403 +
406 - } 404 + for (Collection<FlowRule> rules : stages) {
405 + if (direction == Direction.ADD) {
406 + rules.forEach(builder::add);
407 + } else {
408 + rules.forEach(builder::remove);
407 } 409 }
408 } 410 }
409 411
......