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:
@@ -14,7 +14,6 @@ package org.openhab.binding.mpd.internal;
|
||||
|
||||
import static org.openhab.binding.mpd.internal.MPDBindingConstants.THING_TYPE_MPD;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@@ -37,7 +36,7 @@ import org.osgi.service.component.annotations.Component;
|
||||
@Component(configurationPid = "binding.mpd", service = ThingHandlerFactory.class)
|
||||
public class MPDHandlerFactory extends BaseThingHandlerFactory {
|
||||
|
||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_MPD);
|
||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_MPD);
|
||||
|
||||
@Override
|
||||
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
|
||||
|
||||
@@ -38,8 +38,8 @@ public class MPDActions implements ThingActions {
|
||||
|
||||
@Override
|
||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||
if (handler instanceof MPDHandler) {
|
||||
this.handler = (MPDHandler) handler;
|
||||
if (handler instanceof MPDHandler mpdHandler) {
|
||||
this.handler = mpdHandler;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
package org.openhab.binding.mpd.internal.discovery;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -46,7 +45,7 @@ public class MPDDiscoveryParticipant implements MDNSDiscoveryParticipant {
|
||||
|
||||
@Override
|
||||
public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
|
||||
return Collections.singleton(MPDBindingConstants.THING_TYPE_MPD);
|
||||
return Set.of(MPDBindingConstants.THING_TYPE_MPD);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,9 +75,8 @@ public class MPDDiscoveryParticipant implements MDNSDiscoveryParticipant {
|
||||
|
||||
String name = service.getName();
|
||||
|
||||
final DiscoveryResult result = DiscoveryResultBuilder.create(uid).withLabel(name).withProperties(properties)
|
||||
return DiscoveryResultBuilder.create(uid).withLabel(name).withProperties(properties)
|
||||
.withRepresentationProperty(MPDBindingConstants.UNIQUE_ID).build();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -111,7 +112,7 @@ public class MPDHandler extends BaseThingHandler implements MPDEventListener {
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||
return Collections.singleton(MPDActions.class);
|
||||
return Set.of(MPDActions.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -232,10 +233,10 @@ public class MPDHandler extends BaseThingHandler implements MPDEventListener {
|
||||
} else if (command == OnOffType.OFF) {
|
||||
newValue = 0;
|
||||
}
|
||||
} else if (command instanceof DecimalType) {
|
||||
newValue = ((DecimalType) command).intValue();
|
||||
} else if (command instanceof PercentType) {
|
||||
newValue = ((PercentType) command).intValue();
|
||||
} else if (command instanceof DecimalType decimalCommand) {
|
||||
newValue = decimalCommand.intValue();
|
||||
} else if (command instanceof PercentType percentCommand) {
|
||||
newValue = percentCommand.intValue();
|
||||
} else {
|
||||
logger.debug("Command {} is not supported to change volume", command);
|
||||
return;
|
||||
|
||||
@@ -82,7 +82,7 @@ public class MPDCommand {
|
||||
for (String param : parameters) {
|
||||
builder.append(" ");
|
||||
builder.append("\"");
|
||||
builder.append(param.replaceAll("\"", "\\\\\"").replaceAll("'", "\\\\'"));
|
||||
builder.append(param.replace("\"", "\\\\\"").replace("'", "\\\\'"));
|
||||
builder.append("\"");
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ public class MPDCommand {
|
||||
if ("password".equals(command)) {
|
||||
builder.append(param.replaceAll(".", "."));
|
||||
} else {
|
||||
builder.append(param.replaceAll("\"", "\\\\\"").replaceAll("'", "\\\\'"));
|
||||
builder.append(param.replace("\"", "\\\\\"").replace("'", "\\\\'"));
|
||||
}
|
||||
builder.append("\"");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user