From d31743ca57781f4b5618f3a84b63d41464e6bcca Mon Sep 17 00:00:00 2001 From: Leo Siepel Date: Tue, 17 Oct 2023 22:53:24 +0200 Subject: [PATCH 1/2] adapt to core StringUtils Signed-off-by: Leo Siepel --- .../LaCrosseTemperatureSensorHandler.java | 2 +- .../internal/lacrosse/LgwSensorHandler.java | 2 +- .../jeelink/internal/util/StringUtils.java | 48 ------------------- 3 files changed, 2 insertions(+), 50 deletions(-) delete mode 100644 bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/util/StringUtils.java diff --git a/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LaCrosseTemperatureSensorHandler.java b/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LaCrosseTemperatureSensorHandler.java index 91d54179f4b6e..bf399725476f3 100644 --- a/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LaCrosseTemperatureSensorHandler.java +++ b/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LaCrosseTemperatureSensorHandler.java @@ -26,7 +26,6 @@ import org.openhab.binding.jeelink.internal.RollingAveragePublisher; import org.openhab.binding.jeelink.internal.RollingReadingAverage; import org.openhab.binding.jeelink.internal.config.LaCrosseTemperatureSensorConfig; -import org.openhab.binding.jeelink.internal.util.StringUtils; import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.unit.SIUnits; @@ -38,6 +37,7 @@ import org.openhab.core.thing.binding.builder.ChannelBuilder; import org.openhab.core.thing.binding.builder.ThingBuilder; import org.openhab.core.thing.type.ChannelTypeUID; +import org.openhab.core.util.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LgwSensorHandler.java b/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LgwSensorHandler.java index 3ad324bd03f00..e9b4ddb0a9eea 100644 --- a/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LgwSensorHandler.java +++ b/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LgwSensorHandler.java @@ -21,7 +21,6 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.jeelink.internal.JeeLinkSensorHandler; import org.openhab.binding.jeelink.internal.ReadingPublisher; -import org.openhab.binding.jeelink.internal.util.StringUtils; import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.unit.SIUnits; import org.openhab.core.library.unit.Units; @@ -31,6 +30,7 @@ import org.openhab.core.thing.binding.builder.ChannelBuilder; import org.openhab.core.thing.binding.builder.ThingBuilder; import org.openhab.core.thing.type.ChannelTypeUID; +import org.openhab.core.util.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/util/StringUtils.java b/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/util/StringUtils.java deleted file mode 100644 index d5d93335f392c..0000000000000 --- a/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/util/StringUtils.java +++ /dev/null @@ -1,48 +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.jeelink.internal.util; - -import org.eclipse.jdt.annotation.NonNullByDefault; - -/** - * Utility class for strings - * - * @author Leo Siepel - Initial contribution - */ -@NonNullByDefault -public final class StringUtils { - - /** - *

- * Capitalizes a String changing the first character to title case. - * No other characters are changed. - *

- * - *
-     * StringUtils.capitalize(null)  = null
-     * StringUtils.capitalize("")    = ""
-     * StringUtils.capitalize("cat") = "Cat"
-     * StringUtils.capitalize("cAt") = "CAt"
-     * StringUtils.capitalize("'cat'") = "'cat'"
-     * 
- * - * @param val the String to capitalize, may not be null - * @return the capitalized String - */ - public static String capitalize(String val) { - if (val.length() == 0) { - return val; - } - return val.substring(0, 1).toUpperCase() + val.substring(1); - } -} From 33e0a1f7933041afb7a68c7b6a1ebc1515c65d8d Mon Sep 17 00:00:00 2001 From: Leo Siepel Date: Tue, 17 Oct 2023 23:01:13 +0200 Subject: [PATCH 2/2] null fix Signed-off-by: Leo Siepel --- .../lacrosse/LaCrosseTemperatureSensorHandler.java | 4 +++- .../jeelink/internal/lacrosse/LgwSensorHandler.java | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LaCrosseTemperatureSensorHandler.java b/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LaCrosseTemperatureSensorHandler.java index bf399725476f3..82f69ab5265a9 100644 --- a/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LaCrosseTemperatureSensorHandler.java +++ b/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LaCrosseTemperatureSensorHandler.java @@ -20,6 +20,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import org.openhab.binding.jeelink.internal.JeeLinkSensorHandler; import org.openhab.binding.jeelink.internal.ReadingPublisher; @@ -93,7 +94,8 @@ private void createMissingChannels(int channelNo) { missingChannels.add(ChannelBuilder .create(new ChannelUID(getThing().getUID(), channelName + idSuffix), "Number") .withType(new ChannelTypeUID(getThing().getThingTypeUID().getBindingId(), channelName)) - .withLabel(StringUtils.capitalize(channelName + labelSuffix)).build()); + .withLabel(Objects.requireNonNull(StringUtils.capitalize(channelName + labelSuffix))) + .build()); } } missingChannels.addAll(getThing().getChannels()); diff --git a/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LgwSensorHandler.java b/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LgwSensorHandler.java index e9b4ddb0a9eea..b57becfbd37d8 100644 --- a/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LgwSensorHandler.java +++ b/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LgwSensorHandler.java @@ -17,6 +17,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; +import java.util.Objects; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.jeelink.internal.JeeLinkSensorHandler; @@ -78,7 +79,8 @@ public void publish(LgwReading reading) { .create(new ChannelUID(getThing().getUID(), HUMIDITY_CHANNEL), "Number:Humidity") .withType(new ChannelTypeUID(getThing().getThingTypeUID().getBindingId(), HUMIDITY_CHANNEL)) - .withLabel(StringUtils.capitalize(HUMIDITY_CHANNEL)).build()); + .withLabel(Objects.requireNonNull(StringUtils.capitalize(HUMIDITY_CHANNEL))) + .build()); updateThing(thingBuilder.build()); hasHumidityChannel = true; @@ -94,7 +96,8 @@ public void publish(LgwReading reading) { .create(new ChannelUID(getThing().getUID(), PRESSURE_CHANNEL), "Number:Pressure") .withType(new ChannelTypeUID(getThing().getThingTypeUID().getBindingId(), PRESSURE_CHANNEL)) - .withLabel(StringUtils.capitalize(PRESSURE_CHANNEL)).build()); + .withLabel(Objects.requireNonNull(StringUtils.capitalize(PRESSURE_CHANNEL))) + .build()); updateThing(thingBuilder.build()); hasPressureChannel = true;