From 22dc2c7e54ae012ba38ba6a0ef4ff65575365b93 Mon Sep 17 00:00:00 2001 From: Lars Simon Winzer Date: Tue, 7 Apr 2026 13:27:12 +0200 Subject: [PATCH 1/4] Add: Methods to remove user by UserId, SessionId and Username from SessionRegistry --- .../server/domain/user/UserRegistry.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/domain/user/UserRegistry.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/domain/user/UserRegistry.java index bc0cd36..436c965 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/domain/user/UserRegistry.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/domain/user/UserRegistry.java @@ -31,6 +31,43 @@ public class UserRegistry { return Optional.of(user); } + public synchronized boolean removeByUserId(UserId userId) { + User user = byId.get(userId); + if (user == null) { + return false; + } + + byName.remove(user.getName()); + user.getSessionId().ifPresent(bySessionId::remove); + return true; + } + + public synchronized boolean removeBySessionId(SessionId sessionId) { + User user = bySessionId.get(sessionId); + if (user == null) { + return false; + } + + remove(user); + return true; + } + + public synchronized boolean removeByUsername(String username) { + User user = byName.get(username); + if (user == null) { + return false; + } + + remove(user); + return true; + } + + private synchronized void remove(User user) { + byId.remove(user.getId()); + byName.remove(user.getName()); + user.getSessionId().ifPresent(bySessionId::remove); + } + /** * Removes the user with the given ID, but only if they are still disconnected. This prevents * removing a user who has reconnected between the cleanup job's check and its removal call. -- 2.52.0 From 36f07880e521e88d10a42e6c30004f2aed22f8ad Mon Sep 17 00:00:00 2001 From: Lars Simon Winzer Date: Tue, 7 Apr 2026 13:28:12 +0200 Subject: [PATCH 2/4] Refactor: Use internal remove method --- .../dmi/dbis/cs108/casono/server/domain/user/UserRegistry.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/domain/user/UserRegistry.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/domain/user/UserRegistry.java index 436c965..b79bf69 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/domain/user/UserRegistry.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/domain/user/UserRegistry.java @@ -84,8 +84,7 @@ public class UserRegistry { return false; } - byId.remove(user.getId()); - byName.remove(user.getName()); + remove(user); return true; } -- 2.52.0 From ee694b8168dcdd5f58c76b55ae471a203fd84709 Mon Sep 17 00:00:00 2001 From: Lars Simon Winzer Date: Tue, 7 Apr 2026 13:30:09 +0200 Subject: [PATCH 3/4] Docs: Write JavaDoc for newly added methods --- .../server/domain/user/UserRegistry.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/domain/user/UserRegistry.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/domain/user/UserRegistry.java index b79bf69..2264805 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/domain/user/UserRegistry.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/domain/user/UserRegistry.java @@ -31,6 +31,12 @@ public class UserRegistry { return Optional.of(user); } + /** + * Removes a user from the registry by user ID. + * + * @param userId the ID of the user to remove + * @return true if a user was removed, false if no user with that ID exists + */ public synchronized boolean removeByUserId(UserId userId) { User user = byId.get(userId); if (user == null) { @@ -42,6 +48,12 @@ public class UserRegistry { return true; } + /** + * Removes a user from the registry by session ID. + * + * @param sessionId the session ID associated with the user to remove + * @return true if a user was removed, false if no user with that session exists + */ public synchronized boolean removeBySessionId(SessionId sessionId) { User user = bySessionId.get(sessionId); if (user == null) { @@ -52,6 +64,12 @@ public class UserRegistry { return true; } + /** + * Removes a user from the registry by username. + * + * @param username the username associated with the user to remove + * @return true if a user was removed, false if no user with that session exists + */ public synchronized boolean removeByUsername(String username) { User user = byName.get(username); if (user == null) { @@ -62,6 +80,11 @@ public class UserRegistry { return true; } + /** + * Removes a user from the internals of the registry. + * + * @param user the user to remove + */ private synchronized void remove(User user) { byId.remove(user.getId()); byName.remove(user.getName()); -- 2.52.0 From 822dfe778d2d2ec2778fbc3618451186cdd5f61a Mon Sep 17 00:00:00 2001 From: Lars Simon Winzer Date: Tue, 7 Apr 2026 13:31:26 +0200 Subject: [PATCH 4/4] Style: Apply Spotless --- .../dmi/dbis/cs108/casono/server/domain/user/UserRegistry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/domain/user/UserRegistry.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/domain/user/UserRegistry.java index 2264805..b3cd551 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/domain/user/UserRegistry.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/domain/user/UserRegistry.java @@ -82,7 +82,7 @@ public class UserRegistry { /** * Removes a user from the internals of the registry. - * + * * @param user the user to remove */ private synchronized void remove(User user) { -- 2.52.0