Skip to content

Commit

Permalink
adapt to core StringUtils (#15769)
Browse files Browse the repository at this point in the history
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
  • Loading branch information
lsiepel authored Oct 19, 2023
1 parent 11a716d commit e798ba9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
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;

Expand Down Expand Up @@ -709,9 +710,9 @@ private void updateModuleStatus() throws SmartherIllegalPropertyValueException {
// 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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
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;
Expand Down Expand Up @@ -90,43 +88,6 @@ public static String defaultIfBlank(String str, String defaultStr) {
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}.
Expand Down

0 comments on commit e798ba9

Please sign in to comment.