1
2
3
4
5 package javax.jmdns.impl.constants;
6
7
8
9
10
11
12 public enum DNSState {
13
14
15
16
17 PROBING_1("probing 1", StateClass.probing),
18
19
20
21 PROBING_2("probing 2", StateClass.probing),
22
23
24
25 PROBING_3("probing 3", StateClass.probing),
26
27
28
29 ANNOUNCING_1("announcing 1", StateClass.announcing),
30
31
32
33 ANNOUNCING_2("announcing 2", StateClass.announcing),
34
35
36
37 ANNOUNCED("announced", StateClass.announced),
38
39
40
41 CANCELING_1("canceling 1", StateClass.canceling),
42
43
44
45 CANCELING_2("canceling 2", StateClass.canceling),
46
47
48
49 CANCELING_3("canceling 3", StateClass.canceling),
50
51
52
53 CANCELED("canceled", StateClass.canceled),
54
55
56
57 CLOSING("closing", StateClass.closing),
58
59
60
61 CLOSED("closed", StateClass.closed);
62
63 private enum StateClass {
64 probing, announcing, announced, canceling, canceled, closing, closed
65 }
66
67
68
69 private final String _name;
70
71 private final StateClass _state;
72
73 private DNSState(String name, StateClass state) {
74 _name = name;
75 _state = state;
76 }
77
78 @Override
79 public final String toString() {
80 return _name;
81 }
82
83
84
85
86
87
88
89
90 public final DNSState advance() {
91 switch (this) {
92 case PROBING_1:
93 return PROBING_2;
94 case PROBING_2:
95 return PROBING_3;
96 case PROBING_3:
97 return ANNOUNCING_1;
98 case ANNOUNCING_1:
99 return ANNOUNCING_2;
100 case ANNOUNCING_2:
101 return ANNOUNCED;
102 case ANNOUNCED:
103 return ANNOUNCED;
104 case CANCELING_1:
105 return CANCELING_2;
106 case CANCELING_2:
107 return CANCELING_3;
108 case CANCELING_3:
109 return CANCELED;
110 case CANCELED:
111 return CANCELED;
112 case CLOSING:
113 return CLOSED;
114 case CLOSED:
115 return CLOSED;
116 default:
117
118 return this;
119 }
120 }
121
122
123
124
125
126
127 public final DNSState revert() {
128 switch (this) {
129 case PROBING_1:
130 case PROBING_2:
131 case PROBING_3:
132 case ANNOUNCING_1:
133 case ANNOUNCING_2:
134 case ANNOUNCED:
135 return PROBING_1;
136 case CANCELING_1:
137 case CANCELING_2:
138 case CANCELING_3:
139 return CANCELING_1;
140 case CANCELED:
141 return CANCELED;
142 case CLOSING:
143 return CLOSING;
144 case CLOSED:
145 return CLOSED;
146 default:
147
148 return this;
149 }
150 }
151
152
153
154
155
156
157 public final boolean isProbing() {
158 return _state == StateClass.probing;
159 }
160
161
162
163
164
165
166 public final boolean isAnnouncing() {
167 return _state == StateClass.announcing;
168 }
169
170
171
172
173
174
175 public final boolean isAnnounced() {
176 return _state == StateClass.announced;
177 }
178
179
180
181
182
183
184 public final boolean isCanceling() {
185 return _state == StateClass.canceling;
186 }
187
188
189
190
191
192
193 public final boolean isCanceled() {
194 return _state == StateClass.canceled;
195 }
196
197
198
199
200
201
202 public final boolean isClosing() {
203 return _state == StateClass.closing;
204 }
205
206
207
208
209
210
211 public final boolean isClosed() {
212 return _state == StateClass.closed;
213 }
214
215 }