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

@@ -78,9 +78,8 @@ public class ChromecastAudioSink extends AudioSinkAsync {
handler.stop();
} else {
final String url;
if (audioStream instanceof URLAudioStream) {
// it is an external URL, the speaker can access it itself and play it.
URLAudioStream urlAudioStream = (URLAudioStream) audioStream;
if (audioStream instanceof URLAudioStream urlAudioStream) {
// it is an external URL, the speaker can access it itself and play it
url = urlAudioStream.getURL();
tryClose(audioStream);
} else {

View File

@@ -158,18 +158,16 @@ public class ChromecastCommander {
return;
}
if (command instanceof PlayPauseType) {
if (command instanceof PlayPauseType playPauseCommand) {
MediaStatus mediaStatus = chromeCast.getMediaStatus();
logger.debug("mediaStatus {}", mediaStatus);
if (mediaStatus == null || mediaStatus.playerState == MediaStatus.PlayerState.IDLE) {
logger.debug("{} command ignored because media is not loaded", command);
return;
}
final PlayPauseType playPause = (PlayPauseType) command;
if (playPause == PlayPauseType.PLAY) {
if (playPauseCommand == PlayPauseType.PLAY) {
chromeCast.play();
} else if (playPause == PlayPauseType.PAUSE
} else if (playPauseCommand == PlayPauseType.PAUSE
&& ((mediaStatus.supportedMediaCommands & 0x00000001) == 0x1)) {
chromeCast.pause();
} else {
@@ -199,8 +197,8 @@ public class ChromecastCommander {
}
public void handleVolume(final Command command) {
if (command instanceof PercentType) {
setVolumeInternal((PercentType) command);
if (command instanceof PercentType percentCommand) {
setVolumeInternal(percentCommand);
} else if (command == IncreaseDecreaseType.INCREASE) {
setVolumeInternal(new PercentType(
Math.min(statusUpdater.getVolume().intValue() + VOLUMESTEP, PercentType.HUNDRED.intValue())));

View File

@@ -318,8 +318,8 @@ public class ChromecastStatusUpdater {
state = new DecimalType(((Integer) value).longValue());
} else if (value instanceof String) {
state = new StringType(value.toString());
} else if (value instanceof ZonedDateTime) {
state = new DateTimeType((ZonedDateTime) value);
} else if (value instanceof ZonedDateTime datetime) {
state = new DateTimeType(datetime);
} else {
state = UnDefType.UNDEF;
logger.warn("Update channel {}: Unsupported value type {}", channelUID, value.getClass().getSimpleName());

View File

@@ -82,8 +82,8 @@ public class ChromecastActions implements ThingActions {
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof ChromecastHandler) {
this.handler = (ChromecastHandler) handler;
if (handler instanceof ChromecastHandler chromecastHandler) {
this.handler = chromecastHandler;
}
}