diff --git a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/AbstractServlet.java b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/AbstractServlet.java index 5332e60d928e7..36c97cac4e4d2 100644 --- a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/AbstractServlet.java +++ b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/AbstractServlet.java @@ -23,13 +23,13 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.events.Event; import org.openhab.core.events.EventFilter; import org.openhab.io.neeo.NeeoService; import org.openhab.io.neeo.internal.servletservices.ServletService; +import org.openhab.io.neeo.internal.util.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -115,7 +115,7 @@ protected void doGet(@Nullable HttpServletRequest req, @Nullable HttpServletResp return; } - final String[] paths = StringUtils.split(pathInfo.startsWith("/") ? pathInfo.substring(1) : pathInfo, '/'); + final String[] paths = StringUtils.split(pathInfo.startsWith("/") ? pathInfo.substring(1) : pathInfo, "/"); final ServletService service = getService(paths); if (service == null) { @@ -142,7 +142,7 @@ protected void doPost(@Nullable HttpServletRequest req, @Nullable HttpServletRes } final String pathInfo = NeeoUtil.decodeURIComponent(req.getPathInfo()); - final String[] paths = StringUtils.split(pathInfo.startsWith("/") ? pathInfo.substring(1) : pathInfo, '/'); + final String[] paths = StringUtils.split(pathInfo.startsWith("/") ? pathInfo.substring(1) : pathInfo, "/"); final ServletService service = getService(paths); if (service == null) { diff --git a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/OpenHabToDeviceConverter.java b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/OpenHabToDeviceConverter.java index bb5a25cfc1f9e..a9fe8665a4eaf 100644 --- a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/OpenHabToDeviceConverter.java +++ b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/OpenHabToDeviceConverter.java @@ -20,7 +20,6 @@ import java.util.Objects; import java.util.Set; -import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.items.Item; @@ -38,6 +37,7 @@ import org.openhab.io.neeo.internal.models.NeeoDeviceTiming; import org.openhab.io.neeo.internal.models.NeeoDeviceType; import org.openhab.io.neeo.internal.models.NeeoThingUID; +import org.openhab.io.neeo.internal.util.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -146,7 +146,7 @@ NeeoDevice convert(Thing thing) { final NeeoDeviceTiming timing = new NeeoDeviceTiming(standbyDelay, switchDelay, shutDownDelay); final String dc = properties.get("Device Capabilities"); - final String[] deviceCapabilities = dc == null || dc.isEmpty() ? new String[0] : StringUtils.split(dc, ','); + final String[] deviceCapabilities = dc == null || dc.isEmpty() ? new String[0] : StringUtils.split(dc, ","); try { return new NeeoDevice(new NeeoThingUID(thing.getUID()), 0, diff --git a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/ServiceContext.java b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/ServiceContext.java index 3e8f00e9e9925..cd9c860655f9b 100644 --- a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/ServiceContext.java +++ b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/ServiceContext.java @@ -15,7 +15,6 @@ import java.util.Objects; import java.util.UUID; -import org.apache.commons.lang3.RandomStringUtils; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.addon.AddonInfoRegistry; import org.openhab.core.events.EventPublisher; @@ -26,6 +25,7 @@ import org.openhab.core.thing.link.ItemChannelLinkRegistry; import org.openhab.core.thing.type.ChannelTypeRegistry; import org.openhab.core.thing.type.ThingTypeRegistry; +import org.openhab.core.util.StringUtils; import org.openhab.io.neeo.internal.models.NeeoThingUID; import org.osgi.service.component.ComponentContext; import org.osgi.service.http.HttpService; @@ -238,7 +238,7 @@ public NeeoThingUID generate(String thingType) { NeeoUtil.requireNotEmpty(thingType, "thingType cannot be null"); for (int i = 0; i < 100; i++) { - final String id = RandomStringUtils.randomAlphanumeric(8); + final String id = StringUtils.getRandomAlphanumeric(8); final NeeoThingUID uid = new NeeoThingUID(thingType, id); if (getThingRegistry().get(uid.asThingUID()) == null) { return uid; diff --git a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/models/NeeoThingUID.java b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/models/NeeoThingUID.java index 1aa803cb11655..428a440786fcf 100644 --- a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/models/NeeoThingUID.java +++ b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/models/NeeoThingUID.java @@ -12,7 +12,6 @@ */ package org.openhab.io.neeo.internal.models; -import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.thing.ThingUID; import org.openhab.io.neeo.internal.NeeoConstants; @@ -42,8 +41,8 @@ public NeeoThingUID(ThingUID uid) { * @param thingId the thing ID */ public NeeoThingUID(String thingId) { - super(StringUtils.startsWith(thingId, NeeoConstants.NEEO_ADAPTER_PREFIX) - ? StringUtils.substring(thingId, NeeoConstants.NEEO_ADAPTER_PREFIX.length()) + super(thingId.startsWith(NeeoConstants.NEEO_ADAPTER_PREFIX) + ? thingId.substring(NeeoConstants.NEEO_ADAPTER_PREFIX.length()) : thingId); } diff --git a/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/util/StringUtils.java b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/util/StringUtils.java new file mode 100644 index 0000000000000..5eb753b735a76 --- /dev/null +++ b/bundles/org.openhab.io.neeo/src/main/java/org/openhab/io/neeo/internal/util/StringUtils.java @@ -0,0 +1,30 @@ +/** + * 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.io.neeo.internal.util; + +import java.util.Arrays; + +import org.eclipse.jdt.annotation.NonNullByDefault; + +/** + * The {@link StringUtils} class defines some static string utility methods + * + * @author Leo Siepel - Initial contribution + */ +@NonNullByDefault +public class StringUtils { + + public static String[] split(String input, String delimiter) { + return Arrays.stream(input.split(delimiter)).filter(str -> !str.isEmpty()).toArray(String[]::new); + } +}