Java 17 features (A-G) (#15516)

- 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:
Holger Friedrich
2023-09-05 22:30:16 +02:00
committed by GitHub
parent a0dc5c05f2
commit cf10b3e9c7
486 changed files with 2053 additions and 1955 deletions

View File

@@ -14,7 +14,6 @@ package org.openhab.binding.denonmarantz.internal;
import static org.openhab.binding.denonmarantz.internal.DenonMarantzBindingConstants.THING_TYPE_AVR;
import java.util.Collections;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -41,7 +40,7 @@ import org.osgi.service.component.annotations.Reference;
@NonNullByDefault
public class DenonMarantzHandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_AVR);
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_AVR);
private final HttpClient httpClient;

View File

@@ -165,10 +165,10 @@ public abstract class DenonMarantzConnector {
cmd += "UP";
} else if (command == IncreaseDecreaseType.DECREASE) {
cmd += "DOWN";
} else if (command instanceof DecimalType) {
cmd += toDenonValue(((DecimalType) command));
} else if (command instanceof PercentType) {
cmd += percentToDenonValue(((PercentType) command).toBigDecimal());
} else if (command instanceof DecimalType decimalCommand) {
cmd += toDenonValue(decimalCommand);
} else if (command instanceof PercentType percentCommand) {
cmd += percentToDenonValue(percentCommand.toBigDecimal());
} else {
throw new UnsupportedCommandTypeException();
}

View File

@@ -274,7 +274,7 @@ public class DenonMarantzTelnetConnector extends DenonMarantzConnector implement
* Display info could contain some garbled text, attempt to clean it up.
*/
private String cleanupDisplayInfo(String titleValue) {
byte firstByteRemoved[] = Arrays.copyOfRange(titleValue.getBytes(), 1, titleValue.getBytes().length);
byte[] firstByteRemoved = Arrays.copyOfRange(titleValue.getBytes(), 1, titleValue.getBytes().length);
return new String(firstByteRemoved).replaceAll("[\u0000-\u001f]", "");
}
}

View File

@@ -14,7 +14,6 @@ package org.openhab.binding.denonmarantz.internal.discovery;
import static org.openhab.binding.denonmarantz.internal.DenonMarantzBindingConstants.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -66,7 +65,7 @@ public class DenonMarantzDiscoveryParticipant implements MDNSDiscoveryParticipan
@Override
public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
return Collections.singleton(THING_TYPE_AVR);
return Set.of(THING_TYPE_AVR);
}
@Override
@@ -115,9 +114,8 @@ public class DenonMarantzDiscoveryParticipant implements MDNSDiscoveryParticipan
properties.put(Thing.PROPERTY_MODEL_ID, model);
String label = friendlyName + " (" + vendor + ' ' + model + ")";
DiscoveryResult result = DiscoveryResultBuilder.create(thingUID).withProperties(properties).withLabel(label)
return DiscoveryResultBuilder.create(thingUID).withProperties(properties).withLabel(label)
.withRepresentationProperty(Thing.PROPERTY_SERIAL_NUMBER).build();
return result;
} else {
return null;

View File

@@ -24,7 +24,7 @@ public class OnOffAdapter extends XmlAdapter<String, Boolean> {
@Override
public Boolean unmarshal(String v) throws Exception {
if (v != null) {
return Boolean.valueOf(v.toLowerCase().equals("on"));
return Boolean.valueOf("on".equals(v.toLowerCase()));
}
return Boolean.FALSE;

View File

@@ -27,7 +27,7 @@ public class VolumeAdapter extends XmlAdapter<String, BigDecimal> {
@Override
public BigDecimal unmarshal(String v) throws Exception {
if (v != null && !v.trim().equals("--")) {
if (v != null && !"--".equals(v.trim())) {
return new BigDecimal(v.trim()).add(DB_OFFSET);
}