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:
@@ -12,7 +12,6 @@
|
||||
*/
|
||||
package org.openhab.binding.unifi.internal;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.openhab.binding.unifi.internal.handler.UniFiClientThingHandler;
|
||||
|
||||
/**
|
||||
@@ -42,13 +41,13 @@ public class UniFiClientThingConfig {
|
||||
}
|
||||
|
||||
public UniFiClientThingConfig tidy() {
|
||||
cid = StringUtils.lowerCase(StringUtils.strip(cid));
|
||||
site = StringUtils.lowerCase(StringUtils.strip(site));
|
||||
cid = cid.trim().toLowerCase();
|
||||
site = site.trim().toLowerCase();
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return StringUtils.isNotBlank(cid);
|
||||
return !cid.isBlank();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
*/
|
||||
package org.openhab.binding.unifi.internal;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.openhab.binding.unifi.internal.handler.UniFiControllerThingHandler;
|
||||
|
||||
/**
|
||||
@@ -60,7 +59,7 @@ public class UniFiControllerThingConfig {
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return StringUtils.isNotBlank(host) && StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password);
|
||||
return !host.isBlank() && !username.isBlank() && !password.isBlank();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,7 +17,6 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -77,7 +76,7 @@ public abstract class UniFiCache<T> {
|
||||
public final void put(T value) {
|
||||
for (String prefix : prefixes) {
|
||||
String suffix = getSuffix(value, prefix);
|
||||
if (StringUtils.isNotBlank(suffix)) {
|
||||
if (suffix != null && !suffix.isBlank()) {
|
||||
String key = prefix + SEPARATOR + suffix;
|
||||
map.put(key, value);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ package org.openhab.binding.unifi.internal.api.model;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
import org.apache.commons.lang.BooleanUtils;
|
||||
import org.openhab.binding.unifi.internal.api.UniFiException;
|
||||
import org.openhab.binding.unifi.internal.api.util.UniFiTidyLowerCaseStringDeserializer;
|
||||
import org.openhab.binding.unifi.internal.api.util.UniFiTimestampDeserializer;
|
||||
@@ -95,7 +94,7 @@ public abstract class UniFiClient {
|
||||
public abstract Boolean isWired();
|
||||
|
||||
public final Boolean isWireless() {
|
||||
return BooleanUtils.negate(isWired());
|
||||
return isWired() == null ? null : (isWired().booleanValue() ? Boolean.FALSE : Boolean.TRUE);
|
||||
}
|
||||
|
||||
protected abstract String getDeviceMac();
|
||||
|
||||
@@ -14,7 +14,6 @@ package org.openhab.binding.unifi.internal.api.model;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
@@ -135,7 +134,7 @@ public class UniFiController {
|
||||
|
||||
public @Nullable UniFiSite getSite(@Nullable String id) {
|
||||
UniFiSite site = null;
|
||||
if (StringUtils.isNotBlank(id)) {
|
||||
if (id != null && !id.isBlank()) {
|
||||
synchronized (this) {
|
||||
site = sitesCache.get(id);
|
||||
}
|
||||
@@ -150,7 +149,7 @@ public class UniFiController {
|
||||
|
||||
public @Nullable UniFiDevice getDevice(@Nullable String id) {
|
||||
UniFiDevice device = null;
|
||||
if (StringUtils.isNotBlank(id)) {
|
||||
if (id != null && !id.isBlank()) {
|
||||
synchronized (this) {
|
||||
device = devicesCache.get(id);
|
||||
}
|
||||
@@ -165,7 +164,7 @@ public class UniFiController {
|
||||
|
||||
public @Nullable UniFiClient getClient(@Nullable String id) {
|
||||
UniFiClient client = null;
|
||||
if (StringUtils.isNotBlank(id)) {
|
||||
if (id != null && !id.isBlank()) {
|
||||
synchronized (this) {
|
||||
// mgb: first check active clients and fallback to insights if not found
|
||||
client = clientsCache.get(id);
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
*/
|
||||
package org.openhab.binding.unifi.internal.api.model;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.openhab.binding.unifi.internal.api.util.UniFiTidyLowerCaseStringDeserializer;
|
||||
|
||||
import com.google.gson.annotations.JsonAdapter;
|
||||
@@ -53,7 +52,7 @@ public class UniFiDevice {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return StringUtils.defaultIfBlank(name, mac);
|
||||
return name == null || name.isBlank() ? mac : name;
|
||||
}
|
||||
|
||||
public String getMac() {
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
*/
|
||||
package org.openhab.binding.unifi.internal.api.model;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
@@ -49,8 +47,7 @@ public class UniFiSite {
|
||||
}
|
||||
|
||||
public boolean matchesName(String siteName) {
|
||||
return StringUtils.equalsIgnoreCase(desc, siteName) || StringUtils.equalsIgnoreCase(name, siteName)
|
||||
|| StringUtils.equalsIgnoreCase(id, siteName);
|
||||
return siteName.equalsIgnoreCase(desc) || siteName.equalsIgnoreCase(name) || siteName.equalsIgnoreCase(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,8 +14,6 @@ package org.openhab.binding.unifi.internal.api.util;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -34,6 +32,6 @@ public class UniFiTidyLowerCaseStringDeserializer implements JsonDeserializer<St
|
||||
public String deserialize(JsonElement json, Type type, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
String s = json.getAsJsonPrimitive().getAsString();
|
||||
return StringUtils.lowerCase(StringUtils.strip(s));
|
||||
return s.trim().toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Calendar;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.unifi.internal.UniFiBindingConstants;
|
||||
@@ -84,7 +83,7 @@ public class UniFiClientThingHandler extends UniFiBaseThingHandler<UniFiClient,
|
||||
|
||||
private static boolean belongsToSite(UniFiClient client, String siteName) {
|
||||
boolean result = true; // mgb: assume true = proof by contradiction
|
||||
if (StringUtils.isNotEmpty(siteName)) {
|
||||
if (!siteName.isEmpty()) {
|
||||
UniFiSite site = client.getSite();
|
||||
// mgb: if the 'site' can't be found or the name doesn't match...
|
||||
if (site == null || !site.matchesName(siteName)) {
|
||||
@@ -166,21 +165,21 @@ public class UniFiClientThingHandler extends UniFiBaseThingHandler<UniFiClient,
|
||||
|
||||
// :site
|
||||
case CHANNEL_SITE:
|
||||
if (clientHome && site != null && StringUtils.isNotBlank(site.getDescription())) {
|
||||
if (clientHome && site != null && site.getDescription() != null && !site.getDescription().isBlank()) {
|
||||
state = StringType.valueOf(site.getDescription());
|
||||
}
|
||||
break;
|
||||
|
||||
// :macAddress
|
||||
case CHANNEL_MAC_ADDRESS:
|
||||
if (clientHome && StringUtils.isNotBlank(client.getMac())) {
|
||||
if (clientHome && client.getMac() != null && !client.getMac().isBlank()) {
|
||||
state = StringType.valueOf(client.getMac());
|
||||
}
|
||||
break;
|
||||
|
||||
// :ipAddress
|
||||
case CHANNEL_IP_ADDRESS:
|
||||
if (clientHome && StringUtils.isNotBlank(client.getIp())) {
|
||||
if (clientHome && client.getIp() != null && !client.getIp().isBlank()) {
|
||||
state = StringType.valueOf(client.getIp());
|
||||
}
|
||||
break;
|
||||
@@ -235,14 +234,14 @@ public class UniFiClientThingHandler extends UniFiBaseThingHandler<UniFiClient,
|
||||
// :ap
|
||||
case CHANNEL_AP:
|
||||
UniFiDevice device = client.getDevice();
|
||||
if (clientHome && device != null && StringUtils.isNotBlank(device.getName())) {
|
||||
if (clientHome && device != null && device.getName() != null && !device.getName().isBlank()) {
|
||||
state = StringType.valueOf(device.getName());
|
||||
}
|
||||
break;
|
||||
|
||||
// :essid
|
||||
case CHANNEL_ESSID:
|
||||
if (clientHome && StringUtils.isNotBlank(client.getEssid())) {
|
||||
if (clientHome && client.getEssid() != null && !client.getEssid().isBlank()) {
|
||||
state = StringType.valueOf(client.getEssid());
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user