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:
@@ -14,7 +14,6 @@ package org.openhab.binding.samsungtv.internal;
|
||||
|
||||
import static org.openhab.binding.samsungtv.internal.SamsungTvBindingConstants.SAMSUNG_TV_THING_TYPE;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@@ -42,7 +41,7 @@ import org.osgi.service.component.annotations.Reference;
|
||||
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.samsungtv")
|
||||
public class SamsungTvHandlerFactory extends BaseThingHandlerFactory {
|
||||
|
||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(SAMSUNG_TV_THING_TYPE);
|
||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(SAMSUNG_TV_THING_TYPE);
|
||||
|
||||
private @NonNullByDefault({}) UpnpIOService upnpIOService;
|
||||
private @NonNullByDefault({}) UpnpService upnpService;
|
||||
|
||||
@@ -48,9 +48,9 @@ public class WakeOnLanUtility {
|
||||
static {
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
LOGGER.debug("os: {}", os);
|
||||
if ((os.indexOf("win") >= 0)) {
|
||||
if ((os.contains("win"))) {
|
||||
COMMAND = "arp -a %s";
|
||||
} else if ((os.indexOf("mac") >= 0)) {
|
||||
} else if ((os.contains("mac"))) {
|
||||
COMMAND = "arp %s";
|
||||
} else { // linux
|
||||
if (checkIfLinuxCommandExists("arp")) {
|
||||
|
||||
@@ -15,7 +15,6 @@ package org.openhab.binding.samsungtv.internal.discovery;
|
||||
import static org.openhab.binding.samsungtv.internal.SamsungTvBindingConstants.SAMSUNG_TV_THING_TYPE;
|
||||
import static org.openhab.binding.samsungtv.internal.config.SamsungTvConfiguration.HOST_NAME;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -46,7 +45,7 @@ public class SamsungTvDiscoveryParticipant implements UpnpDiscoveryParticipant {
|
||||
|
||||
@Override
|
||||
public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
|
||||
return Collections.singleton(SAMSUNG_TV_THING_TYPE);
|
||||
return Set.of(SAMSUNG_TV_THING_TYPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -45,8 +45,8 @@ public class DataConverters {
|
||||
value = Math.min(max, currentValue + 1);
|
||||
} else if (command instanceof IncreaseDecreaseType && command == IncreaseDecreaseType.DECREASE) {
|
||||
value = Math.max(min, currentValue - 1);
|
||||
} else if (command instanceof DecimalType) {
|
||||
value = ((DecimalType) command).intValue();
|
||||
} else if (command instanceof DecimalType decimalCommand) {
|
||||
value = decimalCommand.intValue();
|
||||
} else {
|
||||
throw new NumberFormatException("Command '" + command + "' not supported");
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ public class MediaRendererService implements UpnpIOParticipant, SamsungTvService
|
||||
case "CurrentMute":
|
||||
State newState = UnDefType.UNDEF;
|
||||
if (value != null) {
|
||||
newState = value.equals("true") ? OnOffType.ON : OnOffType.OFF;
|
||||
newState = "true".equals(value) ? OnOffType.ON : OnOffType.OFF;
|
||||
}
|
||||
listener.valueReceived(MUTE, newState);
|
||||
break;
|
||||
|
||||
@@ -265,8 +265,7 @@ public class RemoteControllerService implements SamsungTvService, RemoteControll
|
||||
|
||||
KeyCode key = null;
|
||||
|
||||
if (remoteController instanceof RemoteControllerWebSocket) {
|
||||
RemoteControllerWebSocket remoteControllerWebSocket = (RemoteControllerWebSocket) remoteController;
|
||||
if (remoteController instanceof RemoteControllerWebSocket remoteControllerWebSocket) {
|
||||
switch (channel) {
|
||||
case BROWSER_URL:
|
||||
if (command instanceof StringType) {
|
||||
@@ -372,8 +371,8 @@ public class RemoteControllerService implements SamsungTvService, RemoteControll
|
||||
return;
|
||||
|
||||
case CHANNEL:
|
||||
if (command instanceof DecimalType) {
|
||||
int val = ((DecimalType) command).intValue();
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
int val = decimalCommand.intValue();
|
||||
int num4 = val / 1000 % 10;
|
||||
int num3 = val / 100 % 10;
|
||||
int num2 = val / 10 % 10;
|
||||
@@ -419,8 +418,8 @@ public class RemoteControllerService implements SamsungTvService, RemoteControll
|
||||
|
||||
private void sendKeyCodePress(KeyCode key) {
|
||||
try {
|
||||
if (remoteController != null && remoteController instanceof RemoteControllerWebSocket) {
|
||||
((RemoteControllerWebSocket) remoteController).sendKeyPress(key);
|
||||
if (remoteController instanceof RemoteControllerWebSocket remoteControllerWebSocket) {
|
||||
remoteControllerWebSocket.sendKeyPress(key);
|
||||
}
|
||||
} catch (RemoteControllerException e) {
|
||||
reportError(String.format("Could not send command to device on %s:%d", host, port), e);
|
||||
|
||||
Reference in New Issue
Block a user