Skip to content

Package: KuraObjectValueConverter

KuraObjectValueConverter

nameinstructionbranchcomplexitylinemethod
fromString(String, Class)
M: 64 C: 0
0%
M: 18 C: 0
0%
M: 10 C: 0
0%
M: 18 C: 0
0%
M: 1 C: 0
0%
toString(Object)
M: 24 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2016, 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.kura.model.type;
14:
15: import javax.xml.bind.DatatypeConverter;
16:
17: public class KuraObjectValueConverter {
18:
19: private KuraObjectValueConverter() {
20: }
21:
22: public static String toString(Object value) {
23:
24: String stringValue = null;
25:• if (value != null) {
26: Class<?> clazz = value.getClass();
27:• if (clazz == byte[].class || clazz == Byte[].class) {
28: stringValue = DatatypeConverter.printBase64Binary((byte[]) value);
29: } else {
30: // String
31: // Integer
32: // Long
33: // Float
34: // Double
35: // Boolean
36: stringValue = value.toString();
37: }
38: }
39:
40: return stringValue;
41: }
42:
43: public static Object fromString(String stringValue, Class<?> type) throws ClassNotFoundException {
44:
45: Object value = null;
46:• if (stringValue != null) {
47:• if (type == String.class) {
48: value = stringValue;
49:• } else if (type == Integer.class) {
50: value = Integer.parseInt(stringValue);
51:• } else if (type == Long.class) {
52: value = Long.parseLong(stringValue);
53:• } else if (type == Float.class) {
54: value = Float.parseFloat(stringValue);
55:• } else if (type == Double.class) {
56: value = Double.parseDouble(stringValue);
57:• } else if (type == Boolean.class) {
58: value = Boolean.parseBoolean(stringValue);
59:• } else if (type == byte[].class || type == Byte[].class) {
60: value = DatatypeConverter.parseBase64Binary(stringValue);
61: } else {
62: value = stringValue;
63: }
64: }
65:
66: return value;
67: }
68:
69: }