]> git.basschouten.com Git - openhab-addons.git/blob
8f425bfd975611e9aa0e900ca082022f5d7e4b5e
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.mikrotik.internal.model;
14
15 import java.math.BigInteger;
16 import java.util.Map;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20
21 /**
22  * The {@link RouterosBaseData} is a base class for other data models having internal hashmap access methods and
23  * values convertors.
24  *
25  * @author Oleg Vivtash - Initial contribution
26  */
27 @NonNullByDefault
28 public abstract class RouterosBaseData {
29     private final Map<String, String> propMap;
30
31     public RouterosBaseData(Map<String, String> props) {
32         this.propMap = props;
33     }
34
35     public void mergeProps(Map<String, String> otherProps) {
36         this.propMap.putAll(otherProps);
37     }
38
39     protected boolean hasProp(String key) {
40         return propMap.containsKey(key);
41     }
42
43     protected String getProp(String key, String defaultValue) {
44         return propMap.getOrDefault(key, defaultValue);
45     }
46
47     protected void setProp(String key, String value) {
48         propMap.put(key, value);
49     }
50
51     protected @Nullable String getProp(String key) {
52         return propMap.get(key);
53     }
54
55     protected @Nullable Integer getIntProp(String key) {
56         String val = propMap.get(key);
57         return val == null ? null : Integer.valueOf(val);
58     }
59
60     protected @Nullable BigInteger getBigIntProp(String key) {
61         String val = propMap.get(key);
62         return val == null ? null : new BigInteger(propMap.getOrDefault(key, "0"));
63     }
64
65     protected @Nullable Float getFloatProp(String key) {
66         String val = propMap.get(key);
67         return val == null ? null : Float.valueOf(val);
68     }
69 }