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

@@ -16,7 +16,6 @@ import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.mqtt.generic.MqttChannelTypeProvider;
@@ -54,8 +53,8 @@ public class MqttThingHandlerFactory extends BaseThingHandlerFactory implements
}
private boolean isHomeassistantDynamicType(ThingTypeUID thingTypeUID) {
return StringUtils.equals(MqttBindingConstants.BINDING_ID, thingTypeUID.getBindingId())
&& StringUtils.startsWith(thingTypeUID.getId(), MqttBindingConstants.HOMEASSISTANT_MQTT_THING.getId());
return MqttBindingConstants.BINDING_ID.equals(thingTypeUID.getBindingId())
&& thingTypeUID.getId().startsWith(MqttBindingConstants.HOMEASSISTANT_MQTT_THING.getId());
}
@Activate

View File

@@ -16,7 +16,6 @@ import java.util.List;
import java.util.Map;
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.Thing;
@@ -103,9 +102,9 @@ public abstract class BaseChannelConfiguration {
protected @Nullable String name;
protected @Nullable String sw_version;
@Nullable
public String getId() {
return StringUtils.join(identifiers, "_");
public @Nullable String getId() {
List<String> identifiers = this.identifiers;
return identifiers == null ? null : String.join("_", identifiers);
}
}

View File

@@ -16,7 +16,6 @@ import java.net.URI;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ScheduledExecutorService;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.mqtt.generic.ChannelConfigBuilder;
@@ -149,9 +148,9 @@ public class CChannel {
public Builder stateTopic(@Nullable String state_topic, @Nullable String... templates) {
this.state_topic = state_topic;
if (StringUtils.isNotBlank(state_topic)) {
if (state_topic != null && !state_topic.isBlank()) {
for (String template : templates) {
if (StringUtils.isNotBlank(template)) {
if (template != null && !template.isBlank()) {
this.templateIn = template;
break;
}
@@ -204,7 +203,8 @@ public class CChannel {
.withCommandTopic(command_topic).makeTrigger(trigger).build(),
channelUID, valueState, channelStateUpdateListener);
if (StringUtils.isBlank(state_topic) || this.trigger) {
String localStateTopic = state_topic;
if (localStateTopic == null || localStateTopic.isBlank() || this.trigger) {
type = ChannelTypeBuilder.trigger(channelTypeUID, label)
.withConfigDescriptionURI(URI.create(MqttBindingConstants.CONFIG_HA_CHANNEL)).build();
} else {

View File

@@ -15,7 +15,6 @@ package org.openhab.binding.mqtt.homeassistant.internal;
import java.io.IOException;
import java.lang.reflect.Field;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@@ -119,7 +118,7 @@ public class ChannelConfigurationTypeAdapterFactory implements TypeAdapterFactor
final String oldValue = (String) field.get(config);
String newValue = oldValue;
if (StringUtils.isNotBlank(oldValue)) {
if (oldValue != null && !oldValue.isBlank()) {
if (oldValue.charAt(0) == '~') {
newValue = tilde + oldValue.substring(1);
} else if (oldValue.charAt(oldValue.length() - 1) == '~') {

View File

@@ -12,7 +12,6 @@
*/
package org.openhab.binding.mqtt.homeassistant.internal;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.mqtt.generic.values.OnOffValue;
@@ -46,7 +45,7 @@ public class ComponentLock extends AbstractComponent<ComponentLock.ChannelConfig
super(componentConfiguration, ChannelConfiguration.class);
// We do not support all HomeAssistant quirks
if (channelConfiguration.optimistic && StringUtils.isNotBlank(channelConfiguration.state_topic)) {
if (channelConfiguration.optimistic && !channelConfiguration.state_topic.isBlank()) {
throw new UnsupportedOperationException("Component:Lock does not support forced optimistic mode");
}

View File

@@ -15,7 +15,6 @@ package org.openhab.binding.mqtt.homeassistant.internal;
import java.util.List;
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.binding.mqtt.generic.ChannelStateUpdateListener;
@@ -61,7 +60,7 @@ public class ComponentSensor extends AbstractComponent<ComponentSensor.ChannelCo
String uom = channelConfiguration.unit_of_measurement;
if (uom != null && StringUtils.isNotBlank(uom)) {
if (uom != null && !uom.isBlank()) {
value = new NumberValue(null, null, null, uom);
} else {
value = new TextValue();

View File

@@ -12,7 +12,6 @@
*/
package org.openhab.binding.mqtt.homeassistant.internal;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.mqtt.generic.values.OnOffValue;
@@ -52,9 +51,9 @@ public class ComponentSwitch extends AbstractComponent<ComponentSwitch.ChannelCo
super(componentConfiguration, ChannelConfiguration.class);
boolean optimistic = channelConfiguration.optimistic != null ? channelConfiguration.optimistic
: StringUtils.isBlank(channelConfiguration.state_topic);
: channelConfiguration.state_topic.isBlank();
if (optimistic && StringUtils.isNotBlank(channelConfiguration.state_topic)) {
if (optimistic && !channelConfiguration.state_topic.isBlank()) {
throw new UnsupportedOperationException("Component:Switch does not support forced optimistic mode");
}

View File

@@ -15,7 +15,6 @@ package org.openhab.binding.mqtt.homeassistant.internal;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.config.core.Configuration;
@@ -93,7 +92,7 @@ public class HaID {
private static final String createTopic(HaID id) {
StringBuilder str = new StringBuilder();
str.append(id.baseTopic).append('/').append(id.component).append('/');
if (StringUtils.isNotBlank(id.nodeID)) {
if (!id.nodeID.isBlank()) {
str.append(id.nodeID).append('/');
}
str.append(id.objectID).append('/');
@@ -175,7 +174,7 @@ public class HaID {
*/
public String toShortTopic() {
String objectID = this.objectID;
if (StringUtils.isNotBlank(nodeID)) {
if (!nodeID.isBlank()) {
objectID = nodeID + "/" + objectID;
}
@@ -192,10 +191,10 @@ public class HaID {
String result = uniqueId;
// the null test is only here so the compile knows, result is not null afterwards
if (result == null || StringUtils.isBlank(result)) {
if (result == null || result.isBlank()) {
StringBuilder str = new StringBuilder();
if (StringUtils.isNotBlank(nodeID)) {
if (!nodeID.isBlank()) {
str.append(nodeID).append('_');
}
str.append(objectID).append('_').append(component);