diff options
author | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2019-03-27 11:23:50 +0100 |
---|---|---|
committer | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2019-03-28 10:24:34 +0100 |
commit | 7e47192b9e5ea803a31726db17d65da5c6754c79 (patch) | |
tree | 85f74e14d82ded634cc18d88546606280d5f1983 /controller-server | |
parent | 65928abdf774c5f2fba0d8b83d2c073353379595 (diff) |
Extract common pattern in RoleMembership.BuilderWithRole
Diffstat (limited to 'controller-server')
3 files changed, 11 insertions, 14 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/role/PathGroup.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/role/PathGroup.java index 756703ca085..837e4df7166 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/role/PathGroup.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/role/PathGroup.java @@ -7,7 +7,6 @@ import java.util.EnumSet; import java.util.List; import java.util.Optional; import java.util.Set; -import java.util.regex.Pattern; /** * This declares and groups all known REST API paths in the controller. diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/role/RoleMembership.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/role/RoleMembership.java index 97d7947fb4f..c21eef2c29e 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/role/RoleMembership.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/role/RoleMembership.java @@ -80,35 +80,33 @@ public class RoleMembership { @Override public BuilderWithRole add(Role role) { - if (current != null) { - roles.putIfAbsent(current, new HashSet<>()); - roles.get(current).add(Context.unlimitedIn(system)); - } + consumeCurrent(Context.unlimitedIn(system)); current = role; return this; } public Builder limitedTo(TenantName tenant) { - roles.putIfAbsent(current, new HashSet<>()); - roles.get(current).add(Context.limitedTo(tenant, system)); - current = null; + consumeCurrent(Context.limitedTo(tenant, system)); return this; } public Builder limitedTo(TenantName tenant, ApplicationName application) { - roles.putIfAbsent(current, new HashSet<>()); - roles.get(current).add(Context.limitedTo(tenant, application, system)); - current = null; + consumeCurrent(Context.limitedTo(tenant, application, system)); return this; } @Override public RoleMembership build() { + consumeCurrent(Context.unlimitedIn(system)); + return new RoleMembership(roles); + } + + private void consumeCurrent(Context context) { if (current != null) { roles.putIfAbsent(current, new HashSet<>()); - roles.get(current).add(Context.unlimitedIn(system)); + roles.get(current).add(context); } - return new RoleMembership(roles); + current = null; } } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/role/PathGroupTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/role/PathGroupTest.java index 7ec97434966..4cf46933dcb 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/role/PathGroupTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/role/PathGroupTest.java @@ -42,7 +42,7 @@ public class PathGroupTest { int end = Math.min(parts1.length, parts2.length); // If one path has more parts than the other ... // and the other doesn't end with a wildcard matcher ... - // and the longest one isn't just one part longer, which is a wildcard ... + // and the longest one isn't just one wildcard longer ... if (end < parts1.length && (end == 0 || ! parts2[end - 1].equals("{*}")) && ! parts1[end].equals("{*}")) continue; if (end < parts2.length && (end == 0 || ! parts1[end - 1].equals("{*}")) && ! parts2[end].equals("{*}")) continue; |