0

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?

1
  • 3
    Put the values you want to be "visible" in an EnumSet. Commented Nov 7, 2017 at 9:16

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

EnumMap<EnumType, Boolean> to be precise. Now need to populate tableview with it.
1

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.