Java 17 features (H-M) (#15520)

- 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-08 14:36:59 +02:00
committed by GitHub
parent 3751fd0646
commit edaf17b345
519 changed files with 2703 additions and 2660 deletions

View File

@@ -82,7 +82,6 @@ public class KonnectedHandlerFactory extends BaseThingHandlerFactory {
@Override
protected @Nullable ThingHandler createHandler(Thing thing) {
KonnectedHandler thingHandler = new KonnectedHandler(thing, getCallbackUrl());
if (servlet != null) {
logger.debug("Adding thinghandler for thing {} to webhook.", thing.getUID().getId());

View File

@@ -62,9 +62,8 @@ public class KonnectedUPnPServer implements UpnpDiscoveryParticipant {
Map<String, Object> properties = new HashMap<>();
properties.put(BASE_URL, device.getDetails().getBaseURL());
properties.put(MAC_ADDR, device.getDetails().getSerialNumber());
DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties)
return DiscoveryResultBuilder.create(uid).withProperties(properties)
.withLabel(device.getDetails().getFriendlyName()).withRepresentationProperty(MAC_ADDR).build();
return result;
} else {
return null;
}

View File

@@ -88,11 +88,11 @@ public class KonnectedHandler extends BaseThingHandler {
String zone = zoneConfig.zone;
logger.debug("The channelUID is: {} and the zone is : {}", channelUID.getAsString(), zone);
// if the command is OnOfftype
if (command instanceof OnOffType) {
if (command instanceof OnOffType onOffCommand) {
if (channelType.contains(CHANNEL_SWITCH)) {
logger.debug("A command was sent to a sensor type so we are ignoring the command");
} else {
sendActuatorCommand((OnOffType) command, zone, channelUID);
sendActuatorCommand(onOffCommand, zone, channelUID);
}
} else if (command instanceof RefreshType) {
// check to see if handler has been initialized before attempting to get state of pin, else wait one minute
@@ -227,7 +227,7 @@ public class KonnectedHandler extends BaseThingHandler {
// https://github.com/eclipse/smarthome/issues/3484 has been implemented in the framework
String[] cfg = configurationParameter.getKey().split("_");
if ("controller".equals(cfg[0])) {
if (cfg[1].equals("softreset") && value instanceof Boolean && (Boolean) value) {
if ("softreset".equals(cfg[1]) && value instanceof Boolean bool && bool) {
scheduler.execute(() -> {
try {
http.doGet(baseUrl + "/settings?restart=true", null, retryCount);
@@ -235,7 +235,7 @@ public class KonnectedHandler extends BaseThingHandler {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
}
});
} else if (cfg[1].equals("removewifi") && value instanceof Boolean && (Boolean) value) {
} else if ("removewifi".equals(cfg[1]) && value instanceof Boolean bool && bool) {
scheduler.execute(() -> {
try {
http.doGet(baseUrl + "/settings?restore=true", null, retryCount);
@@ -243,7 +243,7 @@ public class KonnectedHandler extends BaseThingHandler {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
}
});
} else if (cfg[1].equals("sendConfig") && value instanceof Boolean && (Boolean) value) {
} else if ("sendConfig".equals(cfg[1]) && value instanceof Boolean bool && bool) {
scheduler.execute(() -> {
try {
String response = updateKonnectedModule();
@@ -444,7 +444,7 @@ public class KonnectedHandler extends BaseThingHandler {
private void getSwitchState(String zone, ChannelUID channelId) {
Channel channel = getThing().getChannel(channelId.getId());
if (!(channel == null)) {
if (channel != null) {
logger.debug("getasstring: {} getID: {} getGroupId: {} toString:{}", channelId.getAsString(),
channelId.getId(), channelId.getGroupId(), channelId);
KonnectedModuleGson payload = new KonnectedModuleGson();