diff --git a/src/engine/mbEnums.java b/src/engine/mbEnums.java index b77bf902..11679641 100644 --- a/src/engine/mbEnums.java +++ b/src/engine/mbEnums.java @@ -55,6 +55,46 @@ public class mbEnums { return enumSet; } + public static > EnumSet fromString(String dbString, Class enumClass) { + + // Build enumset from ; delimited string (from db) + + EnumSet enumSet = EnumSet.noneOf(enumClass); + + // Early exit if empty set + + if (dbString.isEmpty()) + return enumSet; + + String[] enumArray = dbString.split(";"); + + for (String enumeration : enumArray) { + E parsedEnum = Enum.valueOf(enumClass, enumeration); + enumSet.add(parsedEnum); + } + + return enumSet; + } + + + public static > String asString(EnumSet enumSet) { + + if (enumSet == null || enumSet.isEmpty()) + return ""; + + StringBuilder result = new StringBuilder(); + + for (E element : enumSet) + result.append(element.name()).append(";"); + + // Remove the trailing comma + + if (result.length() > 1) + result.setLength(result.length() - 1); + + return result.toString(); + } + public enum PetitionType { NONE, GENERAL,