1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.mina.statemachine.transition;
21
22 import org.apache.mina.statemachine.State;
23 import org.apache.mina.statemachine.StateMachine;
24 import org.apache.mina.statemachine.event.Event;
25
26
27
28
29
30
31
32
33
34 public abstract class AbstractTransition implements Transition {
35
36 private final Object eventId;
37
38
39 private final State nextState;
40
41
42
43
44
45
46
47 public AbstractTransition(Object eventId) {
48 this(eventId, null);
49 }
50
51
52
53
54
55
56
57
58 public AbstractTransition(Object eventId, State nextState) {
59 this.eventId = eventId;
60 this.nextState = nextState;
61 }
62
63
64
65
66
67
68
69 public AbstractTransition(State nextState) {
70 this.eventId = Event.WILDCARD_EVENT_ID;
71 this.nextState = nextState;
72 }
73
74
75
76
77
78 public AbstractTransition() {
79 this.eventId = Event.WILDCARD_EVENT_ID;
80 this.nextState = null;
81 }
82
83
84
85
86 @Override
87 public State getNextState() {
88 return nextState;
89 }
90
91
92
93
94 @Override
95 public boolean execute(Event event) {
96 if (!eventId.equals(Event.WILDCARD_EVENT_ID) && !eventId.equals(event.getId())) {
97 return false;
98 }
99
100 return doExecute(event);
101 }
102
103
104
105
106
107
108
109
110
111
112
113 protected abstract boolean doExecute(Event event);
114
115 @Override
116 public boolean equals(Object o) {
117 if (o == this) {
118 return true;
119 }
120
121 if (!(o instanceof AbstractTransition)) {
122 return false;
123 }
124
125 AbstractTransition./../org/apache/mina/statemachine/transition/AbstractTransition.html#AbstractTransition">AbstractTransition that = (AbstractTransition) o;
126
127 if (eventId != null) {
128 if (!eventId.equals( that.eventId )) {
129 return false;
130 }
131 } else {
132 if (that.eventId != null) {
133 return false;
134 }
135 }
136
137
138 if (nextState != null) {
139 return nextState.equals( that.nextState );
140 } else {
141 return that.nextState == null;
142 }
143 }
144
145 @Override
146 public int hashCode() {
147 int h = 17;
148
149 if ( eventId != null) {
150 h = h*37 + eventId.hashCode();
151 }
152
153 if (nextState != null) {
154 h = h*17 + nextState.hashCode();
155 }
156
157 return h;
158 }
159
160 @Override
161 public String toString() {
162 StringBuilder sb = new StringBuilder();
163
164 sb.append("eventId=").append(eventId);
165 sb.append(",nextState=").append(nextState);
166
167 return sb.toString();
168 }
169 }