Package: Get
Get
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
getDouble(Map, String) |
|
|
|
|
|
||||||||||||||||||||
getInteger(Map, String) |
|
|
|
|
|
||||||||||||||||||||
getLong(Map, String) |
|
|
|
|
|
||||||||||||||||||||
getNonEmptyString(Map, String) |
|
|
|
|
|
||||||||||||||||||||
getString(Map, String) |
|
|
|
|
|
||||||||||||||||||||
lambda$getNonEmptyString$0(String) |
|
|
|
|
|
Coverage
1: /*******************************************************************************
2: * Copyright (c) 2017, 2022 Red Hat Inc 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: * Red Hat Inc - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.kura.simulator.util;
14:
15: import java.util.Map;
16: import java.util.Optional;
17:
18: public final class Get {
19:
20: private Get() {
21: }
22:
23: public static Optional<Long> getLong(final Map<String, Object> configuration, final String key) {
24: final Object value = configuration.get(key);
25:• if (value == null) {
26: return Optional.empty();
27: }
28:• if (value instanceof Long) {
29: return Optional.of((Long) value);
30: }
31:• if (value instanceof Number) {
32: return Optional.of(((Number) value).longValue());
33: }
34: return Optional.of(Long.parseLong(value.toString()));
35: }
36:
37: public static Optional<Integer> getInteger(final Map<String, Object> configuration, final String key) {
38: final Object value = configuration.get(key);
39:• if (value == null) {
40: return Optional.empty();
41: }
42:• if (value instanceof Integer) {
43: return Optional.of((Integer) value);
44: }
45:• if (value instanceof Number) {
46: return Optional.of(((Number) value).intValue());
47: }
48: return Optional.of(Integer.parseInt(value.toString()));
49: }
50:
51: public static Optional<Double> getDouble(final Map<String, Object> configuration, final String key) {
52: final Object value = configuration.get(key);
53:• if (value == null) {
54: return Optional.empty();
55: }
56:• if (value instanceof Double) {
57: return Optional.of((Double) value);
58: }
59:• if (value instanceof Number) {
60: return Optional.of(((Number) value).doubleValue());
61: }
62: return Optional.of(Double.parseDouble(value.toString()));
63: }
64:
65: public static Optional<String> getNonEmptyString(final Map<String, Object> configuration, final String key) {
66:• return getString(configuration, key).map(str -> !str.isEmpty() ? str : null);
67: }
68:
69: public static Optional<String> getString(final Map<String, Object> configuration, final String key) {
70: final Object value = configuration.get(key);
71:• if (value == null) {
72: return Optional.empty();
73: }
74:• if (value instanceof String) {
75: return Optional.of((String) value);
76: }
77: return Optional.of(value.toString());
78: }
79:
80: }