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

@@ -20,7 +20,7 @@ import java.util.HashSet;
import java.util.Map;
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.jupnp.model.meta.RemoteDevice;
@@ -64,7 +64,7 @@ public class OnkyoUpnpDiscoveryParticipant 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);
}
}
@@ -81,8 +81,8 @@ public class OnkyoUpnpDiscoveryParticipant 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(HOST_PARAMETER, device.getIdentity().getDescriptorURL().getHost());
properties.put(UDN_PARAMETER, device.getIdentity().getUdn().getIdentifierString());
@@ -97,13 +97,12 @@ public class OnkyoUpnpDiscoveryParticipant implements UpnpDiscoveryParticipant {
public @Nullable ThingUID getThingUID(RemoteDevice device) {
ThingUID result = null;
if (isAutoDiscoveryEnabled) {
if (StringUtils.containsIgnoreCase(device.getDetails().getManufacturerDetails().getManufacturer(),
MANUFACTURER)) {
logger.debug("Manufacturer matched: search: {}, device value: {}.", MANUFACTURER,
device.getDetails().getManufacturerDetails().getManufacturer());
if (StringUtils.containsIgnoreCase(device.getType().getType(), UPNP_DEVICE_TYPE)) {
logger.debug("Device type matched: search: {}, device value: {}.", UPNP_DEVICE_TYPE,
device.getType().getType());
String manufacturer = device.getDetails().getManufacturerDetails().getManufacturer();
if (manufacturer != null && manufacturer.toLowerCase().contains(MANUFACTURER.toLowerCase())) {
logger.debug("Manufacturer matched: search: {}, device value: {}.", MANUFACTURER, manufacturer);
String type = device.getType().getType();
if (type != null && type.toLowerCase().contains(UPNP_DEVICE_TYPE.toLowerCase())) {
logger.debug("Device type matched: search: {}, device value: {}.", UPNP_DEVICE_TYPE, type);
String deviceModel = device.getDetails().getModelDetails() != null
? device.getDetails().getModelDetails().getModelName()
@@ -143,7 +142,7 @@ public class OnkyoUpnpDiscoveryParticipant implements UpnpDiscoveryParticipant {
* @return
*/
private boolean isSupportedDeviceModel(final @Nullable String deviceModel) {
return StringUtils.isNotBlank(deviceModel) && Arrays.stream(OnkyoModel.values())
return deviceModel != null && !deviceModel.isBlank() && Arrays.stream(OnkyoModel.values())
.anyMatch(model -> StringUtils.startsWithIgnoreCase(deviceModel, model.getId()));
}
}