Java enumerations
- Last Updated: March 24, 2022
- 3 minute read
- Corticon
- Version 6.3
- Documentation
Enumerations are custom Java objects you define and use inside of your Business Objects. They are used to define a preset “value set” for a type.
For simplicity, let's assume that a Java Enumeration has a Name and multiple Labels (or Types). Here is a common example of a Java Enumeration:
public enum Day
{
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY;
}
The Day enumeration has 5 different
Labels {Day.MONDAY, Day.TUESDAY, Day.WEDNESDAY, Day.THURSDAY, and Day.FRIDAY}. These labels are all considered “of type
Day”. So if a method signature accepts a
Day type, it will accept all 5 of these defined
labels.
For example:
public class Person
{
private Day iPayDay = null;
public Day getPayDay() {return iPayDay;}
public void setPayDay(Day aValue) {iPayDay = aValue;}
}
Here is an example of a call to the setPayDay(Day) method:
lPerson.setPayDay(Day.MONDAY);
Because Day.MONDAY is of type Day, the setting of the value is complete.
Business rule execution can also set your business object's Enumeration values. Corticon performs this by matching Labels in your business object's enumerations with the Custom Data Type (CDT) labels defined in your Vocabulary.
From our example:
Java Enumeration Label Names for enum Day:
MONDAY
TUESDAY
WEDNESDAY
THURSDAY
FRIDAY
Now, the Vocabulary must have these same Labels defined in the CDT that is assigned to the attribute.
The key to metadata matching is the Labels – as long as your BO enumeration labels match the Vocabulary's CDT Labels, it should work fine. So what happens if the Labels do NOT match?
Extra validation has been added to the Vocabulary to help identify this problem. The example below shows a Label mismatch:
Notice the Vocabulary attribute is “flagged” with the small orange warning icon (shown in the upper left of the figure above). The associated warning message states:
Java Object Get Method getPayDay return
type is an Enumeration and has a mismatch in values between the Enumeration Labels
[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY] and Custom Datatype
Labels [MONDAYS, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY].