]> git.basschouten.com Git - openhab-addons.git/commitdiff
adapt to core StringUtils (#15761)
authorlsiepel <leosiepel@gmail.com>
Thu, 19 Oct 2023 19:32:42 +0000 (21:32 +0200)
committerGitHub <noreply@github.com>
Thu, 19 Oct 2023 19:32:42 +0000 (21:32 +0200)
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboSkyHandler.java
bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/util/StringUtils.java [deleted file]
bundles/org.openhab.binding.sensibo/src/test/java/org/openhab/binding/sensibo/internal/util/StringUtilsTest.java [deleted file]

index 124d3078aae7955b9b66b59104f1819be56219b8..2d8f18bf3d3b78f627110cd4c8d5186b91d6c05d 100644 (file)
@@ -39,7 +39,6 @@ import org.openhab.binding.sensibo.internal.config.SensiboSkyConfiguration;
 import org.openhab.binding.sensibo.internal.dto.poddetails.TemperatureDTO;
 import org.openhab.binding.sensibo.internal.model.SensiboModel;
 import org.openhab.binding.sensibo.internal.model.SensiboSky;
-import org.openhab.binding.sensibo.internal.util.StringUtils;
 import org.openhab.core.library.types.DecimalType;
 import org.openhab.core.library.types.OnOffType;
 import org.openhab.core.library.types.QuantityType;
@@ -63,6 +62,7 @@ import org.openhab.core.types.RefreshType;
 import org.openhab.core.types.StateDescriptionFragmentBuilder;
 import org.openhab.core.types.StateOption;
 import org.openhab.core.types.UnDefType;
+import org.openhab.core.util.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -105,7 +105,7 @@ public class SensiboSkyHandler extends SensiboBaseThingHandler implements Channe
             bs.append(t);
         }
 
-        return StringUtils.capitalizeFully(bs.toString()).trim();
+        return StringUtils.capitalizeByUnderscore(bs.toString()).trim();
     }
 
     private String getMacAddress() {
diff --git a/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/util/StringUtils.java b/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/util/StringUtils.java
deleted file mode 100644 (file)
index 1607b21..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * 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.binding.sensibo.internal.util;
-
-import java.util.ArrayList;
-import java.util.List;
-
-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 {
-
-    public static String capitalizeFully(String input) {
-        final String delimiter = "_";
-        String capitalizedFully = "";
-        for (String str : input.split(delimiter)) {
-            String properlyCapitalized = "";
-            if (str.length() > 0) {
-                properlyCapitalized = str.substring(0, 1).toUpperCase();
-            }
-            if (str.length() > 1) {
-                properlyCapitalized = str.substring(1).toLowerCase();
-            }
-            capitalizedFully = capitalizedFully + properlyCapitalized;
-        }
-
-        return capitalizedFully;
-    }
-
-    public static String[] splitByCharacterType(@Nullable String input) {
-        if (input == null) {
-            return new String[0];
-        }
-        if (input.isBlank()) {
-            return new String[0];
-        }
-        List<String> cache = new ArrayList<>();
-        char[] inputAsCharArray = input.toCharArray();
-        int prevType = Character.getType(inputAsCharArray[0]);
-        int prevTypeStart = 0;
-        for (int i = prevTypeStart + 1; i < inputAsCharArray.length; i++) {
-            int curType = Character.getType(inputAsCharArray[i]);
-            if (prevType == curType) {
-                continue;
-            }
-            if (curType == Character.LOWERCASE_LETTER && prevType == Character.UPPERCASE_LETTER) {
-                int tmpStart = i - 1;
-                if (tmpStart != prevTypeStart) {
-                    cache.add(new String(inputAsCharArray, prevTypeStart, tmpStart - prevTypeStart));
-                    prevTypeStart = tmpStart;
-                }
-            } else {
-                cache.add(new String(inputAsCharArray, prevTypeStart, i - prevTypeStart));
-                prevTypeStart = i;
-            }
-            prevType = curType;
-        }
-        cache.add(new String(inputAsCharArray, prevTypeStart, inputAsCharArray.length - prevTypeStart));
-        return cache.toArray(String[]::new);
-    }
-}
diff --git a/bundles/org.openhab.binding.sensibo/src/test/java/org/openhab/binding/sensibo/internal/util/StringUtilsTest.java b/bundles/org.openhab.binding.sensibo/src/test/java/org/openhab/binding/sensibo/internal/util/StringUtilsTest.java
deleted file mode 100644 (file)
index d8bb9a0..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * 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.binding.sensibo.internal.util;
-
-import static org.junit.jupiter.api.Assertions.*;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.junit.jupiter.api.Test;
-
-/**
- * The {@link StringUtils} class defines some static string utility methods
- *
- * @author Leo Siepel - Initial contribution
- */
-@NonNullByDefault
-public class StringUtilsTest {
-
-    @Test
-    public void splitByCharacterType() {
-        assertArrayEquals(new String[0], StringUtils.splitByCharacterType(null));
-        assertArrayEquals(new String[0], StringUtils.splitByCharacterType(""));
-        assertArrayEquals(new String[] { "ab", " ", "de", " ", "fg" }, StringUtils.splitByCharacterType("ab de fg"));
-        assertArrayEquals(new String[] { "ab", "   ", "de", " ", "fg" },
-                StringUtils.splitByCharacterType("ab   de fg"));
-        assertArrayEquals(new String[] { "ab", ":", "cd", ":", "ef" }, StringUtils.splitByCharacterType("ab:cd:ef"));
-        assertArrayEquals(new String[] { "number", "5" }, StringUtils.splitByCharacterType("number5"));
-        assertArrayEquals(new String[] { "foo", "Bar" }, StringUtils.splitByCharacterType("fooBar"));
-        assertArrayEquals(new String[] { "foo", "200", "Bar" }, StringUtils.splitByCharacterType("foo200Bar"));
-        assertArrayEquals(new String[] { "ASF", "Rules" }, StringUtils.splitByCharacterType("ASFRules"));
-    }
-}