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

@@ -252,9 +252,9 @@ abstract class SonyAudioHandler extends BaseThingHandler implements SonyAudioEve
updateState(channelUID, new StringType(result.get("soundField")));
}
}
if (command instanceof StringType) {
if (command instanceof StringType stringCommand) {
logger.debug("handleSoundSettings set {}", command);
connection.setSoundSettings("soundField", ((StringType) command).toString());
connection.setSoundSettings("soundField", stringCommand.toString());
}
}
@@ -266,9 +266,9 @@ abstract class SonyAudioHandler extends BaseThingHandler implements SonyAudioEve
updateState(channelUID, new StringType(result.get("nightMode")));
}
}
if (command instanceof OnOffType) {
if (command instanceof OnOffType onOffCommand) {
logger.debug("handleNightMode set {}", command);
connection.setSoundSettings("nightMode", ((OnOffType) command) == OnOffType.ON ? "on" : "off");
connection.setSoundSettings("nightMode", onOffCommand == OnOffType.ON ? "on" : "off");
}
}
@@ -286,9 +286,9 @@ abstract class SonyAudioHandler extends BaseThingHandler implements SonyAudioEve
throw new IOException(ex.getCause());
}
}
if (command instanceof OnOffType) {
if (command instanceof OnOffType onOffCommand) {
logger.debug("handlePowerCommand set {} {}", zone, command);
connection.setPower(((OnOffType) command) == OnOffType.ON, zone);
connection.setPower(onOffCommand == OnOffType.ON, zone);
}
}
@@ -338,18 +338,18 @@ abstract class SonyAudioHandler extends BaseThingHandler implements SonyAudioEve
throw new IOException(ex.getCause());
}
}
if (command instanceof PercentType) {
if (command instanceof PercentType percentCommand) {
logger.debug("handleVolumeCommand PercentType set {} {}", zone, command);
connection.setVolume(((PercentType) command).intValue(), zone);
connection.setVolume(percentCommand.intValue(), zone);
}
if (command instanceof IncreaseDecreaseType) {
logger.debug("handleVolumeCommand IncreaseDecreaseType set {} {}", zone, command);
String change = command == IncreaseDecreaseType.INCREASE ? "+1" : "-1";
connection.setVolume(change, zone);
}
if (command instanceof OnOffType) {
if (command instanceof OnOffType onOffCommand) {
logger.debug("handleVolumeCommand OnOffType set {} {}", zone, command);
connection.setMute(((OnOffType) command) == OnOffType.ON, zone);
connection.setMute(onOffCommand == OnOffType.ON, zone);
}
}
@@ -369,9 +369,9 @@ abstract class SonyAudioHandler extends BaseThingHandler implements SonyAudioEve
throw new IOException(ex.getCause());
}
}
if (command instanceof OnOffType) {
if (command instanceof OnOffType onOffCommand) {
logger.debug("handleMuteCommand set {} {}", zone, command);
connection.setMute(((OnOffType) command) == OnOffType.ON, zone);
connection.setMute(onOffCommand == OnOffType.ON, zone);
}
}
@@ -382,8 +382,8 @@ abstract class SonyAudioHandler extends BaseThingHandler implements SonyAudioEve
if (command instanceof RefreshType) {
updateState(channelUID, new DecimalType(currentRadioStation));
}
if (command instanceof DecimalType) {
currentRadioStation = ((DecimalType) command).intValue();
if (command instanceof DecimalType decimalCommand) {
currentRadioStation = decimalCommand.intValue();
String radioCommand = "radio:fm?contentId=" + currentRadioStation;
for (int i = 1; i <= 4; i++) {
@@ -399,8 +399,8 @@ abstract class SonyAudioHandler extends BaseThingHandler implements SonyAudioEve
if (command instanceof RefreshType) {
updateState(channelUID, new StringType(""));
}
if (command instanceof StringType) {
switch (((StringType) command).toString()) {
if (command instanceof StringType stringCommand) {
switch (stringCommand.toString()) {
case "fwdSeeking":
connection.radioSeekFwd();
break;
@@ -420,16 +420,16 @@ abstract class SonyAudioHandler extends BaseThingHandler implements SonyAudioEve
String path = (String) config.get(SonyAudioBindingConstants.SCALAR_PATH_PARAMETER);
Object port_o = config.get(SonyAudioBindingConstants.SCALAR_PORT_PARAMETER);
int port = 10000;
if (port_o instanceof BigDecimal) {
port = ((BigDecimal) port_o).intValue();
if (port_o instanceof BigDecimal decimalValue) {
port = decimalValue.intValue();
} else if (port_o instanceof Integer) {
port = (int) port_o;
}
Object refresh_o = config.get(SonyAudioBindingConstants.REFRESHINTERVAL);
int refresh = 0;
if (refresh_o instanceof BigDecimal) {
refresh = ((BigDecimal) refresh_o).intValue();
if (refresh_o instanceof BigDecimal decimalValue) {
refresh = decimalValue.intValue();
} else if (refresh_o instanceof Integer) {
refresh = (int) refresh_o;
}

View File

@@ -91,7 +91,7 @@ public class SrsZr5Handler extends SonyAudioHandler {
if (result != null) {
logger.debug("SrsZr5Handler Updating sound field to {} {}", result.get("clearAudio"),
result.get("soundField"));
if (result.get("clearAudio").equalsIgnoreCase("on")) {
if ("on".equalsIgnoreCase(result.get("clearAudio"))) {
updateState(channelUID, new StringType("clearAudio"));
} else {
updateState(channelUID, new StringType(result.get("soundField")));
@@ -101,11 +101,11 @@ public class SrsZr5Handler extends SonyAudioHandler {
throw new IOException(ex.getCause());
}
}
if (command instanceof StringType) {
if (((StringType) command).toString().equalsIgnoreCase("clearAudio")) {
if (command instanceof StringType stringCommand) {
if ("clearAudio".equalsIgnoreCase(stringCommand.toString())) {
connection.setSoundSettings("clearAudio", "on");
} else {
connection.setSoundSettings("soundField", ((StringType) command).toString());
connection.setSoundSettings("soundField", stringCommand.toString());
}
}
}

View File

@@ -127,7 +127,7 @@ public class StrDn1080Handler extends SonyAudioHandler {
if (result != null) {
logger.debug("StrDn1080Handler Updateing sound field to {} {}", result.get("pureDirect"),
result.get("soundField"));
if (result.get("pureDirect").equalsIgnoreCase("on")) {
if ("on".equalsIgnoreCase(result.get("pureDirect"))) {
updateState(channelUID, new StringType("pureDirect"));
} else {
updateState(channelUID, new StringType(result.get("soundField")));
@@ -137,11 +137,11 @@ public class StrDn1080Handler extends SonyAudioHandler {
throw new IOException(ex.getCause());
}
}
if (command instanceof StringType) {
if (((StringType) command).toString().equalsIgnoreCase("pureDirect")) {
if (command instanceof StringType stringCommand) {
if ("pureDirect".equalsIgnoreCase(stringCommand.toString())) {
connection.setSoundSettings("pureDirect", "on");
} else {
connection.setSoundSettings("soundField", ((StringType) command).toString());
connection.setSoundSettings("soundField", stringCommand.toString());
}
}
}

View File

@@ -118,7 +118,7 @@ public class SonyAudioConnection implements SonyAudioClientSocketEventListener {
}
}
if (json.get("method").getAsString().equalsIgnoreCase("notifyPlayingContentInfo")) {
if ("notifyPlayingContentInfo".equalsIgnoreCase(json.get("method").getAsString())) {
SonyAudioInput input = new SonyAudioInput();
input.input = param.get("uri").getAsString();
if (param.has("broadcastFreq")) {
@@ -130,19 +130,19 @@ public class SonyAudioConnection implements SonyAudioClientSocketEventListener {
listener.updateSeekStation("");
}
if (json.get("method").getAsString().equalsIgnoreCase("notifyVolumeInformation")) {
if ("notifyVolumeInformation".equalsIgnoreCase(json.get("method").getAsString())) {
SonyAudioVolume volume = new SonyAudioVolume();
int rawVolume = param.get("volume").getAsInt();
volume.volume = Math.round(100 * (rawVolume - min_volume) / (max_volume - min_volume));
volume.mute = param.get("mute").getAsString().equalsIgnoreCase("on");
volume.mute = "on".equalsIgnoreCase(param.get("mute").getAsString());
listener.updateVolume(zone, volume);
}
if (json.get("method").getAsString().equalsIgnoreCase("notifyPowerStatus")) {
if ("notifyPowerStatus".equalsIgnoreCase(json.get("method").getAsString())) {
String power = param.get("status").getAsString();
listener.updatePowerStatus(zone, power.equalsIgnoreCase("active"));
listener.updatePowerStatus(zone, "active".equalsIgnoreCase(power));
}
listener.updateConnectionState(true);
@@ -193,7 +193,7 @@ public class SonyAudioConnection implements SonyAudioClientSocketEventListener {
for (Iterator<Notification> iter = notifications.disabled.listIterator(); iter.hasNext();) {
Notification a = iter.next();
if (a.name.equalsIgnoreCase("notifyPlayingContentInfo")) {
if ("notifyPlayingContentInfo".equalsIgnoreCase(a.name)) {
notifications.enabled.add(a);
iter.remove();
}
@@ -209,7 +209,7 @@ public class SonyAudioConnection implements SonyAudioClientSocketEventListener {
for (Iterator<Notification> iter = notifications.disabled.listIterator(); iter.hasNext();) {
Notification a = iter.next();
if (a.name.equalsIgnoreCase("notifyVolumeInformation")) {
if ("notifyVolumeInformation".equalsIgnoreCase(a.name)) {
notifications.enabled.add(a);
iter.remove();
}
@@ -225,7 +225,7 @@ public class SonyAudioConnection implements SonyAudioClientSocketEventListener {
for (Iterator<Notification> iter = notifications.disabled.listIterator(); iter.hasNext();) {
Notification a = iter.next();
if (a.name.equalsIgnoreCase("notifyPowerStatus")) {
if ("notifyPowerStatus".equalsIgnoreCase(a.name)) {
notifications.enabled.add(a);
iter.remove();
}
@@ -294,7 +294,7 @@ public class SonyAudioConnection implements SonyAudioClientSocketEventListener {
JsonObject terminal = terminals.next().getAsJsonObject();
String uri = terminal.get("uri").getAsString();
if (uri.equalsIgnoreCase("extOutput:zone?zone=" + Integer.toString(zone))) {
return terminal.get("active").getAsString().equalsIgnoreCase("active") ? true : false;
return "active".equalsIgnoreCase(terminal.get("active").getAsString()) ? true : false;
}
}
}
@@ -310,7 +310,7 @@ public class SonyAudioConnection implements SonyAudioClientSocketEventListener {
if (element != null && element.isJsonArray()) {
String powerStatus = element.getAsJsonArray().get(0).getAsJsonObject().get("status").getAsString();
return powerStatus.equalsIgnoreCase("active") ? true : false;
return "active".equalsIgnoreCase(powerStatus) ? true : false;
}
throw new IOException("Unexpected responses: Unable to parse GetPowerStatus response message");
}
@@ -434,7 +434,7 @@ public class SonyAudioConnection implements SonyAudioClientSocketEventListener {
ret.volume = vol;
String mute = result.get("mute").getAsString();
ret.mute = mute.equalsIgnoreCase("on") ? true : false;
ret.mute = "on".equalsIgnoreCase(mute) ? true : false;
return ret;
}