1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package eteg.sinon.executor;
24
25 /***
26 * Class that represents catalog states.
27 *
28 * @author <a href="mailto:thiagohp at users.sourceforge.net">Thiago H. de Paula Figueiredo</a>
29 * @author Last modified by $Author: thiagohp $
30 * @version $Revision: 1.2 $
31 */
32 public class CatalogState {
33
34 /***
35 * Constant that defines the state of a catalog before its processing
36 * begins.
37 */
38 final private static int BEFORE_PROCESSING_ID = 0;
39
40 /***
41 * Constant that defines the state of a catalog after it is processed.
42 */
43 final private static int AFTER_PROCESSING_ID = 1;
44
45 /***
46 * Constant that defines the state of a catalog before its processing
47 * begins.
48 */
49 final public static CatalogState BEFORE_PROCESSING;
50
51 /***
52 * Constant that defines the state of a catalog after it is processed.
53 */
54 final public static CatalogState AFTER_PROCESSING;
55
56 static {
57
58 BEFORE_PROCESSING = new CatalogState(BEFORE_PROCESSING_ID);
59 AFTER_PROCESSING = new CatalogState(AFTER_PROCESSING_ID);
60
61 }
62
63 /***
64 * State identifier.
65 */
66 private int stateId;
67
68 /***
69 * Single constructor of this class. The only valid values are
70 * {@link #BEFORE_PROCESSING_ID} and {@link #AFTER_PROCESSING_ID}.
71 * @param stateId an <code>int</code>.
72 * @throws java.lang.IllegalArgumentException if <code>stateId</code>
73 * is not valid.
74 */
75 private CatalogState(int stateId) {
76
77 if (stateId < BEFORE_PROCESSING_ID || stateId > AFTER_PROCESSING_ID) {
78
79 throw new IllegalArgumentException(
80 "Invalid stateId parameter value : " + stateId);
81
82 }
83
84 this.stateId = stateId;
85
86 }
87
88 /***
89 * Retorns <code>true</code> if this state is
90 * {@link #BEFORE_PROCESSING}.
91 *
92 * @return <code>true</code> if this state is
93 * {@link #BEFORE_PROCESSING}, <code>false</code> otherwise.
94 */
95 public boolean isBeforeProcessing() {
96 return (stateId == BEFORE_PROCESSING_ID);
97 }
98
99 /***
100 * Retorna <code>true</code> if this state is
101 * {@link #AFTER_PROCESSING}, <code>false</code> otherwise.
102 *
103 * @return <code>true</code> if this state is
104 * {@link #AFTER_PROCESSING}, <code>false</code> otherwise.
105 */
106 public boolean isAfterProcessing() {
107 return (stateId == AFTER_PROCESSING_ID);
108 }
109
110 /***
111 * Returns a <code>String</code> containing the name of this state.
112 *
113 * @return a <code>String</code>.
114 */
115 public String getName() {
116
117 if (stateId == BEFORE_PROCESSING_ID) {
118 return "before processing";
119 }
120 else if (stateId == AFTER_PROCESSING_ID) {
121 return "after processing";
122 }
123 else {
124 return "invalid state";
125 }
126
127 }
128
129 public boolean equals(final Object other) {
130
131 if (other instanceof PageState == false) {
132 return false;
133 }
134
135 CatalogState castOther = (CatalogState) other;
136 return this.stateId == castOther.stateId;
137
138 }
139
140 }