Java 17 features (T-Z) (#15576)
- add missing @override - Java style array syntax - remove redundant modifiers - always move String constants to left side in comparisons - simplify lambda expressions and return statements - use replace instead of replaceAll w/o regex - instanceof matching and multiline strings - remove null check before instanceof Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
package org.openhab.binding.webthing.internal;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.thing.ThingTypeUID;
|
||||
@@ -31,8 +31,8 @@ public class WebThingBindingConstants {
|
||||
|
||||
public static final ThingTypeUID THING_TYPE_UID = new ThingTypeUID(BINDING_ID, "generic");
|
||||
|
||||
public static final Collection<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
|
||||
.singleton(WebThingBindingConstants.THING_TYPE_UID);
|
||||
public static final Collection<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set
|
||||
.of(WebThingBindingConstants.THING_TYPE_UID);
|
||||
|
||||
public static final String MDNS_SERVICE_TYPE = "_webthing._tcp.local.";
|
||||
}
|
||||
|
||||
@@ -261,9 +261,9 @@ public class WebThingHandler extends BaseThingHandler implements ChannelHandler
|
||||
|
||||
@Override
|
||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||
if (command instanceof State) {
|
||||
if (command instanceof State stateCommand) {
|
||||
itemChangedListenerMap.getOrDefault(channelUID, EMPTY_ITEM_CHANGED_LISTENER).onItemStateChanged(channelUID,
|
||||
(State) command);
|
||||
stateCommand);
|
||||
} else if (command instanceof RefreshType) {
|
||||
tryReconnect();
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ public class ConsumedThingImpl implements ConsumedThing {
|
||||
if (optionalProperty.isPresent()) {
|
||||
var propertyDescription = optionalProperty.get();
|
||||
for (var link : propertyDescription.links) {
|
||||
if ((link.rel != null) && (link.href != null) && link.rel.equals("property")) {
|
||||
if ((link.rel != null) && (link.href != null) && "property".equals(link.rel)) {
|
||||
return Optional.of(webThingURI.resolve(link.href));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class DescriptionLoader {
|
||||
|
||||
// currently, the old and new location of the WebThings schema are supported only.
|
||||
// In the future, other schemas such as http://iotschema.org/docs/full.html may be supported
|
||||
if (schema.equals("https://webthings.io/schemas") || schema.equals("https://iot.mozilla.org/schemas")) {
|
||||
if ("https://webthings.io/schemas".equals(schema) || "https://iot.mozilla.org/schemas".equals(schema)) {
|
||||
return description;
|
||||
}
|
||||
logger.debug(
|
||||
|
||||
@@ -57,7 +57,7 @@ public class WebThingDescription {
|
||||
var href = link.href;
|
||||
if ((href != null) && href.startsWith("ws")) {
|
||||
var rel = Optional.ofNullable(link.rel).orElse("<undefined>");
|
||||
if (rel.equals("alternate")) {
|
||||
if ("alternate".equals(rel)) {
|
||||
return Optional.of(URI.create(href));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class TypeConverters {
|
||||
case "color":
|
||||
return new ColorTypeConverter();
|
||||
case "number":
|
||||
if (propertyType.toLowerCase(Locale.ENGLISH).equals("integer")) {
|
||||
if ("integer".equals(propertyType.toLowerCase(Locale.ENGLISH))) {
|
||||
return new IntegerTypeConverter();
|
||||
} else {
|
||||
return new NumberTypeConverter();
|
||||
@@ -169,8 +169,8 @@ class TypeConverters {
|
||||
@Override
|
||||
public Command toStateCommand(Object propertyValue) {
|
||||
String textValue = propertyValue.toString();
|
||||
if (propertyValue instanceof Collection) {
|
||||
textValue = ((Collection<Object>) propertyValue).stream()
|
||||
if (propertyValue instanceof Collection collection) {
|
||||
textValue = collection.stream()
|
||||
.reduce("", (entry1, entry2) -> entry1.toString() + "\n" + entry2.toString()).toString();
|
||||
}
|
||||
return StringType.valueOf(textValue);
|
||||
|
||||
@@ -96,7 +96,7 @@ public class TypeMapping {
|
||||
break;
|
||||
case "LevelProperty":
|
||||
if ((propertyMetadata.unit != null)
|
||||
&& propertyMetadata.unit.toLowerCase(Locale.ENGLISH).equals("percent")) {
|
||||
&& "percent".equals(propertyMetadata.unit.toLowerCase(Locale.ENGLISH))) {
|
||||
type = CoreItemFactory.DIMMER;
|
||||
} else {
|
||||
type = CoreItemFactory.NUMBER;
|
||||
|
||||
Reference in New Issue
Block a user