]> git.basschouten.com Git - openhab-addons.git/commitdiff
adapt to core StringUtils (#15769)
authorlsiepel <leosiepel@gmail.com>
Thu, 19 Oct 2023 19:46:58 +0000 (21:46 +0200)
committerGitHub <noreply@github.com>
Thu, 19 Oct 2023 19:46:58 +0000 (21:46 +0200)
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/api/dto/Module.java
bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/handler/SmartherModuleHandler.java
bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/util/StringUtil.java

index 5efa40168423e075952b602d64901ff4b2ac8bc1..ca79ca8976c0cc493b181e9e635bdee37560c66c 100644 (file)
@@ -12,7 +12,7 @@
  */
 package org.openhab.binding.bticinosmarther.internal.api.dto;
 
-import org.openhab.binding.bticinosmarther.internal.util.StringUtil;
+import org.openhab.core.util.StringUtils;
 
 import com.google.gson.annotations.SerializedName;
 
@@ -34,7 +34,7 @@ public class Module {
      * @return a string containing the module device type
      */
     public String getDeviceType() {
-        return StringUtil.capitalizeAll(deviceType);
+        return StringUtils.capitalizeByWhitespace(deviceType);
     }
 
     /**
index 13ae557b6ffe551936d22af4a806ae7e24d73093..921d69452c633fe7287f3e4ccbd3f3ea66c04f3c 100644 (file)
@@ -53,6 +53,7 @@ import org.openhab.core.thing.binding.BaseThingHandler;
 import org.openhab.core.types.Command;
 import org.openhab.core.types.RefreshType;
 import org.openhab.core.types.State;
+import org.openhab.core.util.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -709,9 +710,9 @@ public class SmartherModuleHandler extends BaseThingHandler {
             // Update the Status channels
             updateChannelState(CHANNEL_STATUS_STATE, (localChrono.isActive() ? OnOffType.ON : OnOffType.OFF));
             updateChannelState(CHANNEL_STATUS_FUNCTION,
-                    new StringType(StringUtil.capitalize(localChrono.getFunction().toLowerCase())));
+                    new StringType(StringUtils.capitalize(localChrono.getFunction().toLowerCase())));
             updateChannelState(CHANNEL_STATUS_MODE,
-                    new StringType(StringUtil.capitalize(localChrono.getMode().toLowerCase())));
+                    new StringType(StringUtils.capitalize(localChrono.getMode().toLowerCase())));
             updateChannelState(CHANNEL_STATUS_TEMPERATURE, localChrono.getSetPointTemperature().toState());
             updateChannelState(CHANNEL_STATUS_ENDTIME,
                     new StringType(localChrono.getActivationTimeLabel(timeZoneProvider)));
index 8a0af0103c900e4765e7f697ab8f3a2f0d8eb732..3a48a1dd8acdeb72488b04651a8f35184b05cd01 100644 (file)
@@ -17,8 +17,6 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.io.StringWriter;
-import java.util.Arrays;
-import java.util.stream.Collectors;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
@@ -90,43 +88,6 @@ public final class StringUtil {
         return (s.isEmpty()) ? null : s;
     }
 
-    /**
-     * Capitalizes a string changing the first letter to title case as per {@link Character#toTitleCase(char)}. No other
-     * letters are changed.
-     *
-     * @param str
-     *            the string to capitalize, may be {@code null}
-     *
-     * @return the capitalized string, {@code null} if {@code null} input string
-     */
-    public static @Nullable String capitalize(@Nullable String str) {
-        if (str == null || str.isEmpty()) {
-            return str;
-        }
-        return str.substring(0, 1).toUpperCase() + str.substring(1);
-    }
-
-    /**
-     * Converts all the whitespace separated words in a string into capitalized words, that is each word is made up of a
-     * titlecase character and then a series of lowercase characters.
-     *
-     * @param str
-     *            the string to capitalize, may be {@code null}
-     *
-     * @return the capitalized string, {@code null} if {@code null} input string
-     */
-    public static @Nullable String capitalizeAll(@Nullable String str) {
-        if (str == null || str.isEmpty()) {
-            return str;
-        }
-        // Java 8 version
-        return Arrays.stream(str.split("\\s+")).map(t -> t.substring(0, 1).toUpperCase() + t.substring(1).toLowerCase())
-                .collect(Collectors.joining(" "));
-        // Ready for Java 9+
-        // return Pattern.compile("\\b(.)(.*?)\\b").matcher(str)
-        // .replaceAll(match -> match.group(1).toUpperCase() + match.group(2).toLowerCase());
-    }
-
     /**
      * Get the contents of an {@link InputStream} stream as a string using the default character encoding of the
      * platform. This method buffers the input internally, so there is no need to use a {@code BufferedInputStream}.