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:
@@ -21,7 +21,6 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
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.TextValue;
|
||||
@@ -78,7 +77,7 @@ public class ChannelState implements MqttMessageSubscriber {
|
||||
this.channelStateUpdateListener = channelStateUpdateListener;
|
||||
this.channelUID = channelUID;
|
||||
this.cachedValue = cachedValue;
|
||||
this.readOnly = StringUtils.isBlank(config.commandTopic);
|
||||
this.readOnly = config.commandTopic.isBlank();
|
||||
}
|
||||
|
||||
public boolean isReadOnly() {
|
||||
@@ -242,7 +241,7 @@ public class ChannelState implements MqttMessageSubscriber {
|
||||
*/
|
||||
public CompletableFuture<@Nullable Void> stop() {
|
||||
final MqttBrokerConnection connection = this.connection;
|
||||
if (connection != null && StringUtils.isNotBlank(config.stateTopic)) {
|
||||
if (connection != null && !config.stateTopic.isBlank()) {
|
||||
return connection.unsubscribe(config.stateTopic, this).thenRun(this::internalStop);
|
||||
} else {
|
||||
internalStop();
|
||||
@@ -297,7 +296,7 @@ public class ChannelState implements MqttMessageSubscriber {
|
||||
|
||||
this.connection = connection;
|
||||
|
||||
if (StringUtils.isBlank(config.stateTopic)) {
|
||||
if (config.stateTopic.isBlank()) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
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.binding.mqtt.generic.AbstractMQTTThingHandler;
|
||||
@@ -164,9 +164,8 @@ public class GenericMQTTThingHandler extends AbstractMQTTThingHandler implements
|
||||
Value value = ValueFactory.createValueState(channelConfig, channelTypeUID.getId());
|
||||
ChannelState channelState = createChannelState(channelConfig, channel.getUID(), value);
|
||||
channelStateByChannelUID.put(channel.getUID(), channelState);
|
||||
StateDescription description = value
|
||||
.createStateDescription(StringUtils.isBlank(channelConfig.commandTopic)).build()
|
||||
.toStateDescription();
|
||||
StateDescription description = value.createStateDescription(channelConfig.commandTopic.isBlank())
|
||||
.build().toStateDescription();
|
||||
if (description != null) {
|
||||
stateDescProvider.setDescription(channel.getUID(), description);
|
||||
}
|
||||
|
||||
@@ -12,12 +12,13 @@
|
||||
*/
|
||||
package org.openhab.binding.mqtt.generic.values;
|
||||
|
||||
import static java.util.function.Predicate.not;
|
||||
|
||||
import java.util.Collections;
|
||||
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.core.library.CoreItemFactory;
|
||||
@@ -45,7 +46,7 @@ public class TextValue extends Value {
|
||||
*/
|
||||
public TextValue(String[] states) {
|
||||
super(CoreItemFactory.STRING, Collections.singletonList(StringType.class));
|
||||
Set<String> s = Stream.of(states).filter(e -> StringUtils.isNotBlank(e)).collect(Collectors.toSet());
|
||||
Set<String> s = Stream.of(states).filter(not(String::isBlank)).collect(Collectors.toSet());
|
||||
if (!s.isEmpty()) {
|
||||
this.states = s;
|
||||
} else {
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
*/
|
||||
package org.openhab.binding.mqtt.generic.values;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.mqtt.generic.ChannelConfig;
|
||||
import org.openhab.binding.mqtt.generic.internal.MqttBindingConstants;
|
||||
@@ -35,7 +34,7 @@ public class ValueFactory {
|
||||
Value value;
|
||||
switch (channelTypeID) {
|
||||
case MqttBindingConstants.STRING:
|
||||
value = StringUtils.isBlank(config.allowedStates) ? new TextValue()
|
||||
value = config.allowedStates.isBlank() ? new TextValue()
|
||||
: new TextValue(config.allowedStates.split(","));
|
||||
break;
|
||||
case MqttBindingConstants.DATETIME:
|
||||
|
||||
Reference in New Issue
Block a user