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

@@ -12,7 +12,6 @@
*/
package org.openhab.binding.magentatv.internal;
import java.util.Collections;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -33,7 +32,7 @@ public class MagentaTVBindingConstants {
// List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_RECEIVER = new ThingTypeUID(BINDING_ID, "receiver");
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_RECEIVER);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_RECEIVER);
/**
* Property names for config/status properties

View File

@@ -58,7 +58,7 @@ public class MagentaTVDynamicConfig extends MagentaTVThingConfiguration {
}
public void setPort(String port) {
if (modelId.contains(MODEL_MR400) && port.equals("49153")) {
if (modelId.contains(MODEL_MR400) && "49153".equals(port)) {
// overwrite port returned by discovery (invalid for this model)
this.port = MR400_DEF_REMOTE_PORT;
} else {
@@ -84,7 +84,7 @@ public class MagentaTVDynamicConfig extends MagentaTVThingConfiguration {
public String getDescriptionUrl() {
if (descriptionUrl.equals(MR400_DEF_DESCRIPTION_URL)
&& !(port.equals(MR400_DEF_REMOTE_PORT) || port.equals("49153"))) {
&& !(port.equals(MR400_DEF_REMOTE_PORT) || "49153".equals(port))) {
// MR401B returns the wrong URL
return MR401B_DEF_DESCRIPTION_URL;
}

View File

@@ -16,7 +16,6 @@ import static org.openhab.binding.magentatv.internal.MagentaTVBindingConstants.*
import static org.openhab.binding.magentatv.internal.MagentaTVUtil.*;
import static org.openhab.core.thing.Thing.*;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
@@ -46,7 +45,7 @@ public class MagentaTVDiscoveryParticipant implements UpnpDiscoveryParticipant {
@Override
public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
return Collections.singleton(THING_TYPE_RECEIVER);
return Set.of(THING_TYPE_RECEIVER);
}
/**
@@ -74,7 +73,7 @@ public class MagentaTVDiscoveryParticipant implements UpnpDiscoveryParticipant {
.substring(device.getIdentity().getUdn().getIdentifierString().length() - 12);
String mac = hex.substring(0, 2) + ":" + hex.substring(2, 4) + ":" + hex.substring(4, 6) + ":"
+ hex.substring(6, 8) + ":" + hex.substring(8, 10) + ":" + hex.substring(10, 12);
if (port.equals("49153")) { // MR400 reports the rong
if ("49153".equals(port)) { // MR400 reports the rong
port = MR400_DEF_REMOTE_PORT;
}
properties.put(PROPERTY_VENDOR, VENDOR + "(" + manufacturer + ")");

View File

@@ -135,7 +135,7 @@ public class MagentaTVControl {
if (result.contains("<X_wakeOnLan>")) {
String wol = substringBetween(result, "<X_wakeOnLan>", "</X_wakeOnLan>");
config.setWakeOnLAN(wol);
logger.debug("{}: Wake-on-LAN is {}", thingId, wol.equals("0") ? "disabled" : "enabled");
logger.debug("{}: Wake-on-LAN is {}", thingId, "0".equals(wol) ? "disabled" : "enabled");
}
if (result.contains("<productVersionNumber>")) {
String version;
@@ -240,7 +240,7 @@ public class MagentaTVControl {
}
String result = substringBetween(response, "<result>", "</result>");
if (!result.equals("0")) {
if (!"0".equals(result)) {
throw new MagentaTVException("Pairing failed, result=" + result);
}
@@ -295,7 +295,7 @@ public class MagentaTVControl {
}
String result = getXmlValue(response, "pairingResult");
if (!result.equals("0")) {
if (!"0".equals(result)) {
logger.debug("{}: Pairing failed or pairing no longer valid, result={}", thingId, result);
resetPairing();
// let the caller decide how to proceed

View File

@@ -223,7 +223,7 @@ public class MagentaTVHandler extends BaseThingHandler implements MagentaTVListe
}
try {
if (!isOnline() || command.toString().equalsIgnoreCase("PAIR")) {
if (!isOnline() || "PAIR".equalsIgnoreCase(command.toString())) {
logger.debug("{}: Receiver {} is offline, try to (re-)connect", thingId, deviceName());
connectReceiver(); // reconnect to MR, throws an exception if this fails
}
@@ -273,7 +273,7 @@ public class MagentaTVHandler extends BaseThingHandler implements MagentaTVListe
}
break;
case CHANNEL_KEY:
if (command.toString().equalsIgnoreCase("PAIR")) { // special key to re-pair receiver (already done
if ("PAIR".equalsIgnoreCase(command.toString())) { // special key to re-pair receiver (already done
// above)
logger.debug("{}: PAIRing key received, reconnect receiver {}", thingId, deviceName());
} else {

View File

@@ -110,7 +110,6 @@ public class MagentaTVHttp {
* @throws IOException
*/
public String sendData(String remoteIp, String remotePort, String data) throws MagentaTVException {
String errorMessage = "";
StringBuffer response = new StringBuffer();
try (Socket socket = new Socket()) {

View File

@@ -48,7 +48,7 @@ public class MagentaTVNetwork {
*/
public void initLocalNet(String localIP, String localPort) throws MagentaTVException {
try {
if (localIP.isEmpty() || localIP.equals("0.0.0.0") || localIP.equals("127.0.0.1")) {
if (localIP.isEmpty() || "0.0.0.0".equals(localIP) || "127.0.0.1".equals(localIP)) {
throw new MagentaTVException("Unable to detect local IP address!");
}
this.localPort = localPort;

View File

@@ -89,7 +89,6 @@ public class MagentaTVNotifyServlet extends HttpServlet {
@Override
protected void service(@Nullable HttpServletRequest request, @Nullable HttpServletResponse response)
throws ServletException, IOException {
String data = inputStreamToString(request);
try {
if ((request == null) || (response == null)) {
@@ -118,7 +117,7 @@ public class MagentaTVNotifyServlet extends HttpServlet {
}
} else {
if (data.contains("STB_")) {
data = data.replaceAll("&quot;", "\"");
data = data.replace("&quot;", "\"");
String stbMac = substringBetween(data, "<STB_Mac>", "</STB_Mac>");
String stbEvent = "";
if (data.contains("<STB_playContent>")) {

View File

@@ -120,9 +120,9 @@ public class MagentaTVOAuth {
if (cred.sam3Para != null) {
for (OauthKeyValue si : cred.sam3Para) {
logger.trace("sam3Para.{} = {}", si.key, si.value);
if (si.key.equalsIgnoreCase("oAuthScope")) {
if ("oAuthScope".equalsIgnoreCase(si.key)) {
oAuthScope = si.value;
} else if (si.key.equalsIgnoreCase("SAM3ServiceURL")) {
} else if ("SAM3ServiceURL".equalsIgnoreCase(si.key)) {
oAuthService = si.value;
}
}
@@ -242,7 +242,7 @@ public class MagentaTVOAuth {
// validate response, API errors are reported as Json
HttpFields responseHeaders = contentResponse.getHeaders();
for (HttpField f : responseHeaders) {
if (f.getName().equals("Set-Cookie")) {
if ("Set-Cookie".equals(f.getName())) {
HttpCookie c = new HttpCookie(f.getName(), f.getValue());
cookies.add(c);
}