diff options
author | Martin Polden <mpolden@mpolden.no> | 2022-12-16 11:11:54 +0100 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2022-12-16 11:14:38 +0100 |
commit | 9f84abbf402b02cb1d12622d50e30e2fdd6d21b5 (patch) | |
tree | d7f6242b7b6af4230c13e2e2d1621821a51499f4 | |
parent | 1fec0e463ccf2722e745e3e166cbde09fe48c6d4 (diff) |
Use switch expression
3 files changed, 20 insertions, 27 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/LockedTenant.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/LockedTenant.java index f8135e27d74..bdf3d438bd7 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/LockedTenant.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/LockedTenant.java @@ -51,12 +51,11 @@ public abstract class LockedTenant { } static LockedTenant of(Tenant tenant, Mutex lock) { - switch (tenant.type()) { - case athenz: return new Athenz((AthenzTenant) tenant); - case cloud: return new Cloud((CloudTenant) tenant); - case deleted: return new Deleted((DeletedTenant) tenant); - default: throw new IllegalArgumentException("Unexpected tenant type '" + tenant.getClass().getName() + "'."); - } + return switch (tenant.type()) { + case athenz -> new Athenz((AthenzTenant) tenant); + case cloud -> new Cloud((CloudTenant) tenant); + case deleted -> new Deleted((DeletedTenant) tenant); + }; } /** Returns a read-only copy of this */ diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/LogSerializer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/LogSerializer.java index 6567b0076e7..9f648675cd0 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/LogSerializer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/LogSerializer.java @@ -18,7 +18,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; /** * Serialisation of {@link LogEntry} objects. Not all fields are stored! @@ -98,25 +97,24 @@ class LogSerializer { } static String valueOf(Type type) { - switch (type) { - case debug: return "debug"; - case info: return "info"; - case warning: return "warning"; - case error: return "error"; - case html: return "html"; - default: throw new AssertionError("Unexpected log entry type '" + type + "'!"); - } + return switch (type) { + case debug -> "debug"; + case info -> "info"; + case warning -> "warning"; + case error -> "error"; + case html -> "html"; + }; } static Type typeOf(String type) { - switch (type) { - case "debug": return Type.debug; - case "info": return Type.info; - case "warning": return Type.warning; - case "error": return Type.error; - case "html": return Type.html; - default: throw new IllegalArgumentException("Unknown log entry type '" + type + "'!"); - } + return switch (type) { + case "debug" -> Type.debug; + case "info" -> Type.info; + case "warning" -> Type.warning; + case "error" -> Type.error; + case "html" -> Type.html; + default -> throw new IllegalArgumentException("Unknown log entry type '" + type + "'!"); + }; } } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/NotificationsSerializer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/NotificationsSerializer.java index beda8942fc2..3d28f35fc26 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/NotificationsSerializer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/NotificationsSerializer.java @@ -4,7 +4,6 @@ package com.yahoo.vespa.hosted.controller.persistence; import com.yahoo.config.provision.ApplicationName; import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.InstanceName; -import com.yahoo.config.provision.SystemName; import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.zone.ZoneId; import com.yahoo.slime.Cursor; @@ -16,7 +15,6 @@ import com.yahoo.vespa.hosted.controller.notification.Notification; import com.yahoo.vespa.hosted.controller.notification.NotificationSource; import java.util.List; -import java.util.stream.Collectors; /** * (de)serializes notifications for a tenant @@ -105,7 +103,6 @@ public class NotificationsSerializer { case deployment -> "deployment"; case feedBlock -> "feedBlock"; case reindex -> "reindex"; - default -> throw new IllegalArgumentException("No serialization defined for notification type " + type); }; } @@ -126,7 +123,6 @@ public class NotificationsSerializer { case info -> "info"; case warning -> "warning"; case error -> "error"; - default -> throw new IllegalArgumentException("No serialization defined for notification level " + level); }; } |