Each permitted state for your class is represented by an instance of the State> helper class. Here you'll use the CodetableState> helper class:
/**
* Actively conducting business with the agency.
*/
private final State<MYLIFECYCLEENTITYSTATEEntry> OPEN =
new CodetableState<MYLIFECYCLEENTITYSTATEEntry>(
states, MYLIFECYCLEENTITYSTATEEntry.OPEN, true, true) {
};
/**
* Business has been suspended pending investigation.
*/
private final State<MYLIFECYCLEENTITYSTATEEntry> SUSPENDED =
new CodetableState<MYLIFECYCLEENTITYSTATEEntry>(
states, MYLIFECYCLEENTITYSTATEEntry.SUSPENDED, true, false) {
};
/**
* No longer conducting business with the agency.
*/
private final State<MYLIFECYCLEENTITYSTATEEntry> CLOSED =
new CodetableState<MYLIFECYCLEENTITYSTATEEntry>(
states, MYLIFECYCLEENTITYSTATEEntry.CLOSED, false, false) {
};
Each State object is an anonymous class, constructed with:
If you require to prevent modifications or removals when your entity is in a particular state, you must override the modify and/or remove methods as appropriate, and in them put validation logic which may make use of calls to State.isModifyAllowed or State.isRemoveAllowed as appropriate.
See Override the modify method (if required) below.