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.fsinternetradio.internal;
import static org.openhab.binding.fsinternetradio.internal.FSInternetRadioBindingConstants.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -141,7 +140,7 @@ public class FSInternetRadioDiscoveryParticipant implements UpnpDiscoveryPartici
@Override
public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
return Collections.singleton(THING_TYPE_RADIO);
return Set.of(THING_TYPE_RADIO);
}
@Override

View File

@@ -14,7 +14,6 @@ package org.openhab.binding.fsinternetradio.internal;
import static org.openhab.binding.fsinternetradio.internal.FSInternetRadioBindingConstants.THING_TYPE_RADIO;
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 FSInternetRadioHandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_RADIO);
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_RADIO);
private final HttpClient httpClient;

View File

@@ -200,8 +200,8 @@ public class FSInternetRadioHandler extends BaseThingHandler {
radio.increaseVolumeAbsolute();
} else if (IncreaseDecreaseType.DECREASE.equals(command) || UpDownType.DOWN.equals(command)) {
radio.decreaseVolumeAbsolute();
} else if (command instanceof PercentType) {
radio.setVolumePercent(((PercentType) command).intValue());
} else if (command instanceof PercentType percentCommand) {
radio.setVolumePercent(percentCommand.intValue());
}
// absolute value should also be updated now, so let's update all items
scheduler.schedule(updateRunnable, 1, SECONDS);
@@ -211,20 +211,20 @@ public class FSInternetRadioHandler extends BaseThingHandler {
radio.increaseVolumeAbsolute();
} else if (IncreaseDecreaseType.DECREASE.equals(command) || UpDownType.DOWN.equals(command)) {
radio.decreaseVolumeAbsolute();
} else if (command instanceof DecimalType) {
radio.setVolumeAbsolute(((DecimalType) command).intValue());
} else if (command instanceof DecimalType decimalCommand) {
radio.setVolumeAbsolute(decimalCommand.intValue());
}
// percent value should also be updated now, so let's update all items
scheduler.schedule(updateRunnable, 1, SECONDS);
break;
case CHANNEL_MODE:
if (command instanceof DecimalType) {
radio.setMode(((DecimalType) command).intValue());
if (command instanceof DecimalType decimalCommand) {
radio.setMode(decimalCommand.intValue());
}
break;
case CHANNEL_PRESET:
if (command instanceof DecimalType) {
radio.setPreset(((DecimalType) command).intValue());
if (command instanceof DecimalType decimalCommand) {
radio.setPreset(decimalCommand.intValue());
}
break;
case CHANNEL_MUTE:

View File

@@ -69,8 +69,8 @@ public class FrontierSiliconRadioApiResult {
logger.trace("converting to XML failed: '{}' with {}: {}", requestResultString, e.getClass().getName(),
e.getMessage());
logger.debug("converting to XML failed with {}: {}", e.getClass().getName(), e.getMessage());
if (e instanceof IOException) {
throw (IOException) e;
if (e instanceof IOException exception) {
throw exception;
}
throw new IOException(e);
}
@@ -192,8 +192,7 @@ public class FrontierSiliconRadioApiResult {
*/
public String getSessionId() {
final NodeList sessionIdTagList = xmlDoc.getElementsByTagName("sessionId");
final String givenSessId = getCharacterDataFromElement((Element) sessionIdTagList.item(0));
return givenSessId;
return getCharacterDataFromElement((Element) sessionIdTagList.item(0));
}
/**
@@ -216,8 +215,7 @@ public class FrontierSiliconRadioApiResult {
factory.setXIncludeAware(false);
factory.setExpandEntityReferences(false);
final DocumentBuilder builder = factory.newDocumentBuilder();
final Document xmlDocument = builder.parse(new InputSource(new StringReader(xmlString)));
return xmlDocument;
return builder.parse(new InputSource(new StringReader(xmlString)));
}
/**
@@ -229,8 +227,7 @@ public class FrontierSiliconRadioApiResult {
*/
private static String getCharacterDataFromElement(Element e) {
final Node child = e.getFirstChild();
if (child instanceof CharacterData) {
final CharacterData cd = (CharacterData) child;
if (child instanceof CharacterData cd) {
return cd.getData();
}
return "";

View File

@@ -818,8 +818,8 @@ public class FSInternetRadioHandlerJavaTest extends JavaTest {
private boolean isConfigurationComplete(Configuration config) {
String ip = (String) config.get(FSInternetRadioBindingConstants.CONFIG_PROPERTY_IP);
BigDecimal port = (BigDecimal) config.get(FSInternetRadioBindingConstants.CONFIG_PROPERTY_PORT.toString());
String pin = (String) config.get(FSInternetRadioBindingConstants.CONFIG_PROPERTY_PIN.toString());
BigDecimal port = (BigDecimal) config.get(FSInternetRadioBindingConstants.CONFIG_PROPERTY_PORT);
String pin = (String) config.get(FSInternetRadioBindingConstants.CONFIG_PROPERTY_PIN);
return !(ip == null || port.compareTo(BigDecimal.ZERO) == 0 || pin == null || pin.isEmpty());
}