Java 17 features (N-S) (#15565)

- 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

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich
2023-09-13 08:03:31 +02:00
committed by GitHub
parent 641b482551
commit ab58f4ffb4
471 changed files with 1624 additions and 1868 deletions

View File

@@ -101,8 +101,8 @@ public class NukiHandlerFactory extends BaseThingHandlerFactory {
public void unregisterHandler(Thing thing) {
super.unregisterHandler(thing);
ThingHandler handler = thing.getHandler();
if (handler instanceof NukiBridgeHandler) {
nukiApiServlet.remove((NukiBridgeHandler) handler);
if (handler instanceof NukiBridgeHandler bridgeHandler) {
nukiApiServlet.remove(bridgeHandler);
}
}

View File

@@ -12,7 +12,6 @@
*/
package org.openhab.binding.nuki.internal.constants;
import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -38,9 +37,9 @@ public class NukiBindingConstants {
public static final ThingTypeUID THING_TYPE_SMARTLOCK = new ThingTypeUID(BINDING_ID, "smartlock");
public static final ThingTypeUID THING_TYPE_OPENER = new ThingTypeUID(BINDING_ID, "opener");
public static final Set<ThingTypeUID> THING_TYPE_BRIDGE_UIDS = Collections.singleton(THING_TYPE_BRIDGE);
public static final Set<ThingTypeUID> THING_TYPE_SMARTLOCK_UIDS = Collections.singleton(THING_TYPE_SMARTLOCK);
public static final Set<ThingTypeUID> THING_TYPE_OPENER_UIDS = Collections.singleton(THING_TYPE_OPENER);
public static final Set<ThingTypeUID> THING_TYPE_BRIDGE_UIDS = Set.of(THING_TYPE_BRIDGE);
public static final Set<ThingTypeUID> THING_TYPE_SMARTLOCK_UIDS = Set.of(THING_TYPE_SMARTLOCK);
public static final Set<ThingTypeUID> THING_TYPE_OPENER_UIDS = Set.of(THING_TYPE_OPENER);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Stream
.of(THING_TYPE_BRIDGE_UIDS, THING_TYPE_SMARTLOCK_UIDS, THING_TYPE_OPENER_UIDS).flatMap(Set::stream)

View File

@@ -73,8 +73,7 @@ public class NukiHttpClient {
private NukiBaseResponse handleException(Exception e) {
if (e instanceof ExecutionException) {
Throwable cause = e.getCause();
if (cause instanceof HttpResponseException) {
HttpResponseException causeException = (HttpResponseException) cause;
if (cause instanceof HttpResponseException causeException) {
int status = causeException.getResponse().getStatus();
String reason = causeException.getResponse().getReason();
logger.debug("HTTP Response Exception! Status[{}] - Reason[{}]! Check your API Token!", status, reason);

View File

@@ -12,7 +12,7 @@
*/
package org.openhab.binding.nuki.internal.discovery;
import java.util.Collections;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jetty.client.HttpClient;
@@ -56,7 +56,7 @@ public class NukiBridgeDiscoveryService extends AbstractDiscoveryService {
@Activate
public NukiBridgeDiscoveryService(@Reference final HttpClientFactory httpClientFactory,
@Reference final ThingRegistry thingRegistry) {
super(Collections.singleton(NukiBindingConstants.THING_TYPE_BRIDGE), 30, false);
super(Set.of(NukiBindingConstants.THING_TYPE_BRIDGE), 30, false);
this.httpClient = httpClientFactory.getCommonHttpClient();
this.thingRegistry = thingRegistry;
}

View File

@@ -103,8 +103,8 @@ public class NukiDeviceDiscoveryService extends AbstractDiscoveryService impleme
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof NukiBridgeHandler) {
bridge = (NukiBridgeHandler) handler;
if (handler instanceof NukiBridgeHandler bridgeHandler) {
bridge = bridgeHandler;
}
}

View File

@@ -149,8 +149,7 @@ public abstract class AbstractNukiDeviceHandler<T extends NukiDeviceConfiguratio
}
private void initializeHandler(@Nullable ThingHandler handler, @Nullable ThingStatus bridgeStatus) {
if (handler instanceof NukiBridgeHandler && bridgeStatus != null) {
NukiBridgeHandler bridgeHandler = (NukiBridgeHandler) handler;
if (handler instanceof NukiBridgeHandler bridgeHandler && bridgeStatus != null) {
if (bridgeStatus == ThingStatus.ONLINE) {
this.nukiHttpClient = bridgeHandler.getNukiHttpClient();
withHttpClient(client -> {
@@ -203,6 +202,7 @@ public abstract class AbstractNukiDeviceHandler<T extends NukiDeviceConfiguratio
}
}
@Override
protected void triggerChannel(String channelId, String event) {
Channel channel = thing.getChannel(channelId);
if (channel != null) {
@@ -335,8 +335,8 @@ public abstract class AbstractNukiDeviceHandler<T extends NukiDeviceConfiguratio
Bridge bridge = getBridge();
if (bridge != null) {
BridgeHandler bridgeHandler = bridge.getHandler();
if (bridgeHandler instanceof NukiBridgeHandler) {
scheduler.execute(() -> handler.accept((NukiBridgeHandler) bridgeHandler));
if (bridgeHandler instanceof NukiBridgeHandler nukiBridgeHandler) {
scheduler.execute(() -> handler.accept(nukiBridgeHandler));
}
}
}

View File

@@ -16,6 +16,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
@@ -143,7 +144,7 @@ public class NukiBridgeHandler extends BaseBridgeHandler {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(NukiDeviceDiscoveryService.class);
return Set.of(NukiDeviceDiscoveryService.class);
}
private synchronized void initializeHandler() {
@@ -175,7 +176,6 @@ public class NukiBridgeHandler extends BaseBridgeHandler {
public void checkBridgeOnline() {
logger.debug("checkBridgeOnline():bridgeIp[{}] status[{}]", this.config.ip, getThing().getStatus());
if (getThing().getStatus().equals(ThingStatus.ONLINE)) {
withHttpClient(client -> {
logger.debug("Requesting BridgeInfo to ensure Bridge[{}] is online.", this.config.ip);
BridgeInfoResponse bridgeInfoResponse = client.getBridgeInfo();

View File

@@ -66,8 +66,8 @@ public class NukiOpenerHandler extends AbstractNukiDeviceHandler<NukiDeviceConfi
protected boolean doHandleCommand(ChannelUID channelUID, Command command) {
switch (channelUID.getId()) {
case NukiBindingConstants.CHANNEL_OPENER_STATE:
if (command instanceof DecimalType) {
OpenerAction action = OpenerAction.fromAction(((DecimalType) command).intValue());
if (command instanceof DecimalType decimalCommand) {
OpenerAction action = OpenerAction.fromAction(decimalCommand.intValue());
if (action != null) {
return withHttpClient(client -> {
BridgeLockActionResponse response = client.getOpenerAction(configuration.nukiId, action);

View File

@@ -82,9 +82,8 @@ public class NukiSmartLockHandler extends AbstractNukiDeviceHandler<NukiSmartLoc
}
break;
case NukiBindingConstants.CHANNEL_SMARTLOCK_STATE:
if (command instanceof DecimalType) {
DecimalType cmd = (DecimalType) command;
SmartLockAction action = SmartLockAction.fromAction(cmd.intValue());
if (command instanceof DecimalType decimalCommand) {
SmartLockAction action = SmartLockAction.fromAction(decimalCommand.intValue());
if (action != null) {
withHttpClient(client -> {
BridgeLockActionResponse bridgeLockActionResponse = client