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:
@@ -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 {
|
||||
|
||||
@@ -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())));
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user