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:
Wouter Born
2021-03-16 12:38:16 +01:00
committed by GitHub
parent 16fba31556
commit f3503430b4
257 changed files with 906 additions and 1125 deletions

View File

@@ -17,7 +17,6 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.jupnp.model.meta.RemoteDevice;
import org.openhab.binding.pioneeravr.internal.PioneerAvrBindingConstants;
import org.openhab.core.config.discovery.DiscoveryResult;
@@ -58,7 +57,7 @@ public class PioneerAvrDiscoveryParticipant implements UpnpDiscoveryParticipant
protected void activate(ComponentContext componentContext) {
if (componentContext.getProperties() != null) {
String autoDiscoveryPropertyValue = (String) componentContext.getProperties().get("enableAutoDiscovery");
if (StringUtils.isNotEmpty(autoDiscoveryPropertyValue)) {
if (autoDiscoveryPropertyValue != null && !autoDiscoveryPropertyValue.isEmpty()) {
isAutoDiscoveryEnabled = Boolean.valueOf(autoDiscoveryPropertyValue);
}
}
@@ -76,8 +75,8 @@ public class PioneerAvrDiscoveryParticipant implements UpnpDiscoveryParticipant
DiscoveryResult result = null;
ThingUID thingUid = getThingUID(device);
if (thingUid != null) {
String label = StringUtils.isEmpty(device.getDetails().getFriendlyName()) ? device.getDisplayString()
: device.getDetails().getFriendlyName();
String friendlyName = device.getDetails().getFriendlyName();
String label = friendlyName == null || friendlyName.isEmpty() ? device.getDisplayString() : friendlyName;
Map<String, Object> properties = new HashMap<>(2, 1);
properties.put(PioneerAvrBindingConstants.HOST_PARAMETER,
device.getIdentity().getDescriptorURL().getHost());
@@ -93,15 +92,16 @@ public class PioneerAvrDiscoveryParticipant implements UpnpDiscoveryParticipant
public ThingUID getThingUID(RemoteDevice device) {
ThingUID result = null;
if (isAutoDiscoveryEnabled) {
if (StringUtils.containsIgnoreCase(device.getDetails().getManufacturerDetails().getManufacturer(),
PioneerAvrBindingConstants.MANUFACTURER)) {
String manufacturer = device.getDetails().getManufacturerDetails().getManufacturer();
if (manufacturer != null
&& manufacturer.toLowerCase().contains(PioneerAvrBindingConstants.MANUFACTURER.toLowerCase())) {
logger.debug("Manufacturer matched: search: {}, device value: {}.",
PioneerAvrBindingConstants.MANUFACTURER,
device.getDetails().getManufacturerDetails().getManufacturer());
if (StringUtils.containsIgnoreCase(device.getType().getType(),
PioneerAvrBindingConstants.UPNP_DEVICE_TYPE)) {
PioneerAvrBindingConstants.MANUFACTURER, manufacturer);
String type = device.getType().getType();
if (type != null
&& type.toLowerCase().contains(PioneerAvrBindingConstants.UPNP_DEVICE_TYPE.toLowerCase())) {
logger.debug("Device type matched: search: {}, device value: {}.",
PioneerAvrBindingConstants.UPNP_DEVICE_TYPE, device.getType().getType());
PioneerAvrBindingConstants.UPNP_DEVICE_TYPE, type);
String deviceModel = device.getDetails().getModelDetails() != null
? device.getDetails().getModelDetails().getModelName()
@@ -150,7 +150,7 @@ public class PioneerAvrDiscoveryParticipant implements UpnpDiscoveryParticipant
* @return
*/
private boolean isSupportedDeviceModel(String deviceModel, Set<String> supportedDeviceModels) {
return StringUtils.isNotBlank(deviceModel) && supportedDeviceModels.stream()
.anyMatch(input -> StringUtils.startsWithIgnoreCase(deviceModel, input));
return deviceModel != null && !deviceModel.isBlank() && supportedDeviceModels.stream()
.anyMatch(input -> deviceModel.toLowerCase().startsWith(input.toLowerCase()));
}
}

View File

@@ -12,7 +12,6 @@
*/
package org.openhab.binding.pioneeravr.internal.protocol;
import org.apache.commons.lang.StringUtils;
import org.openhab.binding.pioneeravr.internal.protocol.avr.AvrCommand;
import org.openhab.binding.pioneeravr.internal.protocol.avr.AvrConnectionException;
@@ -72,7 +71,7 @@ public class ParameterizedCommand extends SimpleCommand {
"The parameter of the command " + super.getCommand() + " must not be null.");
}
if (StringUtils.isNotEmpty(parameterPattern) && !parameter.matches(parameterPattern)) {
if (parameterPattern != null && !parameterPattern.isEmpty() && !parameter.matches(parameterPattern)) {
throw new AvrConnectionException("The parameter value " + parameter + " of the command "
+ super.getCommand() + " does not match the pattern " + parameterPattern);
}

View File

@@ -15,7 +15,7 @@ package org.openhab.binding.pioneeravr.internal.protocol;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.pioneeravr.internal.protocol.avr.AvrConnectionException;
import org.openhab.binding.pioneeravr.internal.protocol.avr.AvrResponse;
@@ -41,11 +41,11 @@ public class Response implements AvrResponse {
private String[] responsePrefixZone;
private String parameterPattern;
private @Nullable String parameterPattern;
private Pattern[] matchPatternZone;
private ResponseType(String parameterPattern, String... responsePrefixZone) {
private ResponseType(@Nullable String parameterPattern, String... responsePrefixZone) {
this.responsePrefixZone = responsePrefixZone;
this.parameterPattern = parameterPattern;
@@ -53,8 +53,8 @@ public class Response implements AvrResponse {
for (int zoneIndex = 0; zoneIndex < responsePrefixZone.length; zoneIndex++) {
String responsePrefix = responsePrefixZone[zoneIndex];
matchPatternZone[zoneIndex] = Pattern.compile(responsePrefix + "("
+ (StringUtils.isNotEmpty(parameterPattern) ? parameterPattern : "") + ")");
matchPatternZone[zoneIndex] = Pattern
.compile(responsePrefix + "(" + (parameterPattern == null ? "" : parameterPattern) + ")");
}
}
@@ -65,11 +65,11 @@ public class Response implements AvrResponse {
@Override
public boolean hasParameter() {
return StringUtils.isNotEmpty(parameterPattern);
return parameterPattern != null && !parameterPattern.isEmpty();
}
@Override
public String getParameterPattern() {
public @Nullable String getParameterPattern() {
return parameterPattern;
}
@@ -115,7 +115,7 @@ public class Response implements AvrResponse {
private String parameter;
public Response(String responseData) throws AvrConnectionException {
if (StringUtils.isEmpty(responseData)) {
if (responseData == null || responseData.isEmpty()) {
throw new AvrConnectionException("responseData is empty. Cannot parse the response.");
}

View File

@@ -12,6 +12,7 @@
*/
package org.openhab.binding.pioneeravr.internal.protocol.avr;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.pioneeravr.internal.protocol.Response.ResponseType;
/**
@@ -46,7 +47,7 @@ public interface AvrResponse {
*
* @return
*/
public String getParameterPattern();
public @Nullable String getParameterPattern();
/**
* Return the zone number if the responseData matches a zone of this responseType.