Populating enumeration values from text file read

5
I'm reading in text files in Java and populating metaobject attributes with them using ICreateBatch and IChangeBatch. If I read in a string from the file what's the best way to populate an enumeration with it? So far I've had to do this, which is not ideal because I have to change the Java code anytime I change the enumeration's possible values. if (valueReadFromFile.equals("someValue")) { branchTariffBatch.setMemberValue (SomeMetaObject.MemberNames.someEnumeration.toString(), SomeEnumeration.someValue.toString()); } etc.
asked
2 answers
5

You can use:

SomeMetaObject.MemberNames.someEnumeration.valueOf(someValue)

This will return the corresponding enum value based on the string input. This will only work if someValue contains values which are exactly the same as your enumeration values.

answered
1

You can only insert new entries into an enumeration from the Modeler. From there you can use the java code Johan suggested to assign the matching enum value to the object.

answered