Java 17 features (H-M) (#15520)

- 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-08 14:36:59 +02:00
committed by GitHub
parent 3751fd0646
commit edaf17b345
519 changed files with 2703 additions and 2660 deletions

View File

@@ -75,10 +75,10 @@ public class KodiAudioSink extends AudioSinkSync {
public @NonNull CompletableFuture<@Nullable Void> processAndComplete(@Nullable AudioStream audioStream) {
// we override this method to intercept URLAudioStream and handle it asynchronously. We won't wait for it to
// play through the end as it can be very long
if (audioStream instanceof URLAudioStream) {
if (audioStream instanceof URLAudioStream stream) {
// Asynchronous handling for URLAudioStream. Id it is an external URL, the speaker can access it itself and
// play it. There will be no volume restoration or call to dispose / complete, but there is no need to.
String url = ((URLAudioStream) audioStream).getURL();
String url = stream.getURL();
AudioFormat format = audioStream.getFormat();
logger.trace("Processing audioStream URL {} of format {}.", url, format);
handler.playURI(new StringType(url));

View File

@@ -12,7 +12,6 @@
*/
package org.openhab.binding.kodi.internal;
import java.util.Collections;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -34,7 +33,7 @@ public class KodiBindingConstants {
// List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_KODI = new ThingTypeUID(BINDING_ID, "kodi");
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_KODI);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_KODI);
// List of thing parameters names
public static final String HOST_PARAMETER = "ipAddress";

View File

@@ -82,10 +82,8 @@ public class KodiUpnpDiscoveryParticipant implements UpnpDiscoveryParticipant {
Map<String, Object> properties = new HashMap<>();
properties.put(HOST_PARAMETER, device.getIdentity().getDescriptorURL().getHost());
DiscoveryResult result = DiscoveryResultBuilder.create(thingUid).withLabel(label)
.withProperties(properties).withRepresentationProperty(HOST_PARAMETER).build();
return result;
return DiscoveryResultBuilder.create(thingUid).withLabel(label).withProperties(properties)
.withRepresentationProperty(HOST_PARAMETER).build();
}
}
return null;

View File

@@ -134,8 +134,8 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener {
private int getIntConfigParameter(String key, int defaultValue) {
Object obj = this.getConfig().get(key);
if (obj instanceof Number) {
return ((Number) obj).intValue();
if (obj instanceof Number numberValue) {
return numberValue.intValue();
} else if (obj instanceof String) {
return Integer.parseInt(obj.toString());
}
@@ -160,8 +160,8 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener {
}
break;
case CHANNEL_VOLUME:
if (command instanceof PercentType) {
connection.setVolume(((PercentType) command).intValue());
if (command instanceof PercentType percentCommand) {
connection.setVolume(percentCommand.intValue());
} else if (command.equals(IncreaseDecreaseType.INCREASE)) {
connection.increaseVolume();
} else if (command.equals(IncreaseDecreaseType.DECREASE)) {
@@ -213,8 +213,8 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener {
}
break;
case CHANNEL_PLAYNOTIFICATION:
if (command instanceof StringType) {
playNotificationSoundURI((StringType) command, true);
if (command instanceof StringType stringCommand) {
playNotificationSoundURI(stringCommand, true);
updateState(CHANNEL_PLAYNOTIFICATION, UnDefType.UNDEF);
} else if (command.equals(RefreshType.REFRESH)) {
updateState(CHANNEL_PLAYNOTIFICATION, UnDefType.UNDEF);
@@ -307,14 +307,14 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener {
case CHANNEL_AUDIO_CODEC:
break;
case CHANNEL_AUDIO_INDEX:
if (command instanceof DecimalType) {
connection.setAudioStream(((DecimalType) command).intValue());
if (command instanceof DecimalType decimalCommand) {
connection.setAudioStream(decimalCommand.intValue());
}
break;
case CHANNEL_VIDEO_CODEC:
case CHANNEL_VIDEO_INDEX:
if (command instanceof DecimalType) {
connection.setVideoStream(((DecimalType) command).intValue());
if (command instanceof DecimalType decimalCommand) {
connection.setVideoStream(decimalCommand.intValue());
}
break;
case CHANNEL_SUBTITLE_ENABLED:
@@ -325,13 +325,13 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener {
}
break;
case CHANNEL_SUBTITLE_INDEX:
if (command instanceof DecimalType) {
connection.setSubtitle(((DecimalType) command).intValue());
if (command instanceof DecimalType decimalCommand) {
connection.setSubtitle(decimalCommand.intValue());
}
break;
case CHANNEL_CURRENTTIME:
if (command instanceof QuantityType) {
connection.setTime(((QuantityType<?>) command).intValue());
if (command instanceof QuantityType quantityCommand) {
connection.setTime(quantityCommand.intValue());
}
break;
case CHANNEL_CURRENTTIMEPERCENTAGE:

View File

@@ -184,9 +184,7 @@ public class KodiConnection implements KodiClientSocketEventListener {
private synchronized JsonArray getPlaylistsInternal() {
String method = "Playlist.GetPlaylists";
String hash = hostname + '#' + method;
JsonElement response = REQUEST_CACHE.putIfAbsentAndGet(hash, () -> {
return socket.callMethod(method);
});
JsonElement response = REQUEST_CACHE.putIfAbsentAndGet(hash, () -> socket.callMethod(method));
if (response instanceof JsonArray) {
return response.getAsJsonArray();