Create an object for each state

Each permitted state for your class is represented by an instance of the State> helper class. Here you'll use the CodetableState> helper class:

Figure 1. Creating an object for each permitted state
/**
   * 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:

  1. the map to which the object will be added (states);
  2. the value used to identify the state object in the map (typically, the code table entry value);
  3. whether the entity may be modified when in this state; and
  4. whether the entity may be removed when in this state.
Note: There is no automatic processing surrounding the use of the "entity may be modified/removed" values.

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.