]> git.basschouten.com Git - openhab-addons.git/commitdiff
[imperihome] Remove org.apache.common (#14441)
authorlsiepel <leosiepel@gmail.com>
Sun, 19 Feb 2023 19:30:58 +0000 (20:30 +0100)
committerGitHub <noreply@github.com>
Sun, 19 Feb 2023 19:30:58 +0000 (20:30 +0100)
Signed-off-by: lsiepel <leosiepel@gmail.com>
bundles/org.openhab.io.imperihome/src/main/java/org/openhab/io/imperihome/internal/model/device/RgbLightDevice.java
bundles/org.openhab.io.imperihome/src/main/java/org/openhab/io/imperihome/internal/processor/ItemProcessor.java
bundles/org.openhab.io.imperihome/src/main/java/org/openhab/io/imperihome/internal/util/StringUtils.java [new file with mode: 0644]

index ebdd4ad2f745ab305fc9835d77619240e9720d85..0b554a846249d4f4942c0d82c422e3c7c3c36f7d 100644 (file)
@@ -15,13 +15,13 @@ package org.openhab.io.imperihome.internal.model.device;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 
-import org.apache.commons.lang3.StringUtils;
 import org.openhab.core.items.Item;
 import org.openhab.core.library.types.HSBType;
 import org.openhab.core.library.types.PercentType;
 import org.openhab.core.types.State;
 import org.openhab.io.imperihome.internal.model.param.DeviceParam;
 import org.openhab.io.imperihome.internal.model.param.ParamType;
+import org.openhab.io.imperihome.internal.util.StringUtils;
 
 /**
  * RGB light device.
@@ -80,7 +80,7 @@ public class RgbLightDevice extends AbstractEnergyLinkDevice {
 
     private String toHex(int value) {
         String hex = Integer.toHexString(value);
-        return StringUtils.leftPad(hex, 2, '0');
+        return StringUtils.padLeft(hex, 2, "0");
     }
 
     private int convertPercentToByte(PercentType percent) {
index c69b6bd2de860844d8c55071acdfed468ef47641..00a69f92a606239de348cf05ede3bb2e07240b68 100644 (file)
@@ -20,7 +20,6 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.commons.lang3.BooleanUtils;
 import org.openhab.core.items.Item;
 import org.openhab.core.items.ItemRegistry;
 import org.openhab.core.items.ItemRegistryChangeListener;
@@ -58,6 +57,7 @@ import org.openhab.io.imperihome.internal.model.device.WindDevice;
 import org.openhab.io.imperihome.internal.model.param.DeviceParam;
 import org.openhab.io.imperihome.internal.model.param.ParamType;
 import org.openhab.io.imperihome.internal.util.DigestUtil;
+import org.openhab.io.imperihome.internal.util.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -227,7 +227,7 @@ public class ItemProcessor implements ItemRegistryChangeListener {
     }
 
     private boolean isInverted(Map<TagType, List<String>> issTags) {
-        return issTags.containsKey(TagType.INVERT) && BooleanUtils.toBoolean(issTags.get(TagType.INVERT).get(0));
+        return issTags.containsKey(TagType.INVERT) && StringUtils.toBoolean(issTags.get(TagType.INVERT).get(0));
     }
 
     private void setDeviceRoom(AbstractDevice device, Map<TagType, List<String>> issTags) {
diff --git a/bundles/org.openhab.io.imperihome/src/main/java/org/openhab/io/imperihome/internal/util/StringUtils.java b/bundles/org.openhab.io.imperihome/src/main/java/org/openhab/io/imperihome/internal/util/StringUtils.java
new file mode 100644 (file)
index 0000000..7e2f219
--- /dev/null
@@ -0,0 +1,44 @@
+/**
+ * Copyright (c) 2010-2023 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.io.imperihome.internal.util;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+
+/**
+ * The {@link StringUtils} class defines some static string utility methods
+ *
+ * @author Leo Siepel - Initial contribution
+ */
+@NonNullByDefault
+public class StringUtils {
+
+    /**
+     * Simple method to create boolean from string.
+     * 'true', 'on', 'y', 't' or 'yes' (case insensitive) will return true. Otherwise, false is returned.
+     */
+    public static boolean toBoolean(@Nullable String input) {
+        if (input != null) {
+            input = input.toLowerCase();
+        }
+        return "true".equals(input) || "on".equals(input) || "y".equals(input) || "t".equals(input)
+                || "yes".equals(input);
+    }
+
+    public static String padLeft(@Nullable String input, int minSize, String padString) {
+        if (input == null) {
+            input = "";
+        }
+        return String.format("%" + minSize + "s", input).replace(" ", padString);
+    }
+}