View Javadoc
1   package nl.tno.imb.mc;
2   
3   import java.util.HashMap;
4   import java.util.Map;
5   
6   /**
7    * The possible states of a model.
8    */
9   public enum ModelState
10  {
11  
12      /** Ready. */
13      READY(0),
14      /** Calculating. */
15      CALCULATING(1),
16      /** Busy. */
17      BUSY(2),
18      /** Model is available for use. */
19      IDLE(3),
20      /** Claim model for use in this session. */
21      LOCK(4),
22      /** Free model to be used in other session. */
23      UNLOCK(5),
24      /** Force termination of model. */
25      // TODO TERMINATE(6),
26      /** Model is no longer available. */
27      REMOVED(-1);
28  
29      /** Map to translate numeric value to enum. */
30      protected static Map<Integer, ModelState> commandMap = new HashMap<>();
31  
32      static
33      {
34          for (ModelState modelState : values())
35          {
36              commandMap.put(modelState.getValue(), modelState);
37          }
38      }
39  
40      /**
41       * Construct a ModelState.
42       * @param value int; the result of the getValue method
43       */
44      private ModelState(final int value)
45      {
46          this.value = value;
47      }
48  
49      /**
50       * Retrieve the integer value that represents this ModelState for transmission over IMB.
51       * @return int; the value that represents this ModelState in transmission over IMB
52       */
53      public int getValue()
54      {
55          return this.value;
56      }
57  
58      /** The value that represents this ModalState when being transmitted over IMB. */
59      private final int value;
60  
61      /**
62       * Lookup the ModelState that corresponds to the value.
63       * @param value int; the value to look up
64       * @return ModelState; the ModelState that corresponds to the value, or null if no ModelState with the specified value is
65       *         defined
66       */
67      protected static ModelState byValue(final int value)
68      {
69          return commandMap.get(value);
70      }
71  
72  }