From 924dac755af783e2e26f48077ad6a5483e5b1a91 Mon Sep 17 00:00:00 2001 From: Jeyrs Chabu Date: Thu, 30 Jan 2020 19:50:01 -0800 Subject: [PATCH] chore(exclusion): Simplify exclusion merging (#341) - simplify merging: initial assumption no longer applies - no need for fancy merging attributes --- .../spinnaker/swabbie/WorkConfigurator.kt | 35 ++++--------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/swabbie-core/src/main/kotlin/com/netflix/spinnaker/swabbie/WorkConfigurator.kt b/swabbie-core/src/main/kotlin/com/netflix/spinnaker/swabbie/WorkConfigurator.kt index a1176f6c..7fb77507 100644 --- a/swabbie-core/src/main/kotlin/com/netflix/spinnaker/swabbie/WorkConfigurator.kt +++ b/swabbie-core/src/main/kotlin/com/netflix/spinnaker/swabbie/WorkConfigurator.kt @@ -119,41 +119,18 @@ open class WorkConfigurator( } private fun mergeExclusions(global: Set?, local: Set?): Set { - if ((global == null || global.isEmpty()) && (local == null || local.isEmpty())) { - return emptySet() - } else if ((global == null || global.isEmpty()) && local != null) { - return local - } else if (global != null && (local == null || local.isEmpty())) { - return global - } - - // local is additive to global. local can override global - val result = local!!.toMutableSet() - merge(global!!, result) - + val result = local?.toMutableSet() ?: mutableSetOf() // include runtime exclusions exclusionsSuppliers.ifPresent { exclusionsProviders -> exclusionsProviders.forEach { exclusionProvider -> - merge(exclusionProvider.get().toSet(), result) + result.addAll(exclusionProvider.get().toSet()) } } - return result.toSet() - } - - private fun merge(from: Set, to: MutableSet) { - from.forEach { f -> - var found = false - to.forEach { t -> - if (t.type == f.type) { - (t.attributes).addAll(f.attributes) - found = true - } - } - - if (!found) { - to.add(f) - } + if (global != null) { + result.addAll(global) } + + return result.toSet() } }