From 2d6bbe0b8bff09d105b77161c1d26a00ce43bf0c Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Thu, 11 Apr 2024 15:09:55 +0200 Subject: Unify on List.of --- .../config/application/api/DeploymentSpec.java | 2 +- .../config/application/api/Notifications.java | 29 +++++++++++----------- .../config/application/api/DeploymentSpecTest.java | 3 +-- .../api/DeploymentSpecWithoutInstanceTest.java | 3 +-- 4 files changed, 17 insertions(+), 20 deletions(-) (limited to 'config-model-api') diff --git a/config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java b/config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java index 16cd7bf7e88..4308e0c2a0e 100644 --- a/config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java +++ b/config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java @@ -386,7 +386,7 @@ public class DeploymentSpec { public abstract boolean concerns(Environment environment, Optional region); /** Returns the zones deployed to in this step. */ - public List zones() { return Collections.emptyList(); } + public List zones() { return List.of(); } /** The delay introduced by this step (beyond the time it takes to execute the step). */ public Duration delay() { return Duration.ZERO; } diff --git a/config-model-api/src/main/java/com/yahoo/config/application/api/Notifications.java b/config-model-api/src/main/java/com/yahoo/config/application/api/Notifications.java index 370dfbff2b8..ac8900ab67b 100644 --- a/config-model-api/src/main/java/com/yahoo/config/application/api/Notifications.java +++ b/config-model-api/src/main/java/com/yahoo/config/application/api/Notifications.java @@ -7,10 +7,9 @@ import com.google.common.collect.ImmutableSet; import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; -import static java.util.Collections.emptyList; - /** * Configuration of notifications for deployment jobs. * @@ -59,7 +58,7 @@ public class Notifications { /** Returns all email addresses to notify for the given condition. */ public Set emailAddressesFor(When when) { ImmutableSet.Builder addresses = ImmutableSet.builder(); - addresses.addAll(emailAddresses.getOrDefault(when, emptyList())); + addresses.addAll(emailAddresses.getOrDefault(when, List.of())); for (When include : when.includes) addresses.addAll(emailAddressesFor(include)); return addresses.build(); @@ -68,7 +67,7 @@ public class Notifications { /** Returns all roles for which email notification is to be sent for the given condition. */ public Set emailRolesFor(When when) { ImmutableSet.Builder roles = ImmutableSet.builder(); - roles.addAll(emailRoles.getOrDefault(when, emptyList())); + roles.addAll(emailRoles.getOrDefault(when, List.of())); for (When include : when.includes) roles.addAll(emailRolesFor(include)); return roles.build(); @@ -81,17 +80,17 @@ public class Notifications { author; public static String toValue(Role role) { - switch (role) { - case author: return "author"; - default: throw new IllegalArgumentException("Unexpected constant '" + role.name() + "'."); + if (Objects.requireNonNull(role) == Role.author) { + return "author"; } + throw new IllegalArgumentException("Unexpected constant '" + role.name() + "'."); } public static Role fromValue(String value) { - switch (value) { - case "author": return author; - default: throw new IllegalArgumentException("Unknown value '" + value + "'."); + if (value.equals("author")) { + return author; } + throw new IllegalArgumentException("Unknown value '" + value + "'."); } } @@ -112,11 +111,11 @@ public class Notifications { } public static String toValue(When when) { - switch (when) { - case failing: return "failing"; - case failingCommit: return "failing-commit"; - default: throw new IllegalArgumentException("Unexpected constant '" + when.name() + "'."); - } + return switch (when) { + case failing -> "failing"; + case failingCommit -> "failing-commit"; + default -> throw new IllegalArgumentException("Unexpected constant '" + when.name() + "'."); + }; } public static When fromValue(String value) { diff --git a/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecTest.java b/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecTest.java index 99c9dad02de..05807ae6cc1 100644 --- a/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecTest.java +++ b/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecTest.java @@ -23,7 +23,6 @@ import java.time.Clock; import java.time.Duration; import java.time.Instant; import java.time.ZoneId; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -1152,7 +1151,7 @@ public class DeploymentSpecTest { """); - assertEquals(Collections.emptyList(), spec.requireInstance("default").endpoints()); + assertEquals(List.of(), spec.requireInstance("default").endpoints()); assertEquals(ZoneEndpoint.defaultEndpoint, spec.zoneEndpoint(InstanceName.defaultName(), defaultId(), ClusterSpec.Id.from("cluster"))); diff --git a/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecWithoutInstanceTest.java b/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecWithoutInstanceTest.java index e102e3afaa7..e25069fdc3a 100644 --- a/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecWithoutInstanceTest.java +++ b/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecWithoutInstanceTest.java @@ -16,7 +16,6 @@ import java.io.StringReader; import java.time.Duration; import java.time.Instant; import java.time.ZoneId; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; @@ -599,7 +598,7 @@ public class DeploymentSpecWithoutInstanceTest { @Test public void emptyEndpoints() { var spec = DeploymentSpec.fromXml(""); - assertEquals(Collections.emptyList(), spec.requireInstance("default").endpoints()); + assertEquals(List.of(), spec.requireInstance("default").endpoints()); } @Test -- cgit v1.2.3