01: package com.technoetic.xplanner.domain;
02:
03: //TODO refactor to use Enum
04: public class IterationStatus {
05: protected final int code;
06:
07: public static final IterationStatus ACTIVE = new IterationStatusPersistent(
08: 0);
09: public static final IterationStatus INACTIVE = new IterationStatusPersistent(
10: 1);
11:
12: public static final String ACTIVE_KEY = "active";
13: public static final String INACTIVE_KEY = "inactive";
14:
15: public static final String[] KEYS = { ACTIVE_KEY, INACTIVE_KEY };
16:
17: protected IterationStatus(int code) {
18: this .code = code;
19: }
20:
21: public String getKey() {
22: return KEYS[code];
23: }
24:
25: public int toInt() {
26: return code;
27: }
28:
29: public static IterationStatus fromKey(String key) {
30: if (key == null) {
31: return null;
32: } else if (ACTIVE_KEY.equals(key)) {
33: return ACTIVE;
34: } else if (INACTIVE_KEY.equals(key)) {
35: return INACTIVE;
36: } else {
37: throw new RuntimeException("Unknown iteration status key");
38: }
39:
40: }
41:
42: public String toString() {
43: return getKey();
44: }
45:
46: public boolean equals(Object obj) {
47: if (obj == this )
48: return true;
49: if (!(obj instanceof IterationStatus))
50: return false;
51: return ((IterationStatus) obj).toInt() == toInt();
52: }
53: }
|