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:
Holger Friedrich
2023-09-13 08:03:31 +02:00
committed by GitHub
parent 641b482551
commit ab58f4ffb4
471 changed files with 1624 additions and 1868 deletions

View File

@@ -263,8 +263,7 @@ public class SoulissGatewayDiscovery extends AbstractDiscoveryService
@Override
public void setThingHandler(ThingHandler handler) {
if (handler instanceof SoulissGatewayHandler) {
SoulissGatewayHandler localGwHandler = (SoulissGatewayHandler) handler;
if (handler instanceof SoulissGatewayHandler localGwHandler) {
this.soulissGwHandler = localGwHandler;
localGwHandler.discoverResult = this;
}

View File

@@ -13,7 +13,7 @@
package org.openhab.binding.souliss.internal.handler;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
@@ -94,7 +94,7 @@ public class SoulissGatewayHandler extends BaseBridgeHandler {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(SoulissGatewayDiscovery.class);
return Set.of(SoulissGatewayDiscovery.class);
}
@Override

View File

@@ -51,12 +51,12 @@ public class SoulissT13Handler extends SoulissGenericHandler {
public void setState(@Nullable PrimitiveType state) {
super.setLastStatusStored();
if (state != null) {
if (state instanceof OnOffType) {
this.updateState(SoulissBindingConstants.STATEONOFF_CHANNEL, (OnOffType) state);
if (state instanceof OnOffType onOffCommand) {
this.updateState(SoulissBindingConstants.STATEONOFF_CHANNEL, onOffCommand);
}
if (state instanceof OpenClosedType) {
this.updateState(SoulissBindingConstants.STATEOPENCLOSE_CHANNEL, (OpenClosedType) state);
if (state instanceof OpenClosedType openClosedCommand) {
this.updateState(SoulissBindingConstants.STATEOPENCLOSE_CHANNEL, openClosedCommand);
}
}
}

View File

@@ -126,9 +126,7 @@ public class SoulissT16Handler extends SoulissGenericHandler {
break;
case SoulissBindingConstants.LED_COLOR_CHANNEL:
if (command instanceof HSBType) {
HSBType localHsbState = (HSBType) command;
if (command instanceof HSBType localHsbState) {
updateState(SoulissBindingConstants.DIMMER_BRIGHTNESS_CHANNEL,
PercentType.valueOf(hsbState.getBrightness().toString()));
commandSendRgb(SoulissProtocolConstants.SOULISS_T1N_SET,

View File

@@ -79,10 +79,10 @@ public class SoulissT19Handler extends SoulissGenericHandler {
break;
case SoulissBindingConstants.DIMMER_BRIGHTNESS_CHANNEL:
if (command instanceof PercentType) {
updateState(SoulissBindingConstants.DIMMER_BRIGHTNESS_CHANNEL, (PercentType) command);
if (command instanceof PercentType percentCommand) {
updateState(SoulissBindingConstants.DIMMER_BRIGHTNESS_CHANNEL, percentCommand);
commandSEND(SoulissProtocolConstants.SOULISS_T1N_SET,
(byte) (((PercentType) command).shortValue() * 255.00 / 100.00));
(byte) (percentCommand.shortValue() * 255.00 / 100.00));
} else if (command.equals(OnOffType.ON)) {
commandSEND(SoulissProtocolConstants.SOULISS_T1N_ON_CMD);

View File

@@ -88,8 +88,8 @@ public class SoulissT22Handler extends SoulissGenericHandler {
}
public void setState(PrimitiveType state) {
if (state instanceof PercentType) {
this.updateState(SoulissBindingConstants.ROLLERSHUTTER_CHANNEL, (PercentType) state);
if (state instanceof PercentType percentCommand) {
this.updateState(SoulissBindingConstants.ROLLERSHUTTER_CHANNEL, percentCommand);
}
}

View File

@@ -119,8 +119,8 @@ public class SoulissT31Handler extends SoulissGenericHandler {
}
break;
case SoulissBindingConstants.T31_SETPOINT_CHANNEL:
if (command instanceof QuantityType<?>) {
int uu = HalfFloatUtils.fromFloat(((QuantityType<?>) command).floatValue());
if (command instanceof QuantityType<?> quantityCommand) {
int uu = HalfFloatUtils.fromFloat(quantityCommand.floatValue());
byte b2 = (byte) (uu >> 8);
byte b1 = (byte) uu;
// setpoint command
@@ -151,7 +151,7 @@ public class SoulissT31Handler extends SoulissGenericHandler {
this.updateState(SoulissBindingConstants.T31_BUTTON_CHANNEL, OnOffType.OFF);
super.setLastStatusStored();
if (state instanceof StringType) {
if (state instanceof StringType stringState) {
switch (state.toString()) {
case SoulissBindingConstants.T31_FANLOW_MESSAGE_FAN_CHANNEL:
case SoulissBindingConstants.T31_FANMEDIUM_MESSAGE_FAN_CHANNEL:
@@ -159,48 +159,48 @@ public class SoulissT31Handler extends SoulissGenericHandler {
case SoulissBindingConstants.T31_FANAUTO_MESSAGE_FAN_CHANNEL:
case SoulissBindingConstants.T31_FANOFF_MESSAGE_FAN_CHANNEL:
if (!fanStateValue.equals(state)) {
this.updateState(SoulissBindingConstants.T31_FAN_CHANNEL, (StringType) state);
fanStateValue = (StringType) state;
this.updateState(SoulissBindingConstants.T31_FAN_CHANNEL, stringState);
fanStateValue = stringState;
}
break;
case SoulissBindingConstants.T31_HEATINGMODE_MESSAGE_MODE_CHANNEL:
if (!modeStateValue.equals(state)) {
this.updateState(SoulissBindingConstants.T31_MODE_CHANNEL, (StringType) state);
modeStateValue = (StringType) state;
this.updateState(SoulissBindingConstants.T31_MODE_CHANNEL, stringState);
modeStateValue = stringState;
}
break;
case SoulissBindingConstants.T31_COOLINGMODE_MESSAGE_MODE_CHANNEL:
if (!modeStateValue.equals(state)) {
this.updateState(SoulissBindingConstants.T31_MODE_CHANNEL, (StringType) state);
modeStateValue = (StringType) state;
this.updateState(SoulissBindingConstants.T31_MODE_CHANNEL, stringState);
modeStateValue = stringState;
}
break;
case SoulissBindingConstants.T31_OFF_MESSAGE_SYSTEM_CHANNEL:
if (!powerState.equals(state)) {
this.updateState(SoulissBindingConstants.T31_SYSTEM_CHANNEL, OnOffType.OFF);
powerState = (StringType) state;
powerState = stringState;
}
break;
case SoulissBindingConstants.T31_ON_MESSAGE_SYSTEM_CHANNEL:
if (!powerState.equals(state)) {
this.updateState(SoulissBindingConstants.T31_SYSTEM_CHANNEL, OnOffType.ON);
powerState = (StringType) state;
powerState = stringState;
}
break;
case SoulissBindingConstants.T31_ON_MESSAGE_FIRE_CHANNEL:
if (!fireState.equals(state)) {
this.updateState(SoulissBindingConstants.T31_FIRE_CHANNEL, OnOffType.ON);
fireState = (StringType) state;
fireState = stringState;
}
break;
case SoulissBindingConstants.T31_OFF_MESSAGE_FIRE_CHANNEL:
if (!fireState.equals(state)) {
this.updateState(SoulissBindingConstants.T31_FIRE_CHANNEL, OnOffType.OFF);
fireState = (StringType) state;
fireState = stringState;
}
break;

View File

@@ -75,8 +75,8 @@ public class SoulissT41Handler extends SoulissGenericHandler {
}
public void setState(PrimitiveType state) {
if (state instanceof OnOffType) {
this.updateState(SoulissBindingConstants.T4N_ONOFFALARM_CHANNEL, (OnOffType) state);
if (state instanceof OnOffType onOffState) {
this.updateState(SoulissBindingConstants.T4N_ONOFFALARM_CHANNEL, onOffState);
} else if (state instanceof StringType) {
switch (String.valueOf(state)) {
case SoulissBindingConstants.T4N_ALARMON_MESSAGE_CHANNEL:

View File

@@ -40,8 +40,8 @@ public class SoulissT6nHandler extends SoulissGenericHandler {
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
if (command instanceof DecimalType) {
int uu = HalfFloatUtils.fromFloat(((DecimalType) command).floatValue());
if (command instanceof DecimalType decimalCommand) {
int uu = HalfFloatUtils.fromFloat(decimalCommand.floatValue());
byte b2 = (byte) (uu >> 8);
byte b1 = (byte) uu;
// setpoint command

View File

@@ -136,7 +136,7 @@ public class SendDispatcherRunnable implements Runnable {
public void run() {
DatagramSocket sender = null;
try (var channel = DatagramChannel.open();) {
try (var channel = DatagramChannel.open()) {
if (checkTime()) {
PacketStruct sp = pop();
if (sp != null) {