Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / cloud / stack / src / main / java / org / iotivity / cloud / base / protocols / coap / enums / CoapStatus.java
1 package org.iotivity.cloud.base.protocols.coap.enums;
2
3 public enum CoapStatus {
4     // Success 2.xx
5     CREATED(65), DELETED(66), VALID(67), CHANGED(68), CONTENT(69),
6     // Client Error 4.xx
7     BAD_REQUEST(128), UNAUTHORIZED(129), BAD_OPTION(130), FORBIDDEN(131),
8     //
9     NOT_FOUND(132), METHOD_NOT_ALLOWED(133), NOT_ACCEPTABLE(134),
10     //
11     PRECONDITION_FAILED(140), REQUEST_ENTITY_TOO_LARGE(141),
12     //
13     UNSUPPORTED_CONTENT_FORMAT(143),
14     // Server Error 5.xx
15     INTERNAL_SERVER_ERROR(160), NOT_IMPLEMENTED(161), BAD_GATEWAY(162),
16     //
17     SERVICE_UNAVAILABLE(163), GATEWAY_TIMEOUT(164), PROXY_NOT_SUPPORTED(165);
18
19     public static CoapStatus valueOf(int code) {
20         switch (code) {
21             case 65:
22                 return CoapStatus.CREATED;
23
24             case 66:
25                 return CoapStatus.DELETED;
26
27             case 67:
28                 return CoapStatus.VALID;
29
30             case 68:
31                 return CoapStatus.CHANGED;
32
33             case 69:
34                 return CoapStatus.CONTENT;
35
36             case 128:
37                 return CoapStatus.BAD_REQUEST;
38
39             case 129:
40                 return CoapStatus.UNAUTHORIZED;
41
42             case 130:
43                 return CoapStatus.BAD_OPTION;
44
45             case 131:
46                 return CoapStatus.FORBIDDEN;
47
48             case 132:
49                 return CoapStatus.NOT_FOUND;
50
51             case 133:
52                 return CoapStatus.METHOD_NOT_ALLOWED;
53
54             case 134:
55                 return CoapStatus.NOT_ACCEPTABLE;
56
57             case 140:
58                 return CoapStatus.PRECONDITION_FAILED;
59
60             case 141:
61                 return CoapStatus.REQUEST_ENTITY_TOO_LARGE;
62
63             case 143:
64                 return CoapStatus.UNSUPPORTED_CONTENT_FORMAT;
65
66             case 160:
67                 return CoapStatus.INTERNAL_SERVER_ERROR;
68
69             case 161:
70                 return CoapStatus.NOT_IMPLEMENTED;
71
72             case 162:
73                 return CoapStatus.BAD_GATEWAY;
74
75             case 163:
76                 return CoapStatus.SERVICE_UNAVAILABLE;
77
78             case 164:
79                 return CoapStatus.GATEWAY_TIMEOUT;
80
81             case 165:
82                 return CoapStatus.PROXY_NOT_SUPPORTED;
83         }
84
85         throw new IllegalArgumentException("Invalid Status value");
86     }
87
88     private final int code;
89
90     private CoapStatus(int code) {
91         this.code = code;
92     }
93
94     public int getCode() {
95         return code;
96     }
97 }