I have a project where I use enum class with 128 values in it and I want to allow end user to select only few of values for his usage (say 20 out of 128) For that I created javafx tableview with checkbotablecell which works nicely but then I would need to make boolean field in enum to define visibility of each value but all enum fields are final and I will not be able to change it dynamically. So, the question is how to dynamically define visibility of each enum value?
2 Answers
You can create a Map of Enum to Boolean inside Enum class.
Eg : static final EnumMap<EnumType , Boolean> visibilityMap.
And add getter and setter methods to access visibility.
1 Comment
You want an EnumSet to be stored.
The enum class of yours defines 128 singleton objects, one cannot have several objects "being" the same enum object. The solution would be to have a class containing the enum object. Or having an EnumSet of several enum constants.
EnumSet is a Set implementation havily optimized for enums, and providing building methods. In the constructor on passes the actual enum class itself so with type erasure the class can still function.
EnumSet<Weekday> weekend = EnumSet.of(Weekday.SATURDAY, Weekday.SUNDAY);