Skip to content

Package: KuraResponseCode

KuraResponseCode

nameinstructionbranchcomplexitylinemethod
KuraResponseCode(String, int, int)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
fromResponseCode(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
fromResponseCode(int)
M: 27 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
getCode()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isAccepted()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isBadRequest()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isInternalError()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isNotFound()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 48 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2018, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.service.device.call.message.kura.app.response;
14:
15: import org.eclipse.kapua.service.device.call.message.app.response.DeviceResponseCode;
16:
17: /**
18: * {@link DeviceResponseCode} {@link org.eclipse.kapua.service.device.call.kura.Kura} implementation
19: *
20: * @since 1.0.0
21: */
22: public enum KuraResponseCode implements DeviceResponseCode {
23:
24: /**
25: * Accepted request.
26: *
27: * @since 1.0.0
28: */
29: ACCEPTED(200),
30:
31: /**
32: * Bad request.
33: *
34: * @since 1.0.0
35: */
36: BAD_REQUEST(400),
37:
38: /**
39: * Resource not found.
40: *
41: * @since 1.0.0
42: */
43: NOT_FOUND(404),
44:
45: /**
46: * Internal error.
47: *
48: * @since 1.0.0
49: */
50: INTERNAL_ERROR(500);
51:
52: /**
53: * The REST-like response code.
54: *
55: * @since 1.0.0
56: */
57: private int code;
58:
59: /**
60: * Constructor.
61: *
62: * @param code The REST-like response code.
63: * @since 1.0.0
64: */
65: KuraResponseCode(int code) {
66: this.code = code;
67: }
68:
69: /**
70: * Gets the REST-like response code.
71: *
72: * @return The REST-like response code.
73: * @since 1.0.0
74: */
75: public int getCode() {
76: return code;
77: }
78:
79: /**
80: * Constructs a {@link KuraResponseCode} from a {@link String} representation.
81: *
82: * @param responseCode The {@link String} response code.
83: * @return The matching {@link KuraResponseCode}.
84: * @since 1.0.0
85: */
86: public static KuraResponseCode fromResponseCode(String responseCode) {
87: return fromResponseCode(Integer.valueOf(responseCode));
88: }
89:
90: /**
91: * Constructs a {@link KuraResponseCode} from an {@link Integer} representation.
92: *
93: * @param responseCode The REST-like response code.
94: * @return The matching {@link KuraResponseCode}.
95: * @since 1.0.0
96: */
97: public static KuraResponseCode fromResponseCode(int responseCode) {
98: KuraResponseCode result = null;
99:• for (KuraResponseCode krc : KuraResponseCode.values()) {
100:• if (krc.getCode() == responseCode) {
101: result = krc;
102: break;
103: }
104: }
105:
106: return result;
107: }
108:
109: @Override
110: public boolean isAccepted() {
111: return ACCEPTED.equals(this);
112: }
113:
114: @Override
115: public boolean isBadRequest() {
116: return BAD_REQUEST.equals(this);
117: }
118:
119: @Override
120: public boolean isNotFound() {
121: return NOT_FOUND.equals(this);
122: }
123:
124: @Override
125: public boolean isInternalError() {
126: return INTERNAL_ERROR.equals(this);
127: }
128: }