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:
@@ -81,8 +81,8 @@ public class SpotifyHandlerFactory extends BaseThingHandlerFactory {
|
||||
|
||||
@Override
|
||||
protected synchronized void removeHandler(ThingHandler thingHandler) {
|
||||
if (thingHandler instanceof SpotifyBridgeHandler) {
|
||||
authService.removeSpotifyAccountHandler((SpotifyBridgeHandler) thingHandler);
|
||||
if (thingHandler instanceof SpotifyBridgeHandler bridgeHandler) {
|
||||
authService.removeSpotifyAccountHandler(bridgeHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,8 +87,8 @@ class SpotifyConnector {
|
||||
} catch (ExecutionException e) {
|
||||
final Throwable cause = e.getCause();
|
||||
|
||||
if (cause instanceof RuntimeException) {
|
||||
throw (RuntimeException) cause;
|
||||
if (cause instanceof RuntimeException runtimeException) {
|
||||
throw runtimeException;
|
||||
} else {
|
||||
throw new SpotifyException(e.getMessage(), e);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import static org.openhab.binding.spotify.internal.SpotifyBindingConstants.PROPE
|
||||
import static org.openhab.binding.spotify.internal.SpotifyBindingConstants.THING_TYPE_DEVICE;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -52,7 +51,7 @@ public class SpotifyDeviceDiscoveryService extends AbstractDiscoveryService
|
||||
// id for device is derived by stripping id of device with this length
|
||||
private static final int PLAYER_ID_LENGTH = 4;
|
||||
// Only devices can be discovered. A bridge must be manually added.
|
||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_DEVICE);
|
||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_DEVICE);
|
||||
// The call to listDevices is fast
|
||||
private static final int DISCOVERY_TIME_SECONDS = 10;
|
||||
// Check every minute for new devices
|
||||
@@ -90,8 +89,8 @@ public class SpotifyDeviceDiscoveryService extends AbstractDiscoveryService
|
||||
|
||||
@Override
|
||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||
if (handler instanceof SpotifyAccountHandler) {
|
||||
bridgeHandler = (SpotifyAccountHandler) handler;
|
||||
if (handler instanceof SpotifyAccountHandler accountHandler) {
|
||||
bridgeHandler = accountHandler;
|
||||
bridgeUID = bridgeHandler.getUID();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,8 +101,8 @@ class SpotifyHandleCommands {
|
||||
commandRun = handleDevicePlay(command, active, deviceId);
|
||||
break;
|
||||
case CHANNEL_DEVICESHUFFLE:
|
||||
if (command instanceof OnOffType) {
|
||||
spotifyApi.setShuffleState(deviceId, (OnOffType) command);
|
||||
if (command instanceof OnOffType onOffCommand) {
|
||||
spotifyApi.setShuffleState(deviceId, onOffCommand);
|
||||
commandRun = true;
|
||||
}
|
||||
break;
|
||||
@@ -112,9 +112,9 @@ class SpotifyHandleCommands {
|
||||
commandRun = true;
|
||||
}
|
||||
case CHANNEL_DEVICEVOLUME:
|
||||
if (command instanceof DecimalType) {
|
||||
final PercentType volume = command instanceof PercentType ? (PercentType) command
|
||||
: new PercentType(((DecimalType) command).intValue());
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
final PercentType volume = command instanceof PercentType percentType ? percentType
|
||||
: new PercentType(decimalCommand.intValue());
|
||||
|
||||
spotifyApi.setVolume(deviceId, volume.intValue());
|
||||
commandRun = true;
|
||||
|
||||
Reference in New Issue
Block a user