Java 17 features (A-G) (#15516)
- 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:
@@ -23,5 +23,5 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@NonNullByDefault
|
||||
public enum TroubleStatus {
|
||||
TROUBLE_STARTED,
|
||||
TROUBLE_RESTORED;
|
||||
TROUBLE_RESTORED
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ package org.openhab.binding.digiplex.internal.discovery;
|
||||
|
||||
import static org.openhab.binding.digiplex.internal.DigiplexBindingConstants.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
@@ -53,7 +53,7 @@ public class DigiplexDiscoveryService extends AbstractDiscoveryService
|
||||
private @Nullable DigiplexBridgeHandler bridgeHandler;
|
||||
|
||||
public DigiplexDiscoveryService() {
|
||||
super(Collections.singleton(THING_TYPE_ZONE), DISCOVERY_TIMEOUT, false);
|
||||
super(Set.of(THING_TYPE_ZONE), DISCOVERY_TIMEOUT, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,9 +100,8 @@ public class DigiplexDiscoveryService extends AbstractDiscoveryService
|
||||
}
|
||||
|
||||
private boolean isDefaultName(ZoneLabelResponse response) {
|
||||
return ZONE_DEFAULT_NAMES.stream().anyMatch(format -> {
|
||||
return String.format(format, response.zoneNo).equals(response.zoneName);
|
||||
});
|
||||
return ZONE_DEFAULT_NAMES.stream()
|
||||
.anyMatch(format -> String.format(format, response.zoneNo).equals(response.zoneName));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -127,8 +126,8 @@ public class DigiplexDiscoveryService extends AbstractDiscoveryService
|
||||
|
||||
@Override
|
||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||
if (handler instanceof DigiplexBridgeHandler) {
|
||||
bridgeHandler = (DigiplexBridgeHandler) handler;
|
||||
if (handler instanceof DigiplexBridgeHandler digiplexBridgeHandler) {
|
||||
bridgeHandler = digiplexBridgeHandler;
|
||||
bridgeHandler.registerMessageHandler(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,8 +121,8 @@ public class DigiplexAreaHandler extends BaseThingHandler {
|
||||
case AREA_CONTROL:
|
||||
if (command == RefreshType.REFRESH) {
|
||||
updateState(AREA_CONTROL, lastCommandResult);
|
||||
} else if (command instanceof StringType) {
|
||||
processControlCommand(((StringType) command).toString());
|
||||
} else if (command instanceof StringType stringCommand) {
|
||||
processControlCommand(stringCommand.toString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.TooManyListenersException;
|
||||
@@ -272,7 +272,7 @@ public class DigiplexBridgeHandler extends BaseBridgeHandler implements SerialPo
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||
return Collections.singletonList(DigiplexDiscoveryService.class);
|
||||
return List.of(DigiplexDiscoveryService.class);
|
||||
}
|
||||
|
||||
private class BridgeMessageHandler implements DigiplexMessageHandler {
|
||||
@@ -367,7 +367,7 @@ public class DigiplexBridgeHandler extends BaseBridgeHandler implements SerialPo
|
||||
stream.write(request.getSerialMessage().getBytes());
|
||||
stream.flush();
|
||||
updateState(BRIDGE_MESSAGES_SENT, new DecimalType(messagesSent.incrementAndGet()));
|
||||
logger.debug("message sent: '{}'", request.getSerialMessage().replaceAll("\r", ""));
|
||||
logger.debug("message sent: '{}'", request.getSerialMessage().replace("\r", ""));
|
||||
Thread.sleep(SLEEP_TIME); // do not flood PRT3 with messages as it creates unpredictable responses
|
||||
} catch (IOException e) {
|
||||
handleCommunicationError();
|
||||
|
||||
Reference in New Issue
Block a user