mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
adapt to core StringUtils (#15769)
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
parent
11a716dfbe
commit
e798ba9406
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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)));
|
||||
|
@ -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}.
|
||||
|
Loading…
Reference in New Issue
Block a user