Rework more commons-lang usages (#10314)
* Reworks many commons-lang usages to use standard Java * Updates all remaining commons.lang imports to commons.lang3 Related to openhab/openhab-addons#7722 Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
@@ -25,7 +25,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.binding.BindingInfoRegistry;
|
||||
@@ -375,8 +374,7 @@ public class NeeoService implements EventSubscriber, NetworkAddressChangeListene
|
||||
* @param brainId the non-empty brain id
|
||||
* @return the servlet for the brainId or null if none
|
||||
*/
|
||||
@Nullable
|
||||
public NeeoBrainServlet getServlet(String brainId) {
|
||||
public @Nullable NeeoBrainServlet getServlet(String brainId) {
|
||||
NeeoUtil.requireNotEmpty(brainId, "brainId cannot be empty");
|
||||
|
||||
final String url = NeeoUtil.getServletUrl(brainId);
|
||||
@@ -389,11 +387,10 @@ public class NeeoService implements EventSubscriber, NetworkAddressChangeListene
|
||||
* @param servletUrl a non-null, non-empty servlet URL
|
||||
* @return the servlet for the URL or null if not found
|
||||
*/
|
||||
@Nullable
|
||||
private NeeoBrainServlet getServletByUrl(String servletUrl) {
|
||||
private @Nullable NeeoBrainServlet getServletByUrl(String servletUrl) {
|
||||
NeeoUtil.requireNotEmpty(servletUrl, "ServletURL cannot be empty");
|
||||
for (NeeoBrainServlet servlet : servlets) {
|
||||
if (StringUtils.equalsIgnoreCase(servletUrl, servlet.getServletUrl())) {
|
||||
if (servletUrl.equalsIgnoreCase(servlet.getServletUrl())) {
|
||||
return servlet;
|
||||
}
|
||||
}
|
||||
@@ -410,9 +407,8 @@ public class NeeoService implements EventSubscriber, NetworkAddressChangeListene
|
||||
return Collections.singleton(ItemStateChangedEvent.TYPE);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public EventFilter getEventFilter() {
|
||||
public @Nullable EventFilter getEventFilter() {
|
||||
return eventFilter;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.events.Event;
|
||||
@@ -55,8 +55,7 @@ public abstract class AbstractServlet extends HttpServlet implements AutoCloseab
|
||||
private final String servletUrl;
|
||||
|
||||
/** Any event filters */
|
||||
@Nullable
|
||||
private final List<EventFilter> eventFilters;
|
||||
private final @Nullable List<EventFilter> eventFilters;
|
||||
|
||||
/**
|
||||
* Creates a servlet to serve the status/definitions web pages
|
||||
@@ -112,7 +111,7 @@ public abstract class AbstractServlet extends HttpServlet implements AutoCloseab
|
||||
final String pathInfo = NeeoUtil.decodeURIComponent(req.getPathInfo());
|
||||
|
||||
// invalid path - probably someone typed the path in manually
|
||||
if (StringUtils.isEmpty(pathInfo)) {
|
||||
if (pathInfo.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -158,8 +157,7 @@ public abstract class AbstractServlet extends HttpServlet implements AutoCloseab
|
||||
* @param paths the non-null, non-empty paths
|
||||
* @return the service that can handle the path or null if none can
|
||||
*/
|
||||
@Nullable
|
||||
protected ServletService getService(String[] paths) {
|
||||
protected @Nullable ServletService getService(String[] paths) {
|
||||
Objects.requireNonNull(paths, "paths cannot be null");
|
||||
if (paths.length == 0) {
|
||||
throw new IllegalArgumentException("paths cannot be of 0 length");
|
||||
@@ -213,8 +211,7 @@ public abstract class AbstractServlet extends HttpServlet implements AutoCloseab
|
||||
*
|
||||
* @return the possibly null event filters;
|
||||
*/
|
||||
@Nullable
|
||||
public List<EventFilter> getEventFilters() {
|
||||
public @Nullable List<EventFilter> getEventFilters() {
|
||||
return eventFilters;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
@@ -521,11 +520,11 @@ public class NeeoApi implements AutoCloseable {
|
||||
}
|
||||
|
||||
for (NeeoRecipe recipe : GSON.fromJson(resp.getContent(), NeeoRecipe[].class)) {
|
||||
if (StringUtils.equalsIgnoreCase(recipe.getUid(), deviceKey)) {
|
||||
if (deviceKey.equalsIgnoreCase(recipe.getUid())) {
|
||||
final NeeoRecipeUrls urls = recipe.getUrls();
|
||||
final String url = urls == null ? null : (on ? urls.getSetPowerOn() : urls.getSetPowerOff());
|
||||
|
||||
if (url != null && StringUtils.isNotEmpty(url)) {
|
||||
if (url != null && !url.isEmpty()) {
|
||||
final HttpResponse cmdResp = rqst.sendGetCommand(url);
|
||||
if (cmdResp.getHttpCode() != HttpStatus.OK_200) {
|
||||
throw cmdResp.createException();
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.thing.Thing;
|
||||
@@ -122,7 +121,7 @@ public class NeeoDeviceDefinitions {
|
||||
// filter for only things that are still valid
|
||||
final ThingRegistry thingRegistry = context.getThingRegistry();
|
||||
for (NeeoDevice device : uidToDevice.values()) {
|
||||
if (StringUtils.equalsIgnoreCase(NeeoConstants.NEEOIO_BINDING_ID, device.getUid().getBindingId())) {
|
||||
if (NeeoConstants.NEEOIO_BINDING_ID.equalsIgnoreCase(device.getUid().getBindingId())) {
|
||||
devices.add(device);
|
||||
} else {
|
||||
if (thingRegistry.get(device.getUid().asThingUID()) != null) {
|
||||
@@ -176,7 +175,7 @@ public class NeeoDeviceDefinitions {
|
||||
final List<NeeoDevice> devices = new ArrayList<>();
|
||||
for (NeeoDevice device : exposeAll || exposeNeeoBinding ? getAllDevices() : uidToDevice.values()) {
|
||||
if (device.getExposedChannels().length > 0 && !NeeoDeviceType.EXCLUDE.equals(device.getType())
|
||||
&& StringUtils.isNotEmpty(device.getType().toString())) {
|
||||
&& !device.getType().toString().isEmpty()) {
|
||||
devices.add(device);
|
||||
}
|
||||
}
|
||||
@@ -242,7 +241,7 @@ public class NeeoDeviceDefinitions {
|
||||
for (NeeoDevice device : uidToDevice.values()) {
|
||||
if (keys.isBound(device.getUid())) {
|
||||
for (NeeoDeviceChannel channel : device.getExposedChannels()) {
|
||||
if (itemName == null || StringUtils.equalsIgnoreCase(itemName, channel.getItemName())) {
|
||||
if (itemName == null || itemName.equalsIgnoreCase(channel.getItemName())) {
|
||||
channels.add(new AbstractMap.SimpleImmutableEntry<>(device, channel));
|
||||
}
|
||||
}
|
||||
@@ -287,7 +286,7 @@ public class NeeoDeviceDefinitions {
|
||||
public List<NeeoDevice> getAllDevices() {
|
||||
final List<NeeoDevice> devices = new ArrayList<>();
|
||||
for (Entry<NeeoThingUID, NeeoDevice> entry : uidToDevice.entrySet()) {
|
||||
if (StringUtils.equalsIgnoreCase(NeeoConstants.NEEOIO_BINDING_ID, entry.getKey().getBindingId())) {
|
||||
if (NeeoConstants.NEEOIO_BINDING_ID.equalsIgnoreCase(entry.getKey().getBindingId())) {
|
||||
devices.add(entry.getValue());
|
||||
} else {
|
||||
final Thing thing = context.getThingRegistry().get(entry.getKey().asThingUID());
|
||||
|
||||
@@ -20,10 +20,10 @@ import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.openhab.core.thing.ThingUID;
|
||||
@@ -178,7 +178,7 @@ public class NeeoDeviceKeys {
|
||||
sb.append("[");
|
||||
sb.append(entry.getKey());
|
||||
sb.append("=");
|
||||
sb.append(StringUtils.join(entries.toArray()));
|
||||
sb.append(entries.stream().map(Object::toString).collect(Collectors.joining()));
|
||||
sb.append("]");
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ package org.openhab.io.neeo.internal;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.items.Item;
|
||||
@@ -138,7 +137,7 @@ public class NeeoItemValueConverter {
|
||||
return new NeeoItemValue(convertedState == UpDownType.UP);
|
||||
|
||||
} else if (convertedState instanceof DecimalType) {
|
||||
if (StringUtils.isEmpty(format) || channel.getType() == NeeoCapabilityType.SLIDER) {
|
||||
if (format == null || format.isEmpty() || channel.getType() == NeeoCapabilityType.SLIDER) {
|
||||
return new NeeoItemValue(((DecimalType) convertedState).toBigDecimal());
|
||||
}
|
||||
} else if (convertedState instanceof UnDefType) {
|
||||
@@ -150,7 +149,7 @@ public class NeeoItemValueConverter {
|
||||
// Formatting must use the actual state (not converted state) to avoid
|
||||
// issues where a decimal converted to string or otherwise
|
||||
String itemValue;
|
||||
if (format != null && StringUtils.isNotEmpty(format)) {
|
||||
if (format != null && !format.isEmpty()) {
|
||||
if (state instanceof UnDefType) {
|
||||
itemValue = formatUndefined(format);
|
||||
} else if (state instanceof Type) {
|
||||
@@ -230,7 +229,7 @@ public class NeeoItemValueConverter {
|
||||
Objects.requireNonNull(item, "item cannot be null");
|
||||
Objects.requireNonNull(eventType, "eventType cannot be null");
|
||||
|
||||
if (actionValue == null || StringUtils.isEmpty(actionValue)) {
|
||||
if (actionValue == null || actionValue.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -265,9 +264,9 @@ public class NeeoItemValueConverter {
|
||||
}
|
||||
break;
|
||||
case "switch":
|
||||
if (StringUtils.equalsIgnoreCase("true", actionValue)) {
|
||||
if ("true".equalsIgnoreCase(actionValue)) {
|
||||
return OnOffType.ON;
|
||||
} else if (StringUtils.equalsIgnoreCase("false", actionValue)) {
|
||||
} else if ("false".equalsIgnoreCase(actionValue)) {
|
||||
return OnOffType.OFF;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.util.concurrent.Future;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.items.Item;
|
||||
@@ -210,7 +209,7 @@ public class NeeoUtil {
|
||||
resp.setContentType("application/json");
|
||||
resp.setCharacterEncoding("UTF-8");
|
||||
final PrintWriter pw = resp.getWriter();
|
||||
if (StringUtils.isEmpty(str)) {
|
||||
if (str.isEmpty()) {
|
||||
pw.print("{}");
|
||||
} else {
|
||||
pw.print(str);
|
||||
@@ -267,7 +266,7 @@ public class NeeoUtil {
|
||||
*/
|
||||
public static void requireNotEmpty(String value, String msg) {
|
||||
Objects.requireNonNull(value, msg);
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
if (value.isEmpty()) {
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
}
|
||||
@@ -318,7 +317,7 @@ public class NeeoUtil {
|
||||
|
||||
if (cmd.isEnum()) {
|
||||
for (Command cmdEnum : cmd.getEnumConstants()) {
|
||||
if (StringUtils.equalsIgnoreCase(((Enum<?>) cmdEnum).name(), enumName)) {
|
||||
if (((Enum<?>) cmdEnum).name().equalsIgnoreCase(enumName)) {
|
||||
return cmdEnum;
|
||||
}
|
||||
}
|
||||
@@ -347,14 +346,14 @@ public class NeeoUtil {
|
||||
public static String getLabel(@Nullable Item item, @Nullable ChannelType channelType) {
|
||||
if (item != null) {
|
||||
final String label = item.getLabel();
|
||||
if (label != null && StringUtils.isNotEmpty(label)) {
|
||||
if (label != null && !label.isEmpty()) {
|
||||
return label;
|
||||
}
|
||||
}
|
||||
|
||||
if (channelType != null) {
|
||||
final String label = channelType.getLabel();
|
||||
if (StringUtils.isNotEmpty(label)) {
|
||||
if (!label.isEmpty()) {
|
||||
return label;
|
||||
}
|
||||
}
|
||||
@@ -374,8 +373,8 @@ public class NeeoUtil {
|
||||
if (item != null) {
|
||||
final StateDescription sd = item.getStateDescription();
|
||||
final String format = sd == null ? null : sd.getPattern();
|
||||
if (StringUtils.isEmpty(format)) {
|
||||
if (StringUtils.equalsIgnoreCase("datetime", item.getType())) {
|
||||
if (format == null || format.isEmpty()) {
|
||||
if ("datetime".equalsIgnoreCase(item.getType())) {
|
||||
return "%tF %<tT";
|
||||
}
|
||||
} else {
|
||||
@@ -385,8 +384,8 @@ public class NeeoUtil {
|
||||
|
||||
if (channelType != null) {
|
||||
final String format = channelType.getState() == null ? null : channelType.getState().getPattern();
|
||||
if (StringUtils.isEmpty(format)) {
|
||||
if (StringUtils.equalsIgnoreCase("datetime", channelType.getItemType())) {
|
||||
if (format == null || format.isEmpty()) {
|
||||
if ("datetime".equalsIgnoreCase(channelType.getItemType())) {
|
||||
return "%tF %<tT";
|
||||
}
|
||||
} else {
|
||||
@@ -406,7 +405,7 @@ public class NeeoUtil {
|
||||
public static String getUniqueLabel(Set<String> labels, String itemLabel) {
|
||||
Objects.requireNonNull(labels, "labels cannot be null");
|
||||
|
||||
String label = StringUtils.isEmpty(itemLabel) ? "NA" : itemLabel;
|
||||
String label = itemLabel.isEmpty() ? "NA" : itemLabel;
|
||||
int idx = 0;
|
||||
if (labels.contains(label)) {
|
||||
do {
|
||||
@@ -432,7 +431,7 @@ public class NeeoUtil {
|
||||
|
||||
if (groupId != null) {
|
||||
for (ChannelGroupDefinition cgd : thingType.getChannelGroupDefinitions()) {
|
||||
if (StringUtils.equals(groupId, cgd.getId())) {
|
||||
if (Objects.equals(groupId, cgd.getId())) {
|
||||
return cgd.getLabel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.items.Item;
|
||||
@@ -101,8 +101,9 @@ class OpenHabToDeviceConverter {
|
||||
.getChannelType(channel.getChannelTypeUID());
|
||||
|
||||
NeeoCapabilityType type = NeeoCapabilityType.EXCLUDE;
|
||||
if (StringUtils.equalsIgnoreCase(NeeoConstants.NEEOBINDING_BINDING_ID, thingUID.getBindingId())) {
|
||||
if (StringUtils.startsWithIgnoreCase(thingUID.getAsString(), NeeoConstants.NEEOBINDING_DEVICE_ID)) {
|
||||
if (NeeoConstants.NEEOBINDING_BINDING_ID.equalsIgnoreCase(thingUID.getBindingId())) {
|
||||
if (thingUID.getAsString().toLowerCase()
|
||||
.startsWith(NeeoConstants.NEEOBINDING_DEVICE_ID.toLowerCase())) {
|
||||
// all device channels are currently macros - so buttons are appropriate
|
||||
type = NeeoCapabilityType.BUTTON;
|
||||
} else {
|
||||
@@ -127,7 +128,7 @@ class OpenHabToDeviceConverter {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (StringUtils.equalsIgnoreCase(NeeoConstants.NEEOBINDING_BINDING_ID, thing.getUID().getBindingId())) {
|
||||
if (NeeoConstants.NEEOBINDING_BINDING_ID.equalsIgnoreCase(thing.getUID().getBindingId())) {
|
||||
final Map<String, String> properties = thing.getProperties();
|
||||
/** The following properties have matches in org.openhab.binding.neeo.NeeoDeviceHandler.java */
|
||||
String neeoType = properties.get("Type");
|
||||
@@ -145,7 +146,7 @@ class OpenHabToDeviceConverter {
|
||||
final NeeoDeviceTiming timing = new NeeoDeviceTiming(standbyDelay, switchDelay, shutDownDelay);
|
||||
|
||||
final String dc = properties.get("Device Capabilities");
|
||||
final String[] deviceCapabilities = StringUtils.isEmpty(dc) ? 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,
|
||||
@@ -174,9 +175,9 @@ class OpenHabToDeviceConverter {
|
||||
* @param value a possibly null, possibly empty value to parse
|
||||
* @return an Integer or null if not a number
|
||||
*/
|
||||
@Nullable
|
||||
private static Integer parseInteger(String value) {
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
|
||||
private static @Nullable Integer parseInteger(String value) {
|
||||
if (value.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
@@ -194,7 +195,7 @@ class OpenHabToDeviceConverter {
|
||||
*/
|
||||
@Nullable
|
||||
List<NeeoDeviceChannel> getNeeoDeviceChannel(String itemName) {
|
||||
if (StringUtils.isEmpty(itemName)) {
|
||||
if (itemName.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ package org.openhab.io.neeo.internal;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.RandomStringUtils;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.binding.BindingInfoRegistry;
|
||||
import org.openhab.core.events.EventPublisher;
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.binding.BindingInfo;
|
||||
@@ -104,7 +104,7 @@ public class TokenSearch {
|
||||
final Thing thing = context.getThingRegistry().get(device.getUid().asThingUID());
|
||||
if (thing != null) {
|
||||
final String location = thing.getLocation();
|
||||
if (location != null && StringUtils.isNotEmpty(location)) {
|
||||
if (location != null && !location.isEmpty()) {
|
||||
score += search(location, needles);
|
||||
}
|
||||
|
||||
@@ -160,13 +160,13 @@ public class TokenSearch {
|
||||
int arrayLength = needles.length;
|
||||
for (int i = 0; i < arrayLength; i++) {
|
||||
String needle = needles[i];
|
||||
int stringPos = StringUtils.indexOfIgnoreCase(haystack, needle);
|
||||
int stringPos = haystack.toLowerCase().indexOf(needle.toLowerCase());
|
||||
int tokenScore = 0;
|
||||
if (stringPos > -1) {
|
||||
if (needle.length() < 2) {
|
||||
tokenScore = 1;
|
||||
} else {
|
||||
if (StringUtils.equalsIgnoreCase(haystack, needle)) {
|
||||
if (haystack.equalsIgnoreCase(needle)) {
|
||||
tokenScore = 6;
|
||||
} else if (stringPos == 0) {
|
||||
tokenScore = 2;
|
||||
|
||||
@@ -36,7 +36,6 @@ import javax.jmdns.ServiceInfo;
|
||||
import javax.jmdns.ServiceListener;
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.common.ThreadPoolManager;
|
||||
@@ -142,9 +141,9 @@ public class MdnsBrainDiscovery extends AbstractBrainDiscovery {
|
||||
final String[] ipAddresses = gson.fromJson(json, String[].class);
|
||||
if (ipAddresses != null) {
|
||||
logger.debug("Restoring discovery from {}: {}", file.getAbsolutePath(),
|
||||
StringUtils.join(ipAddresses, ','));
|
||||
String.join(",", ipAddresses));
|
||||
for (String ipAddress : ipAddresses) {
|
||||
if (StringUtils.isNotBlank(ipAddress)) {
|
||||
if (!ipAddress.isBlank()) {
|
||||
addDiscovered(ipAddress, false);
|
||||
}
|
||||
}
|
||||
@@ -184,7 +183,7 @@ public class MdnsBrainDiscovery extends AbstractBrainDiscovery {
|
||||
@Nullable
|
||||
private Entry<String, InetAddress> getNeeoBrainInfo(ServiceInfo info) {
|
||||
Objects.requireNonNull(info, "info cannot be null");
|
||||
if (!StringUtils.equals("neeo", info.getApplication())) {
|
||||
if (!"neeo".equals(info.getApplication())) {
|
||||
logger.debug("A non-neeo application was found for the NEEO MDNS: {}", info);
|
||||
return null;
|
||||
}
|
||||
@@ -338,7 +337,7 @@ public class MdnsBrainDiscovery extends AbstractBrainDiscovery {
|
||||
systemsLock.lock();
|
||||
try {
|
||||
final Optional<NeeoSystemInfo> sysInfo = systems.keySet().stream()
|
||||
.filter(e -> StringUtils.equals(servletUrl, NeeoUtil.getServletUrl(e.getHostname()))).findFirst();
|
||||
.filter(e -> servletUrl.equals(NeeoUtil.getServletUrl(e.getHostname()))).findFirst();
|
||||
if (sysInfo.isPresent()) {
|
||||
systems.remove(sysInfo.get());
|
||||
fireRemoved(sysInfo.get());
|
||||
@@ -371,7 +370,7 @@ public class MdnsBrainDiscovery extends AbstractBrainDiscovery {
|
||||
try {
|
||||
NeeoSystemInfo foundInfo = null;
|
||||
for (NeeoSystemInfo existingSysInfo : systems.keySet()) {
|
||||
if (StringUtils.equals(existingSysInfo.getHostname(), brainInfo.getKey())) {
|
||||
if (existingSysInfo.getHostname().equals(brainInfo.getKey())) {
|
||||
foundInfo = existingSysInfo;
|
||||
break;
|
||||
}
|
||||
@@ -398,7 +397,7 @@ public class MdnsBrainDiscovery extends AbstractBrainDiscovery {
|
||||
final List<String> ipAddresses = systems.values().stream().map(e -> e.getHostAddress())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
logger.debug("Saving brain's discovered to {}: {}", file.toPath(), StringUtils.join(ipAddresses, ','));
|
||||
logger.debug("Saving brain's discovered to {}: {}", file.toPath(), String.join(",", ipAddresses));
|
||||
|
||||
final String json = gson.toJson(ipAddresses);
|
||||
final byte[] contents = json.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
@@ -14,7 +14,6 @@ package org.openhab.io.neeo.internal.models;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
@@ -58,11 +57,11 @@ public enum ItemSubType {
|
||||
* @return the ItemSubType type
|
||||
*/
|
||||
public static ItemSubType parse(final String text) {
|
||||
if (StringUtils.isEmpty(text)) {
|
||||
if (text.isEmpty()) {
|
||||
return NONE;
|
||||
}
|
||||
for (ItemSubType enm : ItemSubType.values()) {
|
||||
if (StringUtils.equalsIgnoreCase(text, enm.text)) {
|
||||
if (text.equalsIgnoreCase(enm.text)) {
|
||||
return enm;
|
||||
}
|
||||
}
|
||||
@@ -77,11 +76,11 @@ public enum ItemSubType {
|
||||
* @return true if valid, false otherwise
|
||||
*/
|
||||
public static boolean isValid(final String text) {
|
||||
if (StringUtils.isEmpty(text)) {
|
||||
if (text.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
for (ItemSubType enm : ItemSubType.values()) {
|
||||
if (StringUtils.equalsIgnoreCase(text, enm.text)) {
|
||||
if (text.equalsIgnoreCase(enm.text)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ package org.openhab.io.neeo.internal.models;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
@@ -57,11 +56,11 @@ public enum ListUiAction {
|
||||
* @return the ListUiAction type
|
||||
*/
|
||||
public static ListUiAction parse(final String text) {
|
||||
if (StringUtils.isEmpty(text)) {
|
||||
if (text.isEmpty()) {
|
||||
return CLOSE;
|
||||
}
|
||||
for (ListUiAction enm : ListUiAction.values()) {
|
||||
if (StringUtils.equalsIgnoreCase(text, enm.text)) {
|
||||
if (text.equalsIgnoreCase(enm.text)) {
|
||||
return enm;
|
||||
}
|
||||
}
|
||||
@@ -76,11 +75,11 @@ public enum ListUiAction {
|
||||
* @return true if valid, false otherwise
|
||||
*/
|
||||
public static boolean isValid(final String text) {
|
||||
if (StringUtils.isEmpty(text)) {
|
||||
if (text.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
for (ListUiAction enm : ListUiAction.values()) {
|
||||
if (StringUtils.equalsIgnoreCase(text, enm.text)) {
|
||||
if (text.equalsIgnoreCase(enm.text)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ package org.openhab.io.neeo.internal.models;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
@@ -110,28 +109,28 @@ public class NeeoButtonGroup {
|
||||
*/
|
||||
@Nullable
|
||||
public static NeeoButtonGroup parse(final String text) {
|
||||
if (StringUtils.isEmpty(text)) {
|
||||
if (text.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// note: if we add more - might want to switch this into a loop
|
||||
if (StringUtils.equalsIgnoreCase(text, POWERONOFF.text)) {
|
||||
if (text.equalsIgnoreCase(POWERONOFF.text)) {
|
||||
return POWERONOFF;
|
||||
}
|
||||
|
||||
if (StringUtils.equalsIgnoreCase(text, VOLUMES.text)) {
|
||||
if (text.equalsIgnoreCase(VOLUMES.text)) {
|
||||
return VOLUMES;
|
||||
}
|
||||
|
||||
if (StringUtils.equalsIgnoreCase(text, CHANNELS.text)) {
|
||||
if (text.equalsIgnoreCase(CHANNELS.text)) {
|
||||
return CHANNELS;
|
||||
}
|
||||
|
||||
if (StringUtils.equalsIgnoreCase(text, CURSORUPDOWN.text)) {
|
||||
if (text.equalsIgnoreCase(CURSORUPDOWN.text)) {
|
||||
return CURSORUPDOWN;
|
||||
}
|
||||
|
||||
if (StringUtils.equalsIgnoreCase(text, CURSORLEFTRIGHT.text)) {
|
||||
if (text.equalsIgnoreCase(CURSORLEFTRIGHT.text)) {
|
||||
return CURSORLEFTRIGHT;
|
||||
}
|
||||
|
||||
@@ -145,7 +144,7 @@ public class NeeoButtonGroup {
|
||||
* @return true if matches, false otherwise
|
||||
*/
|
||||
public boolean equals(String text) {
|
||||
return StringUtils.equalsIgnoreCase(this.text, text);
|
||||
return this.text.equalsIgnoreCase(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,7 +14,6 @@ package org.openhab.io.neeo.internal.models;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.thing.type.ChannelType;
|
||||
@@ -72,11 +71,11 @@ public enum NeeoCapabilityType {
|
||||
* @return the NeeoCapabilityType type
|
||||
*/
|
||||
public static NeeoCapabilityType parse(final String text) {
|
||||
if (StringUtils.isEmpty(text)) {
|
||||
if (text.isEmpty()) {
|
||||
return EXCLUDE;
|
||||
}
|
||||
for (NeeoCapabilityType enm : NeeoCapabilityType.values()) {
|
||||
if (StringUtils.equalsIgnoreCase(text, enm.text)) {
|
||||
if (text.equalsIgnoreCase(enm.text)) {
|
||||
return enm;
|
||||
}
|
||||
}
|
||||
@@ -91,11 +90,12 @@ public enum NeeoCapabilityType {
|
||||
* @return the best guess {@link NeeoCapabilityType}
|
||||
*/
|
||||
public static NeeoCapabilityType guessType(@Nullable ChannelType channelType) {
|
||||
if (channelType == null || StringUtils.isEmpty(channelType.getItemType())) {
|
||||
String itemType = channelType == null ? null : channelType.getItemType();
|
||||
if (channelType == null || itemType == null || itemType.isEmpty()) {
|
||||
return NeeoCapabilityType.EXCLUDE;
|
||||
}
|
||||
|
||||
switch (channelType.getItemType().toLowerCase()) {
|
||||
switch (itemType.toLowerCase()) {
|
||||
case "switch":
|
||||
case "contact":
|
||||
case "rollershutter":
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.items.Item;
|
||||
@@ -72,14 +71,13 @@ public class NeeoDevice {
|
||||
/**
|
||||
* The specific name for the device, if null - NEEO will default it based on the type (ie "ACCESSORY", etc)
|
||||
*/
|
||||
@Nullable
|
||||
private final String specificName;
|
||||
|
||||
private final @Nullable String specificName;
|
||||
|
||||
/**
|
||||
* The icon name to assign. If null, NEEO will default it to a standard icon based on the type
|
||||
*/
|
||||
@Nullable
|
||||
private final String iconName;
|
||||
private final @Nullable String iconName;
|
||||
|
||||
/**
|
||||
* The driver version for the device
|
||||
@@ -173,7 +171,7 @@ public class NeeoDevice {
|
||||
this.driverVersion = driverVersion;
|
||||
this.type = type;
|
||||
this.manufacturer = manufacturer;
|
||||
this.name = name == null || StringUtils.isEmpty(name) ? "(N/A)" : name;
|
||||
this.name = name == null || name.isEmpty() ? "(N/A)" : name;
|
||||
this.specificName = specificName;
|
||||
this.iconName = iconName;
|
||||
this.channels.addAll(channels);
|
||||
@@ -224,8 +222,7 @@ public class NeeoDevice {
|
||||
*
|
||||
* @return a possibly null, possibly empty specific name
|
||||
*/
|
||||
@Nullable
|
||||
public String getSpecificName() {
|
||||
public @Nullable String getSpecificName() {
|
||||
return specificName;
|
||||
}
|
||||
|
||||
@@ -234,8 +231,7 @@ public class NeeoDevice {
|
||||
*
|
||||
* @return a possibly null, possibly empty icon name
|
||||
*/
|
||||
@Nullable
|
||||
public String getIconName() {
|
||||
public @Nullable String getIconName() {
|
||||
return iconName;
|
||||
}
|
||||
|
||||
@@ -262,8 +258,7 @@ public class NeeoDevice {
|
||||
*
|
||||
* @return a possibly null {@link NeeoDeviceTiming}
|
||||
*/
|
||||
@Nullable
|
||||
public NeeoDeviceTiming getDeviceTiming() {
|
||||
public @Nullable NeeoDeviceTiming getDeviceTiming() {
|
||||
if (supportTiming(this)) {
|
||||
return timing;
|
||||
}
|
||||
@@ -287,8 +282,7 @@ public class NeeoDevice {
|
||||
public NeeoDeviceChannel[] getExposedChannels() {
|
||||
final List<NeeoDeviceChannel> exposedChannels = new ArrayList<>(channels.size());
|
||||
for (NeeoDeviceChannel channel : channels) {
|
||||
if (channel.getType() != NeeoCapabilityType.EXCLUDE
|
||||
&& StringUtils.isNotEmpty(channel.getType().toString())) {
|
||||
if (channel.getType() != NeeoCapabilityType.EXCLUDE && !channel.getType().toString().isEmpty()) {
|
||||
exposedChannels.add(channel);
|
||||
}
|
||||
}
|
||||
@@ -308,8 +302,8 @@ public class NeeoDevice {
|
||||
for (NeeoDeviceChannel channel : channels) {
|
||||
|
||||
final boolean notExcluded = channel.getType() != NeeoCapabilityType.EXCLUDE;
|
||||
final boolean notEmpty = StringUtils.isNotEmpty(channel.getType().toString());
|
||||
final boolean isItemMatch = StringUtils.equalsIgnoreCase(itemName, channel.getItemName());
|
||||
final boolean notEmpty = !channel.getType().toString().isEmpty();
|
||||
final boolean isItemMatch = itemName.equalsIgnoreCase(channel.getItemName());
|
||||
|
||||
logger.trace("isExposed(channel): {} --- notExcluded({}) -- notEmpty({}) -- isItemMatch({}) -- {}",
|
||||
itemName, notExcluded, notEmpty, isItemMatch, channel);
|
||||
@@ -330,13 +324,12 @@ public class NeeoDevice {
|
||||
* @param channelNbr the channel nbr
|
||||
* @return the channel or null if none found
|
||||
*/
|
||||
@Nullable
|
||||
public NeeoDeviceChannel getChannel(String itemName, ItemSubType subType, int channelNbr) {
|
||||
public @Nullable NeeoDeviceChannel getChannel(String itemName, ItemSubType subType, int channelNbr) {
|
||||
NeeoUtil.requireNotEmpty(itemName, "itemName cannot be empty");
|
||||
Objects.requireNonNull(subType, "subType cannot be null");
|
||||
|
||||
for (NeeoDeviceChannel channel : channels) {
|
||||
if (StringUtils.equalsIgnoreCase(itemName, channel.getItemName()) && channel.getSubType() == subType
|
||||
if (itemName.equalsIgnoreCase(channel.getItemName()) && channel.getSubType() == subType
|
||||
&& channel.getChannelNbr() == channelNbr) {
|
||||
return channel;
|
||||
}
|
||||
@@ -351,11 +344,10 @@ public class NeeoDevice {
|
||||
* @param context the non-null service context
|
||||
* @return the new {@link NeeoDevice} or null if the {@link Thing} doesn't exist anymore
|
||||
*/
|
||||
@Nullable
|
||||
public NeeoDevice merge(ServiceContext context) {
|
||||
public @Nullable NeeoDevice merge(ServiceContext context) {
|
||||
Objects.requireNonNull(context, "context cannot be null");
|
||||
|
||||
if (StringUtils.equalsIgnoreCase(NeeoConstants.NEEOIO_BINDING_ID, uid.getBindingId())) {
|
||||
if (NeeoConstants.NEEOIO_BINDING_ID.equals(uid.getBindingId())) {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ package org.openhab.io.neeo.internal.models;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.thing.type.ChannelKind;
|
||||
|
||||
@@ -50,11 +49,11 @@ public enum NeeoDeviceChannelKind {
|
||||
* @return the NeeoDeviceChannelKind type
|
||||
*/
|
||||
public static NeeoDeviceChannelKind parse(final String text) {
|
||||
if (StringUtils.isEmpty(text)) {
|
||||
if (text.isEmpty()) {
|
||||
return ITEM;
|
||||
}
|
||||
for (NeeoDeviceChannelKind enm : NeeoDeviceChannelKind.values()) {
|
||||
if (StringUtils.equalsIgnoreCase(text, enm.text)) {
|
||||
if (text.equalsIgnoreCase(enm.text)) {
|
||||
return enm;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ package org.openhab.io.neeo.internal.models;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.items.Item;
|
||||
import org.openhab.core.library.types.PercentType;
|
||||
@@ -64,7 +63,7 @@ public class NeeoDeviceChannelRange {
|
||||
}
|
||||
this.minValue = minValue;
|
||||
this.maxValue = maxValue;
|
||||
this.unit = StringUtils.isEmpty(unit) ? UNIT_NUMBER : unit;
|
||||
this.unit = unit.isEmpty() ? UNIT_NUMBER : unit;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,7 +14,6 @@ package org.openhab.io.neeo.internal.models;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
@@ -51,7 +50,7 @@ public class NeeoDeviceType {
|
||||
*/
|
||||
private NeeoDeviceType(final String text) {
|
||||
Objects.requireNonNull(text, "text is required");
|
||||
this.text = StringUtils.equalsIgnoreCase(text, ACCESSORY) ? ACCESSOIRE.text : text;
|
||||
this.text = text.equalsIgnoreCase(ACCESSORY) ? ACCESSOIRE.text : text;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,11 +60,11 @@ public class NeeoDeviceType {
|
||||
* @return the possibly null NeeoDeviceType
|
||||
*/
|
||||
public static NeeoDeviceType parse(final String text) {
|
||||
if (StringUtils.isEmpty(text)) {
|
||||
if (text.isEmpty()) {
|
||||
return EXCLUDE;
|
||||
}
|
||||
|
||||
if (StringUtils.equalsIgnoreCase(text, ACCESSOIRE.text) || StringUtils.equalsIgnoreCase(text, ACCESSORY)) {
|
||||
if (text.equalsIgnoreCase(ACCESSOIRE.text) || text.equalsIgnoreCase(ACCESSORY)) {
|
||||
return ACCESSOIRE;
|
||||
}
|
||||
|
||||
@@ -82,7 +81,7 @@ public class NeeoDeviceType {
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
return StringUtils.equals(text, ((NeeoDeviceType) obj).text);
|
||||
return text.equals(((NeeoDeviceType) obj).text);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
*/
|
||||
package org.openhab.io.neeo.internal.models;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.io.neeo.internal.NeeoUtil;
|
||||
@@ -29,16 +28,13 @@ public class NeeoDirectoryResultItem {
|
||||
private final String title;
|
||||
|
||||
/** The URI to the thumbnail representing the item */
|
||||
@Nullable
|
||||
private final String thumbnailUri;
|
||||
private final @Nullable String thumbnailUri;
|
||||
|
||||
/** The browse identifier (reflected back in a request if this item is a container) */
|
||||
@Nullable
|
||||
private final String browseIdentifier;
|
||||
private final @Nullable String browseIdentifier;
|
||||
|
||||
/** The action identifier (reflected back in a request if this is a leaf) */
|
||||
@Nullable
|
||||
private final String actionIdentifier;
|
||||
private final @Nullable String actionIdentifier;
|
||||
|
||||
/** Whether the item is queueable (no explanation posted by NEEO) */
|
||||
private final boolean isQueueable;
|
||||
@@ -57,7 +53,8 @@ public class NeeoDirectoryResultItem {
|
||||
@Nullable String actionIdentifier, boolean isQueueable) {
|
||||
NeeoUtil.requireNotEmpty(title, "title cannot be empty");
|
||||
|
||||
if (StringUtils.isEmpty(browseIdentifier) && StringUtils.isEmpty(actionIdentifier)) {
|
||||
if ((browseIdentifier == null || browseIdentifier.isEmpty())
|
||||
&& (actionIdentifier == null || actionIdentifier.isEmpty())) {
|
||||
throw new IllegalArgumentException("Either browserIdentifier or actionIdentifier must be specified");
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
*/
|
||||
package org.openhab.io.neeo.internal.models;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.io.neeo.internal.NeeoUtil;
|
||||
@@ -43,7 +42,7 @@ public class NeeoNotification {
|
||||
NeeoUtil.requireNotEmpty(itemName, "itemName cannot be empty");
|
||||
|
||||
this.type = deviceKey + ":" + itemName;
|
||||
this.data = data == null || (data instanceof String && StringUtils.isEmpty(data.toString())) ? "-" : data;
|
||||
this.data = data == null || (data instanceof String && data.toString().isEmpty()) ? "-" : data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
*/
|
||||
package org.openhab.io.neeo.internal.models;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.io.neeo.internal.NeeoConstants;
|
||||
@@ -56,14 +55,13 @@ public class NeeoSensorNotification {
|
||||
NeeoUtil.requireNotEmpty(deviceKey, "deviceKey cannot be empty");
|
||||
NeeoUtil.requireNotEmpty(itemName, "itemName cannot be empty");
|
||||
|
||||
this.type = overrideType == null || StringUtils.isEmpty(overrideType)
|
||||
? NeeoConstants.NEEO_SENSOR_NOTIFICATION_TYPE
|
||||
this.type = overrideType == null || overrideType.isEmpty() ? NeeoConstants.NEEO_SENSOR_NOTIFICATION_TYPE
|
||||
: overrideType;
|
||||
this.data = new SensorNotificationData(
|
||||
deviceKey + ":" + itemName
|
||||
+ (StringUtils.endsWithIgnoreCase(itemName, NeeoConstants.NEEO_SENSOR_SUFFIX) ? ""
|
||||
+ (itemName.toLowerCase().endsWith(NeeoConstants.NEEO_SENSOR_SUFFIX.toLowerCase()) ? ""
|
||||
: NeeoConstants.NEEO_SENSOR_SUFFIX),
|
||||
data == null || (data instanceof String && StringUtils.isEmpty(data.toString())) ? "-" : data);
|
||||
data == null || (data instanceof String && data.toString().isEmpty()) ? "-" : data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,6 @@ package org.openhab.io.neeo.internal.models;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.io.neeo.internal.NeeoUtil;
|
||||
@@ -81,7 +80,7 @@ public class NeeoSystemInfo {
|
||||
* @return true if greater than or equal, false otherwise
|
||||
*/
|
||||
public boolean isFirmwareGreaterOrEqual(String checkFirmwareVersion) {
|
||||
if (StringUtils.isEmpty(checkFirmwareVersion)) {
|
||||
if (checkFirmwareVersion.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -136,6 +135,6 @@ public class NeeoSystemInfo {
|
||||
return false;
|
||||
}
|
||||
|
||||
return StringUtils.equals(hostname, ((NeeoSystemInfo) obj).hostname);
|
||||
return hostname.equals(((NeeoSystemInfo) obj).hostname);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
package org.openhab.io.neeo.internal.models;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
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;
|
||||
|
||||
@@ -16,7 +16,6 @@ import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.io.neeo.internal.NeeoConstants;
|
||||
@@ -90,16 +89,16 @@ public class NeeoBrainDeviceSerializer implements JsonSerializer<NeeoDevice> {
|
||||
jsonObject.add("device", deviceObj);
|
||||
|
||||
final String specificName = device.getSpecificName();
|
||||
if (specificName != null && StringUtils.isNotEmpty(specificName)) {
|
||||
if (specificName != null && !specificName.isEmpty()) {
|
||||
deviceObj.addProperty("specificname", specificName);
|
||||
jsonObject.addProperty("specificname", specificName);
|
||||
} else if (StringUtils.isNotEmpty(deviceName)) {
|
||||
} else if (!deviceName.isEmpty()) {
|
||||
deviceObj.addProperty("specificname", deviceName);
|
||||
jsonObject.addProperty("specificname", deviceName);
|
||||
}
|
||||
|
||||
final String iconName = device.getIconName();
|
||||
if (iconName != null && StringUtils.isNotEmpty(iconName)) {
|
||||
if (iconName != null && !iconName.isEmpty()) {
|
||||
deviceObj.addProperty("icon", iconName);
|
||||
jsonObject.addProperty("icon", iconName);
|
||||
}
|
||||
@@ -113,19 +112,19 @@ public class NeeoBrainDeviceSerializer implements JsonSerializer<NeeoDevice> {
|
||||
|
||||
final String uniqueItemName = channel.getUniqueItemName();
|
||||
final String sensorItemName = uniqueItemName
|
||||
+ (StringUtils.endsWithIgnoreCase(uniqueItemName, NeeoConstants.NEEO_SENSOR_SUFFIX) ? ""
|
||||
+ (uniqueItemName.toLowerCase().endsWith(NeeoConstants.NEEO_SENSOR_SUFFIX.toLowerCase()) ? ""
|
||||
: NeeoConstants.NEEO_SENSOR_SUFFIX);
|
||||
|
||||
if (capabilityType == NeeoCapabilityType.BUTTON) {
|
||||
final String name = StringUtils.isEmpty(channel.getLabel()) ? uniqueItemName : channel.getLabel();
|
||||
final String name = channel.getLabel().isEmpty() ? uniqueItemName : channel.getLabel();
|
||||
|
||||
if (channel.getKind() == NeeoDeviceChannelKind.TRIGGER) {
|
||||
final String path = compPath + "/button/trigger";
|
||||
capabilities.add(createBase(name, channel.getLabel(), capabilityType.toString(), path));
|
||||
} else {
|
||||
final String value = channel.getValue();
|
||||
final String path = compPath + "/button/" + (value == null || StringUtils.isEmpty(value) ? "on"
|
||||
: NeeoUtil.encodeURIComponent(value.trim()));
|
||||
final String path = compPath + "/button/"
|
||||
+ (value == null || value.isEmpty() ? "on" : NeeoUtil.encodeURIComponent(value.trim()));
|
||||
capabilities.add(createBase(name, channel.getLabel(), capabilityType.toString(), path));
|
||||
}
|
||||
} else if (capabilityType == NeeoCapabilityType.SENSOR_POWER) {
|
||||
@@ -187,8 +186,7 @@ public class NeeoBrainDeviceSerializer implements JsonSerializer<NeeoDevice> {
|
||||
}
|
||||
} else if (capabilityType == NeeoCapabilityType.IMAGEURL) {
|
||||
final String value = channel.getValue();
|
||||
final String size = (value == null || StringUtils.isEmpty(value) ? "large" : value.trim())
|
||||
.toLowerCase();
|
||||
final String size = (value == null || value.isEmpty() ? "large" : value.trim()).toLowerCase();
|
||||
|
||||
final JsonObject jo = createBase(uniqueItemName, channel.getLabel(), capabilityType.toString(),
|
||||
compPath + "/image/actor", "sensor", new JsonPrimitive(sensorItemName));
|
||||
@@ -277,7 +275,7 @@ public class NeeoBrainDeviceSerializer implements JsonSerializer<NeeoDevice> {
|
||||
compObj.addProperty("type", type);
|
||||
|
||||
compObj.addProperty("path", NeeoUtil.encodeURIComponent(path));
|
||||
if (sensor != null && StringUtils.isNotEmpty(sensorName)) {
|
||||
if (sensor != null && sensorName != null && !sensorName.isEmpty()) {
|
||||
if (sensor instanceof JsonPrimitive) {
|
||||
compObj.addProperty(sensorName, sensor.getAsString());
|
||||
} else {
|
||||
|
||||
@@ -16,7 +16,6 @@ import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.items.Item;
|
||||
@@ -99,12 +98,13 @@ public class NeeoDeviceChannelSerializer
|
||||
final Item item = localContext.getItemRegistry().getItem(chnl.getItemName());
|
||||
itemType = item.getType();
|
||||
|
||||
if (StringUtils.isNotEmpty(item.getLabel())) {
|
||||
itemLabel = item.getLabel();
|
||||
String label = item.getLabel();
|
||||
if (label != null && !label.isEmpty()) {
|
||||
itemLabel = label;
|
||||
}
|
||||
|
||||
for (Class<? extends Command> cmd : item.getAcceptedCommandTypes()) {
|
||||
if (!StringUtils.equalsIgnoreCase(cmd.getSimpleName(), "refreshtype")) {
|
||||
if (!cmd.getSimpleName().equalsIgnoreCase("refreshtype")) {
|
||||
commandTypes.add(cmd.getSimpleName().toLowerCase());
|
||||
}
|
||||
}
|
||||
@@ -127,7 +127,7 @@ public class NeeoDeviceChannelSerializer
|
||||
itemType = "N/A";
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(itemLabel)) {
|
||||
if (!itemLabel.isEmpty()) {
|
||||
switch (chnl.getSubType()) {
|
||||
case HUE:
|
||||
itemType += " (Hue)";
|
||||
@@ -172,7 +172,7 @@ public class NeeoDeviceChannelSerializer
|
||||
final JsonObject jo = (JsonObject) elm;
|
||||
final String itemName = NeeoUtil.getString(jo, "itemName");
|
||||
|
||||
if (itemName == null || StringUtils.isEmpty(itemName)) {
|
||||
if (itemName == null || itemName.isEmpty()) {
|
||||
throw new JsonParseException("Element requires an itemName attribute: " + elm);
|
||||
}
|
||||
|
||||
@@ -201,19 +201,17 @@ public class NeeoDeviceChannelSerializer
|
||||
final boolean labelVisible = jo.has("labelVisible") ? jo.get("labelVisible").getAsBoolean() : true;
|
||||
|
||||
return new NeeoDeviceChannelText(kind, itemName, channelNbr, capType, itemSubType,
|
||||
label == null || StringUtils.isEmpty(label) ? NeeoUtil.NOTAVAILABLE : label, value, range,
|
||||
labelVisible);
|
||||
label == null || label.isEmpty() ? NeeoUtil.NOTAVAILABLE : label, value, range, labelVisible);
|
||||
} else if (capType == NeeoCapabilityType.DIRECTORY) {
|
||||
final NeeoDeviceChannelDirectoryListItem[] listItems = jo.has("listItems")
|
||||
? context.deserialize(jo.get("listItems"), NeeoDeviceChannelDirectoryListItem[].class)
|
||||
: new NeeoDeviceChannelDirectoryListItem[0];
|
||||
|
||||
return new NeeoDeviceChannelDirectory(kind, itemName, channelNbr, capType, itemSubType,
|
||||
label == null || StringUtils.isEmpty(label) ? NeeoUtil.NOTAVAILABLE : label, value, range,
|
||||
listItems);
|
||||
label == null || label.isEmpty() ? NeeoUtil.NOTAVAILABLE : label, value, range, listItems);
|
||||
} else {
|
||||
return new NeeoDeviceChannel(kind, itemName, channelNbr, capType, itemSubType,
|
||||
label == null || StringUtils.isEmpty(label) ? NeeoUtil.NOTAVAILABLE : label, value, range);
|
||||
label == null || label.isEmpty() ? NeeoUtil.NOTAVAILABLE : label, value, range);
|
||||
}
|
||||
} catch (NullPointerException | IllegalArgumentException e) {
|
||||
throw new JsonParseException(e);
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.Objects;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.io.neeo.NeeoService;
|
||||
import org.openhab.io.neeo.internal.NeeoBrainServlet;
|
||||
@@ -69,11 +68,9 @@ public class BrainDashboardService extends DefaultServletService {
|
||||
*/
|
||||
@Override
|
||||
public boolean canHandleRoute(String[] paths) {
|
||||
return paths.length >= 1 && (StringUtils.equalsIgnoreCase(paths[0], "brainstatus")
|
||||
|| StringUtils.equalsIgnoreCase(paths[0], "addbrain")
|
||||
|| StringUtils.equalsIgnoreCase(paths[0], "removebrain")
|
||||
|| StringUtils.equalsIgnoreCase(paths[0], "getlog")
|
||||
|| StringUtils.equalsIgnoreCase(paths[0], "blinkled"));
|
||||
return paths.length >= 1 && (paths[0].equalsIgnoreCase("brainstatus") || paths[0].equalsIgnoreCase("addbrain")
|
||||
|| paths[0].equalsIgnoreCase("removebrain") || paths[0].equalsIgnoreCase("getlog")
|
||||
|| paths[0].equalsIgnoreCase("blinkled"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,13 +85,13 @@ public class BrainDashboardService extends DefaultServletService {
|
||||
Objects.requireNonNull(resp, "resp cannot be null");
|
||||
|
||||
try {
|
||||
if (StringUtils.equalsIgnoreCase(paths[0], "brainstatus")) {
|
||||
if (paths[0].equalsIgnoreCase("brainstatus")) {
|
||||
final List<BrainStatus> status = new ArrayList<>();
|
||||
for (NeeoBrainServlet servlet : service.getServlets()) {
|
||||
status.add(servlet.getBrainStatus());
|
||||
}
|
||||
NeeoUtil.write(resp, gson.toJson(status));
|
||||
} else if (StringUtils.equalsIgnoreCase(paths[0], "blinkled")) {
|
||||
} else if (paths[0].equalsIgnoreCase("blinkled")) {
|
||||
final String brainId = req.getParameter("brainid");
|
||||
if (brainId == null) {
|
||||
NeeoUtil.write(resp, gson.toJson(new ReturnStatus("BrainID is null")));
|
||||
@@ -112,7 +109,7 @@ public class BrainDashboardService extends DefaultServletService {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (StringUtils.equalsIgnoreCase(paths[0], "getlog")) {
|
||||
} else if (paths[0].equalsIgnoreCase("getlog")) {
|
||||
final String brainId = req.getParameter("brainid");
|
||||
if (brainId == null) {
|
||||
NeeoUtil.write(resp, gson.toJson(new ReturnStatus("BrainID is null")));
|
||||
@@ -131,7 +128,7 @@ public class BrainDashboardService extends DefaultServletService {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.debug("Unknown get path: {}", StringUtils.join(paths, ','));
|
||||
logger.debug("Unknown get path: {}", String.join(",", paths));
|
||||
}
|
||||
} catch (JsonParseException | IllegalArgumentException | NullPointerException e) {
|
||||
logger.debug("Exception handling get: {}", e.getMessage(), e);
|
||||
@@ -154,7 +151,7 @@ public class BrainDashboardService extends DefaultServletService {
|
||||
}
|
||||
|
||||
try {
|
||||
if (StringUtils.equalsIgnoreCase(paths[0], "removebrain")) {
|
||||
if (paths[0].equalsIgnoreCase("removebrain")) {
|
||||
final BrainInfo info = gson.fromJson(req.getReader(), BrainInfo.class);
|
||||
final String brainId = info.getBrainId();
|
||||
if (brainId == null) {
|
||||
@@ -165,7 +162,7 @@ public class BrainDashboardService extends DefaultServletService {
|
||||
NeeoUtil.write(resp,
|
||||
gson.toJson(new ReturnStatus("BrainID (" + brainId + ") could not be removed")));
|
||||
}
|
||||
} else if (StringUtils.equalsIgnoreCase(paths[0], "addbrain")) {
|
||||
} else if (paths[0].equalsIgnoreCase("addbrain")) {
|
||||
final BrainInfo info = gson.fromJson(req.getReader(), BrainInfo.class);
|
||||
final String brainIp = info.getBrainIp();
|
||||
if (brainIp == null) {
|
||||
@@ -177,7 +174,7 @@ public class BrainDashboardService extends DefaultServletService {
|
||||
"Brain (" + brainIp + ") could not be added - no brain at that IP Address")));
|
||||
}
|
||||
} else {
|
||||
logger.debug("Unknown get path: {}", StringUtils.join(paths, ','));
|
||||
logger.debug("Unknown get path: {}", String.join(",", paths));
|
||||
}
|
||||
} catch (JsonParseException | IllegalArgumentException | NullPointerException e) {
|
||||
logger.debug("Exception handling get: {}", e.getMessage(), e);
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.io.neeo.internal.NeeoConstants;
|
||||
import org.openhab.io.neeo.internal.NeeoUtil;
|
||||
@@ -60,7 +59,7 @@ public class NeeoBrainSearchService extends DefaultServletService {
|
||||
private final ServiceContext context;
|
||||
|
||||
/** The last search results */
|
||||
private final ConcurrentHashMap<Integer, NeeoThingUID> lastSearchResults = new ConcurrentHashMap<>();
|
||||
private final Map<Integer, NeeoThingUID> lastSearchResults = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Constructs the service from the given {@link ServiceContext}.
|
||||
@@ -85,7 +84,7 @@ public class NeeoBrainSearchService extends DefaultServletService {
|
||||
*/
|
||||
@Override
|
||||
public boolean canHandleRoute(String[] paths) {
|
||||
return paths.length >= 1 && StringUtils.equalsIgnoreCase(paths[0], "db");
|
||||
return paths.length >= 1 && paths[0].equalsIgnoreCase("db");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,17 +102,17 @@ public class NeeoBrainSearchService extends DefaultServletService {
|
||||
Objects.requireNonNull(paths, "paths cannot be null");
|
||||
Objects.requireNonNull(resp, "resp cannot be null");
|
||||
if (paths.length < 2) {
|
||||
throw new IllegalArgumentException("paths must have atleast 2 elements: " + StringUtils.join(paths));
|
||||
throw new IllegalArgumentException("paths must have atleast 2 elements: " + String.join("", paths));
|
||||
}
|
||||
|
||||
final String path = StringUtils.lowerCase(paths[1]);
|
||||
final String path = paths[1].toLowerCase();
|
||||
|
||||
if (StringUtils.equalsIgnoreCase(path, "search")) {
|
||||
if (path.equalsIgnoreCase("search")) {
|
||||
String queryString = req.getQueryString();
|
||||
if (queryString != null) {
|
||||
doSearch(queryString, resp);
|
||||
}
|
||||
} else if (StringUtils.equalsIgnoreCase(path, "adapterdefinition") && paths.length >= 3) {
|
||||
} else if (path.equalsIgnoreCase("adapterdefinition") && paths.length >= 3) {
|
||||
doAdapterDefinition(paths[2], resp);
|
||||
} else {
|
||||
doQuery(path, resp);
|
||||
@@ -131,7 +130,7 @@ public class NeeoBrainSearchService extends DefaultServletService {
|
||||
Objects.requireNonNull(queryString, "queryString cannot be null");
|
||||
Objects.requireNonNull(resp, "resp cannot be null");
|
||||
|
||||
final int idx = StringUtils.indexOf(queryString, '=');
|
||||
final int idx = queryString.indexOf("=");
|
||||
|
||||
if (idx >= 0 && idx + 1 < queryString.length()) {
|
||||
final String search = NeeoUtil.decodeURIComponent(queryString.substring(idx + 1));
|
||||
|
||||
@@ -23,7 +23,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
@@ -142,13 +141,12 @@ public class NeeoBrainService extends DefaultServletService {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (StringUtils.equalsIgnoreCase(paths[0], "device")) {
|
||||
if (paths[0].equalsIgnoreCase("device")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final String lastPath = paths.length >= 2 ? paths[1] : null;
|
||||
return StringUtils.equalsIgnoreCase(lastPath, "subscribe")
|
||||
|| StringUtils.equalsIgnoreCase(lastPath, "unsubscribe");
|
||||
return "subscribe".equalsIgnoreCase(lastPath) || "unsubscribe".equalsIgnoreCase(lastPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -160,19 +158,19 @@ public class NeeoBrainService extends DefaultServletService {
|
||||
throw new IllegalArgumentException("paths cannot be empty");
|
||||
}
|
||||
|
||||
final boolean hasDeviceStart = StringUtils.equalsIgnoreCase(paths[0], "device");
|
||||
final boolean hasDeviceStart = paths[0].equalsIgnoreCase("device");
|
||||
|
||||
if (hasDeviceStart) {
|
||||
final PathInfo pathInfo = new PathInfo(paths);
|
||||
|
||||
if (StringUtils.equalsIgnoreCase("directory", pathInfo.getComponentType())) {
|
||||
if ("directory".equalsIgnoreCase(pathInfo.getComponentType())) {
|
||||
handleDirectory(req, resp, pathInfo);
|
||||
} else {
|
||||
logger.debug("Unknown/unhandled brain service device route (POST): {}", StringUtils.join(paths, '/'));
|
||||
logger.debug("Unknown/unhandled brain service device route (POST): {}", String.join("/", paths));
|
||||
|
||||
}
|
||||
} else {
|
||||
logger.debug("Unknown/unhandled brain service route (POST): {}", StringUtils.join(paths, '/'));
|
||||
logger.debug("Unknown/unhandled brain service route (POST): {}", String.join("/", paths));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,26 +190,27 @@ public class NeeoBrainService extends DefaultServletService {
|
||||
// 4. Old subscribe path: /{thingUID}/subscribe or unsubscribe/{deviceid}/{devicekey}
|
||||
// 4. Old unsubscribe path: /{thingUID}/subscribe or unsubscribe/{deviceid}
|
||||
|
||||
final boolean hasDeviceStart = StringUtils.equalsIgnoreCase(paths[0], "device");
|
||||
if (hasDeviceStart && (paths.length >= 3 && !StringUtils.equalsIgnoreCase(paths[2], "subscribe")
|
||||
&& !StringUtils.equalsIgnoreCase(paths[2], "unsubscribe"))) {
|
||||
final boolean hasDeviceStart = paths[0].equalsIgnoreCase("device");
|
||||
if (hasDeviceStart && (paths.length >= 3 && !paths[2].equalsIgnoreCase("subscribe")
|
||||
&& !paths[2].equalsIgnoreCase("unsubscribe"))) {
|
||||
try {
|
||||
final PathInfo pathInfo = new PathInfo(paths);
|
||||
|
||||
if (StringUtils.isEmpty(pathInfo.getActionValue())) {
|
||||
String actionValue = pathInfo.getActionValue();
|
||||
if (actionValue == null || actionValue.isEmpty()) {
|
||||
handleGetValue(resp, pathInfo);
|
||||
} else {
|
||||
handleSetValue(resp, pathInfo);
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.debug("Bad path: {} - {}", StringUtils.join(paths), e.getMessage(), e);
|
||||
logger.debug("Bad path: {} - {}", String.join("", paths), e.getMessage(), e);
|
||||
}
|
||||
} else {
|
||||
int idx = hasDeviceStart ? 1 : 0;
|
||||
|
||||
if (idx + 2 < paths.length) {
|
||||
final String adapterName = paths[idx++];
|
||||
final String action = StringUtils.lowerCase(paths[idx++]);
|
||||
final String action = paths[idx++].toLowerCase();
|
||||
idx++; // deviceId/default - not used
|
||||
|
||||
switch (action) {
|
||||
@@ -220,7 +219,7 @@ public class NeeoBrainService extends DefaultServletService {
|
||||
final String deviceKey = paths[idx++];
|
||||
handleSubscribe(resp, adapterName, deviceKey);
|
||||
} else {
|
||||
logger.debug("No device key set for a subscribe action: {}", StringUtils.join(paths, '/'));
|
||||
logger.debug("No device key set for a subscribe action: {}", String.join("/", paths));
|
||||
}
|
||||
break;
|
||||
case "unsubscribe":
|
||||
@@ -231,7 +230,7 @@ public class NeeoBrainService extends DefaultServletService {
|
||||
}
|
||||
|
||||
} else {
|
||||
logger.debug("Unknown/unhandled brain service route (GET): {}", StringUtils.join(paths, '/'));
|
||||
logger.debug("Unknown/unhandled brain service route (GET): {}", String.join("/", paths));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -384,7 +383,7 @@ public class NeeoBrainService extends DefaultServletService {
|
||||
if (device != null) {
|
||||
final NeeoDeviceChannel channel = device.getChannel(pathInfo.getItemName(), pathInfo.getSubType(),
|
||||
pathInfo.getChannelNbr());
|
||||
if (StringUtils.equalsIgnoreCase("action", pathInfo.getActionValue())) {
|
||||
if ("action".equalsIgnoreCase(pathInfo.getActionValue())) {
|
||||
final NeeoDirectoryRequestAction discoveryAction = gson.fromJson(req.getReader(),
|
||||
NeeoDirectoryRequestAction.class);
|
||||
|
||||
@@ -515,13 +514,11 @@ public class NeeoBrainService extends DefaultServletService {
|
||||
if (state instanceof OnOffType) {
|
||||
Boolean recipeState = null;
|
||||
final String label = channel.getLabel();
|
||||
if (StringUtils.equalsIgnoreCase(NeeoButtonGroup.POWERONOFF.getText(), label)) {
|
||||
if (NeeoButtonGroup.POWERONOFF.getText().equalsIgnoreCase(label)) {
|
||||
recipeState = state == OnOffType.ON;
|
||||
} else if (state == OnOffType.ON
|
||||
&& StringUtils.equalsIgnoreCase(ButtonInfo.POWERON.getLabel(), label)) {
|
||||
} else if (state == OnOffType.ON && ButtonInfo.POWERON.getLabel().equalsIgnoreCase(label)) {
|
||||
recipeState = true;
|
||||
} else if (state == OnOffType.OFF
|
||||
&& StringUtils.equalsIgnoreCase(ButtonInfo.POWEROFF.getLabel(), label)) {
|
||||
} else if (state == OnOffType.OFF && ButtonInfo.POWEROFF.getLabel().equalsIgnoreCase(label)) {
|
||||
recipeState = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.thing.ChannelUID;
|
||||
import org.openhab.io.neeo.NeeoService;
|
||||
@@ -84,14 +83,14 @@ public class ThingDashboardService extends DefaultServletService {
|
||||
*/
|
||||
@Override
|
||||
public boolean canHandleRoute(String[] paths) {
|
||||
return paths.length >= 1 && (StringUtils.equalsIgnoreCase(paths[0], "thingstatus")
|
||||
|| StringUtils.equalsIgnoreCase(paths[0], "getchannel")
|
||||
|| StringUtils.equalsIgnoreCase(paths[0], "getvirtualdevice")
|
||||
|| StringUtils.equalsIgnoreCase(paths[0], "restoredevice")
|
||||
|| StringUtils.equalsIgnoreCase(paths[0], "refreshdevice")
|
||||
|| StringUtils.equalsIgnoreCase(paths[0], "deletedevice")
|
||||
|| StringUtils.equalsIgnoreCase(paths[0], "exportrules")
|
||||
|| StringUtils.equalsIgnoreCase(paths[0], "updatedevice"));
|
||||
return paths.length >= 1 && (paths[0].equalsIgnoreCase("thingstatus") //
|
||||
|| paths[0].equalsIgnoreCase("getchannel") //
|
||||
|| paths[0].equalsIgnoreCase("getvirtualdevice") //
|
||||
|| paths[0].equalsIgnoreCase("restoredevice") //
|
||||
|| paths[0].equalsIgnoreCase("refreshdevice") //
|
||||
|| paths[0].equalsIgnoreCase("deletedevice") //
|
||||
|| paths[0].equalsIgnoreCase("exportrules") //
|
||||
|| paths[0].equalsIgnoreCase("updatedevice"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,10 +105,10 @@ public class ThingDashboardService extends DefaultServletService {
|
||||
Objects.requireNonNull(resp, "resp cannot be null");
|
||||
|
||||
try {
|
||||
if (StringUtils.equalsIgnoreCase(paths[0], "thingstatus")) {
|
||||
if (paths[0].equalsIgnoreCase("thingstatus")) {
|
||||
final List<NeeoDevice> devices = context.getDefinitions().getAllDevices();
|
||||
NeeoUtil.write(resp, gson.toJson(devices));
|
||||
} else if (StringUtils.equalsIgnoreCase(paths[0], "getchannel")) {
|
||||
} else if (paths[0].equalsIgnoreCase("getchannel")) {
|
||||
final String itemName = NeeoUtil.decodeURIComponent(req.getParameter("itemname"));
|
||||
final List<NeeoDeviceChannel> channels = context.getDefinitions().getNeeoDeviceChannel(itemName);
|
||||
if (channels == null) {
|
||||
@@ -117,13 +116,13 @@ public class ThingDashboardService extends DefaultServletService {
|
||||
} else {
|
||||
NeeoUtil.write(resp, gson.toJson(new ReturnStatus(channels)));
|
||||
}
|
||||
} else if (StringUtils.equalsIgnoreCase(paths[0], "getvirtualdevice")) {
|
||||
} else if (paths[0].equalsIgnoreCase("getvirtualdevice")) {
|
||||
final NeeoThingUID uid = context.generate(NeeoConstants.VIRTUAL_THING_TYPE);
|
||||
final NeeoDevice device = new NeeoDevice(uid, 0, NeeoDeviceType.EXCLUDE, "NEEO Integration",
|
||||
"New Virtual Thing", new ArrayList<>(), null, null, null, null);
|
||||
NeeoUtil.write(resp, gson.toJson(new ReturnStatus(device)));
|
||||
} else {
|
||||
logger.debug("Unknown get path: {}", StringUtils.join(paths, ','));
|
||||
logger.debug("Unknown get path: {}", String.join(",", paths));
|
||||
}
|
||||
} catch (JsonParseException | IllegalArgumentException | NullPointerException e) {
|
||||
logger.debug("Exception handling get: {}", e.getMessage(), e);
|
||||
@@ -146,7 +145,7 @@ public class ThingDashboardService extends DefaultServletService {
|
||||
}
|
||||
|
||||
try {
|
||||
if (StringUtils.equalsIgnoreCase(paths[0], "updatedevice")) {
|
||||
if (paths[0].equalsIgnoreCase("updatedevice")) {
|
||||
final NeeoDevice device = gson.fromJson(req.getReader(), NeeoDevice.class);
|
||||
context.getDefinitions().put(device);
|
||||
|
||||
@@ -155,7 +154,7 @@ public class ThingDashboardService extends DefaultServletService {
|
||||
}
|
||||
|
||||
NeeoUtil.write(resp, gson.toJson(ReturnStatus.SUCCESS));
|
||||
} else if (StringUtils.equalsIgnoreCase(paths[0], "restoredevice")) {
|
||||
} else if (paths[0].equalsIgnoreCase("restoredevice")) {
|
||||
final NeeoThingUID uid = new NeeoThingUID(IOUtils.toString(req.getReader()));
|
||||
context.getDefinitions().remove(uid);
|
||||
final NeeoDevice device = context.getDefinitions().getDevice(uid);
|
||||
@@ -164,7 +163,7 @@ public class ThingDashboardService extends DefaultServletService {
|
||||
} else {
|
||||
NeeoUtil.write(resp, gson.toJson(new ReturnStatus(device)));
|
||||
}
|
||||
} else if (StringUtils.equalsIgnoreCase(paths[0], "refreshdevice")) {
|
||||
} else if (paths[0].equalsIgnoreCase("refreshdevice")) {
|
||||
final NeeoThingUID uid = new NeeoThingUID(IOUtils.toString(req.getReader()));
|
||||
final NeeoDevice device = context.getDefinitions().getDevice(uid);
|
||||
if (device == null) {
|
||||
@@ -172,12 +171,12 @@ public class ThingDashboardService extends DefaultServletService {
|
||||
} else {
|
||||
NeeoUtil.write(resp, gson.toJson(new ReturnStatus(device)));
|
||||
}
|
||||
} else if (StringUtils.equalsIgnoreCase(paths[0], "deletedevice")) {
|
||||
} else if (paths[0].equalsIgnoreCase("deletedevice")) {
|
||||
final NeeoThingUID uid = new NeeoThingUID(IOUtils.toString(req.getReader()));
|
||||
final boolean deleted = context.getDefinitions().remove(uid);
|
||||
NeeoUtil.write(resp, gson.toJson(new ReturnStatus(
|
||||
deleted ? null : "Device " + uid + " was not found (possibly already deleted?)")));
|
||||
} else if (StringUtils.equalsIgnoreCase(paths[0], "exportrules")) {
|
||||
} else if (paths[0].equalsIgnoreCase("exportrules")) {
|
||||
final NeeoThingUID uid = new NeeoThingUID(IOUtils.toString(req.getReader()));
|
||||
final NeeoDevice device = context.getDefinitions().getDevice(uid);
|
||||
if (device == null) {
|
||||
@@ -186,7 +185,7 @@ public class ThingDashboardService extends DefaultServletService {
|
||||
writeExampleRules(resp, device);
|
||||
}
|
||||
} else {
|
||||
logger.debug("Unknown post path: {}", StringUtils.join(paths, ','));
|
||||
logger.debug("Unknown post path: {}", String.join(",", paths));
|
||||
}
|
||||
} catch (JsonParseException | IllegalArgumentException | NullPointerException e) {
|
||||
logger.debug("Exception handling post: {}", e.getMessage(), e);
|
||||
|
||||
@@ -14,7 +14,6 @@ package org.openhab.io.neeo.internal.servletservices.models;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.io.neeo.internal.models.ItemSubType;
|
||||
@@ -47,8 +46,7 @@ public class PathInfo {
|
||||
private final String componentSubType;
|
||||
|
||||
/** The action value */
|
||||
@Nullable
|
||||
private final String actionValue;
|
||||
private final @Nullable String actionValue;
|
||||
|
||||
/**
|
||||
* Creates the path info object from the route path
|
||||
@@ -89,7 +87,7 @@ public class PathInfo {
|
||||
componentType = paths[idx++];
|
||||
|
||||
// actor/sensor/buttoncmd
|
||||
if (StringUtils.equalsIgnoreCase("button", componentType)) {
|
||||
if ("button".equalsIgnoreCase(componentType)) {
|
||||
componentSubType = "actor";
|
||||
actionValue = paths[idx++];
|
||||
} else {
|
||||
|
||||
@@ -14,7 +14,6 @@ package org.openhab.io.neeo.internal.servletservices.models;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.io.neeo.internal.models.NeeoDevice;
|
||||
@@ -36,16 +35,13 @@ public class ReturnStatus {
|
||||
private final boolean success;
|
||||
|
||||
/** The optional message if not successful */
|
||||
@Nullable
|
||||
private final String message;
|
||||
private final @Nullable String message;
|
||||
|
||||
/** The optional device if successful */
|
||||
@Nullable
|
||||
private final NeeoDevice device;
|
||||
private final @Nullable NeeoDevice device;
|
||||
|
||||
/** The optional channel if successful */
|
||||
@Nullable
|
||||
private final List<NeeoDeviceChannel> channels;
|
||||
private final @Nullable List<NeeoDeviceChannel> channels;
|
||||
|
||||
/**
|
||||
* Creates a return status of true or not (with no message or device)
|
||||
@@ -81,7 +77,7 @@ public class ReturnStatus {
|
||||
* @param message the possibly null, possibly empty message
|
||||
*/
|
||||
public ReturnStatus(@Nullable String message) {
|
||||
this(StringUtils.isEmpty(message), message, null, null);
|
||||
this(message == null || message.isEmpty(), message, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,8 +120,7 @@ public class ReturnStatus {
|
||||
*
|
||||
* @return the possibly empty, possibly null message
|
||||
*/
|
||||
@Nullable
|
||||
public String getMessage() {
|
||||
public @Nullable String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@@ -134,8 +129,7 @@ public class ReturnStatus {
|
||||
*
|
||||
* @return the possibly null device
|
||||
*/
|
||||
@Nullable
|
||||
public NeeoDevice getDevice() {
|
||||
public @Nullable NeeoDevice getDevice() {
|
||||
return device;
|
||||
}
|
||||
|
||||
@@ -144,8 +138,7 @@ public class ReturnStatus {
|
||||
*
|
||||
* @return the possibly null channel
|
||||
*/
|
||||
@Nullable
|
||||
public List<NeeoDeviceChannel> getChannels() {
|
||||
public @Nullable List<NeeoDeviceChannel> getChannels() {
|
||||
return channels;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user