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

@@ -42,8 +42,8 @@ public class ZmActions implements ThingActions {
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof ZmMonitorHandler) {
this.handler = (ZmMonitorHandler) handler;
if (handler instanceof ZmMonitorHandler zmMonitorHandler) {
this.handler = zmMonitorHandler;
}
}

View File

@@ -70,8 +70,8 @@ public class MonitorDiscoveryService extends AbstractDiscoveryService implements
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof ZmBridgeHandler) {
bridgeHandler = (ZmBridgeHandler) handler;
if (handler instanceof ZmBridgeHandler zmBridgeHandler) {
bridgeHandler = zmBridgeHandler;
}
}

View File

@@ -222,7 +222,7 @@ public class ZmBridgeHandler extends BaseBridgeHandler {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(MonitorDiscoveryService.class);
return Set.of(MonitorDiscoveryService.class);
}
public boolean isBackgroundDiscoveryEnabled() {
@@ -294,8 +294,7 @@ public class ZmBridgeHandler extends BaseBridgeHandler {
try {
ContentResponse response = request.send();
if (response.getStatus() == HttpStatus.OK_200) {
RawType image = new RawType(response.getContent(), response.getHeaders().get(HttpHeader.CONTENT_TYPE));
return image;
return new RawType(response.getContent(), response.getHeaders().get(HttpHeader.CONTENT_TYPE));
} else {
errorMsg = String.format("HTTP GET failed: %d, %s", response.getStatus(), response.getReason());
}

View File

@@ -16,8 +16,8 @@ import static org.openhab.binding.zoneminder.internal.ZmBindingConstants.*;
import java.time.ZonedDateTime;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@@ -125,8 +125,8 @@ public class ZmMonitorHandler extends BaseThingHandler {
}
break;
case CHANNEL_ENABLE:
if (command instanceof OnOffType) {
localHandler.setEnabled(monitorId, (OnOffType) command);
if (command instanceof OnOffType onOffCommand) {
localHandler.setEnabled(monitorId, onOffCommand);
logger.debug("Monitor {}: Set monitor enable to {}", monitorId, command);
}
break;
@@ -147,7 +147,7 @@ public class ZmMonitorHandler extends BaseThingHandler {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(ZmActions.class);
return Set.of(ZmActions.class);
}
public String getId() {