Browse Source

Enumset helper created

combat-2
MagicBot 9 months ago
parent
commit
5e1ebeb4df
  1. 31
      src/engine/gameManager/DbManager.java

31
src/engine/gameManager/DbManager.java

@ -22,6 +22,7 @@ import java.sql.Connection; @@ -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 { @@ -266,6 +267,35 @@ public enum DbManager {
}
public static <E extends java.lang.Enum<E>> EnumSet<E> parseEnumSet(String mysqlSet, Class<E> enumClass) {
// Create empty EnumSet of the given class
EnumSet<E> 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 { @@ -324,4 +354,5 @@ public enum DbManager {
Logger.info("Database configured with " + connectionCount + " connections");
}
}

Loading…
Cancel
Save