Java 17 features (T-Z) (#15576)

- 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-21 07:58:53 +02:00
committed by GitHub
parent bf1aa3deb2
commit 1b122a53b9
277 changed files with 1402 additions and 1298 deletions

View File

@@ -55,7 +55,6 @@ public class WlanThermoEsp32CommandHandler {
public static State getState(ChannelUID channelUID, Data data, Settings settings)
throws WlanThermoUnknownChannelException, WlanThermoInputException {
String groupId = requireNonNull(channelUID.getGroupId());
System system = data.getSystem();
Unit<Temperature> unit = "F".equals(system.getUnit()) ? ImperialUnits.FAHRENHEIT : SIUnits.CELSIUS;
@@ -186,9 +185,9 @@ public class WlanThermoEsp32CommandHandler {
}
return false;
case CHANNEL_MIN:
if (command instanceof QuantityType) {
if (command instanceof QuantityType quantityCommand) {
try {
channel.setMin(requireNonNull(((QuantityType<?>) command).toUnit(unit)).doubleValue());
channel.setMin(requireNonNull(quantityCommand.toUnit(unit)).doubleValue());
return true;
} catch (WlanThermoInputException ignore) {
return false;
@@ -196,9 +195,9 @@ public class WlanThermoEsp32CommandHandler {
}
return false;
case CHANNEL_MAX:
if (command instanceof QuantityType) {
if (command instanceof QuantityType quantityCommand) {
try {
channel.setMax(requireNonNull(((QuantityType<?>) command).toUnit(unit)).doubleValue());
channel.setMax(requireNonNull(quantityCommand.toUnit(unit)).doubleValue());
return true;
} catch (WlanThermoInputException ignore) {
return false;
@@ -230,14 +229,14 @@ public class WlanThermoEsp32CommandHandler {
}
return false;
case CHANNEL_COLOR_NAME:
if (command instanceof StringType) {
channel.setColor(WlanThermoEsp32Util.toHex(((StringType) command).toString()));
if (command instanceof StringType stringCommand) {
channel.setColor(WlanThermoEsp32Util.toHex(stringCommand.toString()));
return true;
}
return false;
case CHANNEL_COLOR:
if (command instanceof HSBType) {
channel.setColor(WlanThermoUtil.toHex((HSBType) command));
if (command instanceof HSBType hsbCommand) {
channel.setColor(WlanThermoUtil.toHex(hsbCommand));
return true;
}
return false;
@@ -264,8 +263,8 @@ public class WlanThermoEsp32CommandHandler {
}
case CHANNEL_PITMASTER_STATE:
String state = ((StringType) command).toString();
if (state.equalsIgnoreCase("off") || state.equalsIgnoreCase("manual")
|| state.equalsIgnoreCase("auto")) {
if ("off".equalsIgnoreCase(state) || "manual".equalsIgnoreCase(state)
|| "auto".equalsIgnoreCase(state)) {
pm.setTyp(state);
return true;
}

View File

@@ -134,7 +134,7 @@ public class WlanThermoMiniCommandHandler {
case WlanThermoBindingConstants.CHANNEL_PITMASTER_DUTY_CYCLE:
return new DecimalType(pit.getControlOut());
case WlanThermoBindingConstants.CHANNEL_PITMASTER_LID_OPEN:
return OnOffType.from(pit.getOpenLid().equals("True"));
return OnOffType.from("True".equals(pit.getOpenLid()));
case WlanThermoBindingConstants.CHANNEL_PITMASTER_CHANNEL_ID:
return new DecimalType(pit.getCh());
}

View File

@@ -130,7 +130,7 @@ public class WlanThermoNanoV1CommandHandler {
}
} else if (channelUID.getId().startsWith(CHANNEL_PITMASTER_1)) {
if (data.getPitmaster() != null && data.getPitmaster().getPm() != null
&& data.getPitmaster().getPm().size() > 0) {
&& !data.getPitmaster().getPm().isEmpty()) {
Pm pm = data.getPitmaster().getPm().get(0);
switch (channelUID.getIdWithoutGroup()) {
case CHANNEL_PITMASTER_CHANNEL_ID:
@@ -175,9 +175,9 @@ public class WlanThermoNanoV1CommandHandler {
}
return false;
case CHANNEL_MIN:
if (command instanceof QuantityType) {
if (command instanceof QuantityType quantityCommand) {
try {
channel.setMin(requireNonNull(((QuantityType<?>) command).toUnit(unit)).doubleValue());
channel.setMin(requireNonNull(quantityCommand.toUnit(unit)).doubleValue());
return true;
} catch (WlanThermoInputException ignore) {
return false;
@@ -185,9 +185,9 @@ public class WlanThermoNanoV1CommandHandler {
}
return false;
case CHANNEL_MAX:
if (command instanceof QuantityType) {
if (command instanceof QuantityType quantityCommand) {
try {
channel.setMax(requireNonNull(((QuantityType<?>) command).toUnit(unit)).doubleValue());
channel.setMax(requireNonNull(quantityCommand.toUnit(unit)).doubleValue());
return true;
} catch (WlanThermoInputException ignore) {
return false;
@@ -219,8 +219,8 @@ public class WlanThermoNanoV1CommandHandler {
}
return false;
case CHANNEL_COLOR_NAME:
if (command instanceof StringType) {
channel.setColor(WlanThermoNanoV1Util.toHex(((StringType) command).toString()));
if (command instanceof StringType stringCommand) {
channel.setColor(WlanThermoNanoV1Util.toHex(stringCommand.toString()));
return true;
}
return false;
@@ -228,7 +228,7 @@ public class WlanThermoNanoV1CommandHandler {
}
} else if (channelUID.getId().startsWith(CHANNEL_PITMASTER_1)) {
if (data.getPitmaster() != null && data.getPitmaster().getPm() != null
&& data.getPitmaster().getPm().size() > 0) {
&& !data.getPitmaster().getPm().isEmpty()) {
Pm pm = data.getPitmaster().getPm().get(0);
switch (channelUID.getIdWithoutGroup()) {
case CHANNEL_PITMASTER_CHANNEL_ID:
@@ -246,8 +246,8 @@ public class WlanThermoNanoV1CommandHandler {
}
case CHANNEL_PITMASTER_STATE:
String state = ((StringType) command).toString();
if (state.equalsIgnoreCase("off") || state.equalsIgnoreCase("manual")
|| state.equalsIgnoreCase("auto")) {
if ("off".equalsIgnoreCase(state) || "manual".equalsIgnoreCase(state)
|| "auto".equalsIgnoreCase(state)) {
pm.setTyp(state);
return true;
}
@@ -260,7 +260,6 @@ public class WlanThermoNanoV1CommandHandler {
public static String getTrigger(ChannelUID channelUID, Data data)
throws WlanThermoUnknownChannelException, WlanThermoInputException {
String groupId = requireNonNull(channelUID.getGroupId());
List<Channel> channelList = data.getChannel();