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:
Holger Friedrich
2023-09-05 22:30:16 +02:00
committed by GitHub
parent a0dc5c05f2
commit cf10b3e9c7
486 changed files with 2053 additions and 1955 deletions

View File

@@ -42,8 +42,8 @@ public class BridgeActions implements ThingActions {
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof ADBridgeHandler) {
this.bridge = (ADBridgeHandler) handler;
if (handler instanceof ADBridgeHandler bridgeHandler) {
this.bridge = bridgeHandler;
}
}

View File

@@ -20,8 +20,8 @@ import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@@ -87,7 +87,7 @@ public abstract class ADBridgeHandler extends BaseBridgeHandler {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singletonList(BridgeActions.class);
return List.of(BridgeActions.class);
}
public void setDiscoveryService(AlarmDecoderDiscoveryService discoveryService) {

View File

@@ -113,13 +113,13 @@ public class KeypadHandler extends ADThingHandler {
IntCommandMap intCommandMap = this.intCommandMap;
if (channelUID.getId().equals(CHANNEL_KP_COMMAND)) {
if (command instanceof StringType) {
String cmd = ((StringType) command).toString();
if (command instanceof StringType commandString) {
String cmd = commandString.toString();
handleKeypadCommand(cmd);
}
} else if (channelUID.getId().equals(CHANNEL_KP_INTCOMMAND)) {
if (command instanceof Number) {
int icmd = ((Number) command).intValue();
if (command instanceof Number numberCommand) {
int icmd = numberCommand.intValue();
if (intCommandMap != null) {
String cmd = intCommandMap.getCommand(icmd);
if (cmd != null) {

View File

@@ -78,8 +78,8 @@ public class VZoneHandler extends ADThingHandler {
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
if (channelUID.getId().equals(CHANNEL_COMMAND)) {
if (command instanceof StringType) {
String cmd = ((StringType) command).toString();
if (command instanceof StringType stringCommand) {
String cmd = stringCommand.toString();
if (CMD_OPEN.equalsIgnoreCase(cmd)) {
sendCommand(ADCommand.setZone(config.address, ADCommand.ZONE_OPEN));
setChannelState(OnOffType.OFF);

View File

@@ -46,7 +46,7 @@ public class ZoneHandler extends ADThingHandler {
}
/** Construct zone id from address and channel */
public static final String zoneID(int address, int channel) {
public static String zoneID(int address, int channel) {
return String.format("%d-%d", address, channel);
}

View File

@@ -40,7 +40,7 @@ public class EXPMessage extends ADMessage {
public EXPMessage(String message) throws IllegalArgumentException {
super(message);
String topLevel[] = message.split(":");
String[] topLevel = message.split(":");
if (topLevel.length != 2) {
throw new IllegalArgumentException("Multiple colons found in EXP message");
}

View File

@@ -143,8 +143,7 @@ public class KeypadMessage extends ADMessage {
return false;
} else if (this == obj) {
return true;
} else if (obj instanceof KeypadMessage) {
KeypadMessage other = (KeypadMessage) obj;
} else if (obj instanceof KeypadMessage other) {
return this.message.equals(other.message);
} else {
return false;

View File

@@ -43,7 +43,7 @@ public class LRRMessage extends ADMessage {
public LRRMessage(String message) throws IllegalArgumentException {
super(message);
String topLevel[] = message.split(":");
String[] topLevel = message.split(":");
if (topLevel.length != 2) {
throw new IllegalArgumentException("multiple colons in LRR message");
}

View File

@@ -43,7 +43,7 @@ public class RFXMessage extends ADMessage {
public RFXMessage(String message) throws IllegalArgumentException {
super(message);
String topLevel[] = message.split(":");
String[] topLevel = message.split(":");
if (topLevel.length != 2) {
throw new IllegalArgumentException("Multiple colons found in RFX message");
}

View File

@@ -38,7 +38,7 @@ public class VersionMessage extends ADMessage {
public VersionMessage(String message) throws IllegalArgumentException {
super(message);
String topLevel[] = message.split(":");
String[] topLevel = message.split(":");
if (topLevel.length != 2) {
throw new IllegalArgumentException("Multiple colons found in VER message");
}