From 673b1a60aa173cb3e0dcfce506a473618a852c17 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Tue, 3 Dec 2024 19:27:09 +0000 Subject: [PATCH] Turn Server into a sealed interface Sealed interfaces are useful in switch exprs to enumerate possible values so that it becomes a compile error to introduce a new server type without implementing an appropriate arm for the switch block. --- .../net/rptools/clientserver/simple/server/AbstractServer.java | 2 +- .../java/net/rptools/clientserver/simple/server/NilServer.java | 2 +- .../java/net/rptools/clientserver/simple/server/Server.java | 2 +- .../net/rptools/clientserver/simple/server/SocketServer.java | 2 +- .../net/rptools/clientserver/simple/server/WebRTCServer.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clientserver/src/main/java/net/rptools/clientserver/simple/server/AbstractServer.java b/clientserver/src/main/java/net/rptools/clientserver/simple/server/AbstractServer.java index 7186d6c0ef..2f45ec8389 100644 --- a/clientserver/src/main/java/net/rptools/clientserver/simple/server/AbstractServer.java +++ b/clientserver/src/main/java/net/rptools/clientserver/simple/server/AbstractServer.java @@ -20,7 +20,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -public abstract class AbstractServer implements Server { +public abstract class AbstractServer { private static final Logger log = LogManager.getLogger(AbstractServer.class); diff --git a/clientserver/src/main/java/net/rptools/clientserver/simple/server/NilServer.java b/clientserver/src/main/java/net/rptools/clientserver/simple/server/NilServer.java index ad9b76bec3..9aacaaa8b0 100644 --- a/clientserver/src/main/java/net/rptools/clientserver/simple/server/NilServer.java +++ b/clientserver/src/main/java/net/rptools/clientserver/simple/server/NilServer.java @@ -15,7 +15,7 @@ package net.rptools.clientserver.simple.server; /** A server implementation that never receives connections */ -public class NilServer extends AbstractServer { +public final class NilServer extends AbstractServer implements Server { @Override public void start() {} diff --git a/clientserver/src/main/java/net/rptools/clientserver/simple/server/Server.java b/clientserver/src/main/java/net/rptools/clientserver/simple/server/Server.java index 00b379a7d9..9f92b9926e 100644 --- a/clientserver/src/main/java/net/rptools/clientserver/simple/server/Server.java +++ b/clientserver/src/main/java/net/rptools/clientserver/simple/server/Server.java @@ -16,7 +16,7 @@ import java.io.IOException; -public interface Server extends AutoCloseable { +public sealed interface Server extends AutoCloseable permits NilServer, SocketServer, WebRTCServer { void start() throws IOException; void close(); diff --git a/clientserver/src/main/java/net/rptools/clientserver/simple/server/SocketServer.java b/clientserver/src/main/java/net/rptools/clientserver/simple/server/SocketServer.java index 2b4c0ac9c5..c7341d169f 100644 --- a/clientserver/src/main/java/net/rptools/clientserver/simple/server/SocketServer.java +++ b/clientserver/src/main/java/net/rptools/clientserver/simple/server/SocketServer.java @@ -25,7 +25,7 @@ /** * @author drice */ -public class SocketServer extends AbstractServer { +public final class SocketServer extends AbstractServer implements Server { private static final Logger log = LogManager.getLogger(SocketServer.class); private final int port; diff --git a/clientserver/src/main/java/net/rptools/clientserver/simple/server/WebRTCServer.java b/clientserver/src/main/java/net/rptools/clientserver/simple/server/WebRTCServer.java index 32ad0b8c7b..880424ef2a 100644 --- a/clientserver/src/main/java/net/rptools/clientserver/simple/server/WebRTCServer.java +++ b/clientserver/src/main/java/net/rptools/clientserver/simple/server/WebRTCServer.java @@ -29,7 +29,7 @@ import org.java_websocket.client.WebSocketClient; import org.java_websocket.handshake.ServerHandshake; -public class WebRTCServer extends AbstractServer { +public final class WebRTCServer extends AbstractServer implements Server { private static final Logger log = LogManager.getLogger(WebRTCServer.class); public interface Listener {