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:
Holger Friedrich
2023-09-21 07:58:53 +02:00
committed by GitHub
parent bf1aa3deb2
commit 1b122a53b9
277 changed files with 1402 additions and 1298 deletions

View File

@@ -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.";
}

View File

@@ -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();
}

View File

@@ -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));
}
}

View File

@@ -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(

View File

@@ -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));
}
}

View File

@@ -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);

View File

@@ -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;