22
22
import java .util .Optional ;
23
23
24
24
public final class Status {
25
- private Integer status ;
25
+ public enum StatusCode {
26
+ Success (0x0 ),
27
+ Failure (0x01 ),
28
+ InvalidSusbscription (0x7d ),
29
+ UnsupportedAccess (0x7e ),
30
+ UnsupportedEndPoint (0x7f ),
31
+ InvalidAction (0x80 ),
32
+ UnsupportedCommand (0x81 ),
33
+ Deprecated82 (0x82 ),
34
+ Deprecated83 (0x83 ),
35
+ Deprecated84 (0x84 ),
36
+ InvalidCommand (0x85 ),
37
+ UnsupportedAttribute (0x86 ),
38
+ ConstraintError (0x87 ),
39
+ UnsupportedWrite (0x88 ),
40
+ ResourceExhausted (0x89 ),
41
+ Deprecated8a (0x8a ),
42
+ NotFound (0x8b ),
43
+ UnreportableAttribute (0x8c ),
44
+ InvalidDataType (0x8d ),
45
+ Deprecated8e (0x8e ),
46
+ UnsupportedRead (0x8f ),
47
+ Deprecated90 (0x90 ),
48
+ Deprecated91 (0x91 ),
49
+ DataVersionMismatch (0x92 ),
50
+ Deprecated93 (0x93 ),
51
+ Timeout (0x94 ),
52
+ Reserved95 (0x95 ),
53
+ Reserved96 (0x96 ),
54
+ Reserved97 (0x97 ),
55
+ Reserved98 (0x98 ),
56
+ Reserved99 (0x99 ),
57
+ Reserved9a (0x9a ),
58
+ Busy (0x9c ),
59
+ Deprecatedc0 (0xc0 ),
60
+ Deprecatedc1 (0xc1 ),
61
+ Deprecatedc2 (0xc2 ),
62
+ UnsupportedCluster (0xc3 ),
63
+ Deprecatedc4 (0xc4 ),
64
+ NoUpstreamSubsricption (0xc5 ),
65
+ NeedTimedInteraction (0xc6 ),
66
+ UnsupportedEvent (0xc7 ),
67
+ PathExhausted (0xc8 ),
68
+ TimedRequestMismatch (0xc9 ),
69
+ FailsafeRequired (0xca ),
70
+ InvalidInState (0xcb ),
71
+ NoCommandResponse (0xcc );
72
+
73
+ private int id = 0 ;
74
+
75
+ StatusCode (int id ) {
76
+ this .id = id ;
77
+ }
78
+
79
+ public int getId () {
80
+ return id ;
81
+ }
82
+
83
+ public static StatusCode fromId (int id ) {
84
+ for (StatusCode type : values ()) {
85
+ if (type .getId () == id ) {
86
+ return type ;
87
+ }
88
+ }
89
+ return null ;
90
+ }
91
+ }
92
+
93
+ private StatusCode status = StatusCode .Success ;
26
94
private Optional <Integer > clusterStatus ;
27
95
28
96
private Status (int status , Optional <Integer > clusterStatus ) {
29
- this .status = status ;
97
+ this .status = StatusCode . fromId ( status ) ;
30
98
this .clusterStatus = clusterStatus ;
31
99
}
32
100
33
101
// Getters
34
- public Integer getStatus () {
102
+ public StatusCode getStatus () {
35
103
return status ;
36
104
}
37
105
@@ -43,7 +111,7 @@ public String toString() {
43
111
return String .format (
44
112
Locale .ENGLISH ,
45
113
"status %s, clusterStatus %s" ,
46
- String . valueOf ( status ),
114
+ status . name ( ),
47
115
clusterStatus .isPresent () ? String .valueOf (clusterStatus .get ()) : "None" );
48
116
}
49
117
@@ -55,7 +123,7 @@ public static Status newInstance(int status) {
55
123
return new Status (status , Optional .empty ());
56
124
}
57
125
58
- static Status newInstance (int status , Integer clusterStatus ) {
126
+ public static Status newInstance (int status , Integer clusterStatus ) {
59
127
return new Status (status , Optional .ofNullable (clusterStatus ));
60
128
}
61
129
}
0 commit comments