From 5e1ebeb4dfac83c879beb88fc0e50fe34ce4e939 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 11 Feb 2024 07:55:38 -0500 Subject: [PATCH] Enumset helper created --- src/engine/gameManager/DbManager.java | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/engine/gameManager/DbManager.java b/src/engine/gameManager/DbManager.java index cbd52a3d..6dc9c392 100644 --- a/src/engine/gameManager/DbManager.java +++ b/src/engine/gameManager/DbManager.java @@ -22,6 +22,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.EnumMap; +import java.util.EnumSet; import java.util.concurrent.ConcurrentHashMap; public enum DbManager { @@ -266,6 +267,35 @@ public enum DbManager { } + public static > EnumSet parseEnumSet(String mysqlSet, Class enumClass) { + + // Create empty EnumSet of the given class + + EnumSet enumSet = EnumSet.noneOf(enumClass); + + // Remove the leading and trailing brackets from the MySQL set + + mysqlSet = mysqlSet.substring(1, mysqlSet.length() - 1); + + // Split set string and trim each element + + String[] elements = mysqlSet.split(","); + + for (String element : elements) { + + element = element.trim(); + + // Parse the element into an enum and add to set + + E enumConstant = java.lang.Enum.valueOf(enumClass, element); + enumSet.add(enumConstant); + } + + // Return the EnumSet + + return enumSet; + } + public static void printCacheCount(PlayerCharacter pc) { ChatManager.chatSystemInfo(pc, "Cache Lists"); @@ -324,4 +354,5 @@ public enum DbManager { Logger.info("Database configured with " + connectionCount + " connections"); } + }