2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mikrotik.internal.model;
15 import java.math.BigInteger;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
22 * The {@link RouterosBaseData} is a base class for other data models having internal hashmap access methods and
25 * @author Oleg Vivtash - Initial contribution
28 public abstract class RouterosBaseData {
29 private final Map<String, String> propMap;
31 public RouterosBaseData(Map<String, String> props) {
35 public void mergeProps(Map<String, String> otherProps) {
36 this.propMap.putAll(otherProps);
39 protected boolean hasProp(String key) {
40 return propMap.containsKey(key);
43 protected String getProp(String key, String defaultValue) {
44 return propMap.getOrDefault(key, defaultValue);
47 protected void setProp(String key, String value) {
48 propMap.put(key, value);
51 protected @Nullable String getProp(String key) {
52 return propMap.get(key);
55 protected @Nullable Integer getIntProp(String key) {
56 String val = propMap.get(key);
57 return val == null ? null : Integer.valueOf(val);
60 protected @Nullable BigInteger getBigIntProp(String key) {
61 String val = propMap.get(key);
62 return val == null ? null : new BigInteger(propMap.getOrDefault(key, "0"));
65 protected @Nullable Float getFloatProp(String key) {
66 String val = propMap.get(key);
67 return val == null ? null : Float.valueOf(val);