Skip to content

Commit

Permalink
[neeo] Remove org.apache.common (openhab#14442)
Browse files Browse the repository at this point in the history
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
Signed-off-by: Jørgen Austvik <jaustvik@acm.org>
  • Loading branch information
lsiepel authored and austvik committed Mar 27, 2024
1 parent f9cbcb8 commit 3f6f4b7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 3f6f4b7

Please sign in to comment.