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:
@@ -18,7 +18,7 @@ import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintStream;
|
||||
import java.net.Socket;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
@@ -111,11 +111,11 @@ public class PilightConnector implements Runnable, Closeable {
|
||||
callback.versionReceived(version);
|
||||
} else if (line.startsWith("{\"status\":")) {
|
||||
// currently unused
|
||||
} else if (line.equals("1")) {
|
||||
} else if ("1".equals(line)) {
|
||||
throw new IOException("Connection to pilight lost");
|
||||
} else {
|
||||
final @Nullable Status status = inputMapper.readValue(line, Status.class);
|
||||
callback.statusReceived(Collections.singletonList(status));
|
||||
callback.statusReceived(List.of(status));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,9 +57,14 @@ public class PilightBridgeDiscoveryService extends AbstractDiscoveryService {
|
||||
private static final int AUTODISCOVERY_SEARCH_TIME_SEC = 5;
|
||||
private static final int AUTODISCOVERY_BACKGROUND_SEARCH_INTERVAL_SEC = 60 * 10;
|
||||
|
||||
private static final String SSDP_DISCOVERY_REQUEST_MESSAGE = "M-SEARCH * HTTP/1.1\r\n"
|
||||
+ "Host:239.255.255.250:1900\r\n" + "ST:urn:schemas-upnp-org:service:pilight:1\r\n"
|
||||
+ "Man:\"ssdp:discover\"\r\n" + "MX:3\r\n\r\n";
|
||||
private static final String SSDP_DISCOVERY_REQUEST_MESSAGE = """
|
||||
M-SEARCH * HTTP/1.1
|
||||
Host:239.255.255.250:1900
|
||||
ST:urn:schemas-upnp-org:service:pilight:1
|
||||
Man:"ssdp:discover"
|
||||
MX:3
|
||||
|
||||
""";
|
||||
public static final String SSDP_MULTICAST_ADDRESS = "239.255.255.250";
|
||||
public static final int SSDP_PORT = 1900;
|
||||
public static final int SSDP_WAIT_TIMEOUT = 2000; // in milliseconds
|
||||
@@ -73,7 +78,7 @@ public class PilightBridgeDiscoveryService extends AbstractDiscoveryService {
|
||||
}
|
||||
|
||||
public static Set<ThingTypeUID> getSupportedThingTypeUIDs() {
|
||||
return Collections.singleton(PilightBindingConstants.THING_TYPE_BRIDGE);
|
||||
return Set.of(PilightBindingConstants.THING_TYPE_BRIDGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -165,12 +165,9 @@ public class PilightDeviceDiscoveryService extends AbstractDiscoveryService impl
|
||||
|
||||
@Override
|
||||
public void setThingHandler(final ThingHandler handler) {
|
||||
if (handler instanceof PilightBridgeHandler) {
|
||||
this.pilightBridgeHandler = (PilightBridgeHandler) handler;
|
||||
final @Nullable PilightBridgeHandler pilightBridgeHandler = this.pilightBridgeHandler;
|
||||
if (pilightBridgeHandler != null) {
|
||||
bridgeUID = pilightBridgeHandler.getThing().getUID();
|
||||
}
|
||||
if (handler instanceof PilightBridgeHandler pilightBridgeHandler) {
|
||||
this.pilightBridgeHandler = pilightBridgeHandler;
|
||||
bridgeUID = pilightBridgeHandler.getThing().getUID();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -121,8 +121,8 @@ public abstract class PilightBaseHandler extends BaseThingHandler {
|
||||
if (bridge != null) {
|
||||
@Nullable
|
||||
BridgeHandler handler = bridge.getHandler();
|
||||
if (handler instanceof PilightBridgeHandler) {
|
||||
return (PilightBridgeHandler) handler;
|
||||
if (handler instanceof PilightBridgeHandler bridgeHandler) {
|
||||
return bridgeHandler;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
package org.openhab.binding.pilight.internal.handler;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
@@ -185,8 +185,8 @@ public class PilightBridgeHandler extends BaseBridgeHandler {
|
||||
if (!DeviceType.SERVER.equals(type)) {
|
||||
for (Thing thing : getThing().getThings()) {
|
||||
final @Nullable ThingHandler handler = thing.getHandler();
|
||||
if (handler instanceof PilightBaseHandler) {
|
||||
((PilightBaseHandler) handler).updateFromStatusIfMatches(status);
|
||||
if (handler instanceof PilightBaseHandler baseHandler) {
|
||||
baseHandler.updateFromStatusIfMatches(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -194,7 +194,7 @@ public class PilightBridgeHandler extends BaseBridgeHandler {
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||
return Collections.singleton(PilightDeviceDiscoveryService.class);
|
||||
return Set.of(PilightDeviceDiscoveryService.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,8 +228,8 @@ public class PilightBridgeHandler extends BaseBridgeHandler {
|
||||
private void processConfig(Config config) {
|
||||
for (Thing thing : getThing().getThings()) {
|
||||
final @Nullable ThingHandler handler = thing.getHandler();
|
||||
if (handler instanceof PilightBaseHandler) {
|
||||
((PilightBaseHandler) handler).updateFromConfigIfMatches(config);
|
||||
if (handler instanceof PilightBaseHandler baseHandler) {
|
||||
baseHandler.updateFromConfigIfMatches(config);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,8 +91,8 @@ public class PilightDimmerHandler extends PilightBaseHandler {
|
||||
|
||||
if (command instanceof OnOffType) {
|
||||
code.setState(command.equals(OnOffType.ON) ? Code.STATE_ON : Code.STATE_OFF);
|
||||
} else if (command instanceof PercentType) {
|
||||
setDimmerValue((PercentType) command, code);
|
||||
} else if (command instanceof PercentType percentCommand) {
|
||||
setDimmerValue(percentCommand, code);
|
||||
} else {
|
||||
logger.warn("Only OnOffType and PercentType are supported by a dimmer.");
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user