2 Replies Latest reply on Mar 21, 2013 11:24 PM by John Sylora

    Enum data types in Forge

    John Sylora Newbie

      Hello Forge users,

       

      1) I'm trying to set up enum types using the Forge command line tool. The only way I could do it was with the Forge command:

       

      $ java new-enum-type --package ~.model 'public enum PartType {}'

       

      Then to add the list of enum constants I used:

       

      PartType.java $ java new-enum-const 'Biopsy1'

       

      PartType.java $ java new-enum-const 'Biopsy2'

       

      Is this the best way to do this? Thank you.

       

      2) After the enum type is set up what is the best way to include it in another class. For example, I have a new class called SpecimenPart. The way I added the enum class PartType was as follows:

       

      SpecimenPart.java $ java new-field 'private PartType type;'

       

      Is this the best way to do this? Thanks again.

        • 1. Re: Enum data types in Forge
          George Gastaldi Master

          Hello John !

           

          If you're using Forge 1.2.1.Final onwards, you may be able to create enums like this:

           

          $ java new-enum-type --named PartType --package ~.model
          

           

          As for creating the enum constants, you're doing the correct way.

           

          To include your enum in another class, you may use the the code you're using or if you have Persistence enabled in you project, you may simply use:

           

          $ field custom --named partType --type ~.model.PartType.java
          

           

          As this will also create getters and setters for your field.

           

          Best Regards,

           

          George Gastaldi

          • 2. Re: Enum data types in Forge
            John Sylora Newbie

            Thank you George.. the answer was perfect. I would like to extend this discussion to the general use of enums vs lists.

             

            1) In my example above, if my PartType enum class contains several items which I want the user to be able to add or delete from, is my use of the enum type incorrect? Will it be difficult/impossible for the user to change the items in the enum class? Should the use of enums be limited to lists of items which will definitely not change and which the user cannot change? For example the months of the year, days of week etc..

             

            2) In the case when the list of items may change, is it better to use a list? If so what would be an ideal way of implementing this?

             

            Thank you..