01: /*
02: * Copyright 2005 JBoss Inc
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.drools.examples.manners;
17:
18: import java.io.Serializable;
19:
20: public class Context implements Serializable {
21:
22: /**
23: *
24: */
25: private static final long serialVersionUID = 400L;
26: public static final int START_UP = 0;
27: public static final int ASSIGN_SEATS = 1;
28: public static final int MAKE_PATH = 2;
29: public static final int CHECK_DONE = 3;
30: public static final int PRINT_RESULTS = 4;
31:
32: public static final String[] stateStrings = { "START_UP",
33: "ASSIGN_SEATS", "MAKE_PATH", "CHECK_DONE", "PRINT_RESULTS" };
34:
35: private int state;
36:
37: public Context() {
38: }
39:
40: public Context(final String state) {
41: if ("start".equals(state)) {
42: this .state = Context.START_UP;
43: } else {
44: throw new RuntimeException("Context '" + state
45: + "' does not exist for Context Enum");
46: }
47: }
48:
49: public Context(final int state) {
50: this .state = state;
51: }
52:
53: public void setState(final int state) {
54: this .state = state;
55: }
56:
57: public boolean isState(final int state) {
58: return this .state == state;
59: }
60:
61: public int getState() {
62: return this .state;
63: }
64:
65: public String getStringValue() {
66: return Context.stateStrings[this .state];
67: }
68:
69: public String toString() {
70: return "[Context state=" + getStringValue() + "]";
71: }
72: }
|