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:
@@ -181,7 +181,7 @@ public class RioSystemDeviceDiscoveryService extends AbstractDiscoveryService {
|
||||
|
||||
final DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID)
|
||||
.withProperty(RioSourceConfig.SOURCE, s).withBridge(sysHandler.getThing().getUID())
|
||||
.withLabel((name == null || name.isEmpty() || name.equalsIgnoreCase("null") ? "Source" : name)
|
||||
.withLabel((name == null || name.isEmpty() || "null".equalsIgnoreCase(name) ? "Source" : name)
|
||||
+ " (" + s + ")")
|
||||
.build();
|
||||
thingDiscovered(discoveryResult);
|
||||
@@ -214,7 +214,7 @@ public class RioSystemDeviceDiscoveryService extends AbstractDiscoveryService {
|
||||
|
||||
final DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID)
|
||||
.withProperty(RioZoneConfig.ZONE, z).withBridge(controllerUID)
|
||||
.withLabel((name.equalsIgnoreCase("null") ? "Zone" : name) + " (" + z + ")").build();
|
||||
.withLabel(("null".equalsIgnoreCase(name) ? "Zone" : name) + " (" + z + ")").build();
|
||||
thingDiscovered(discoveryResult);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -66,7 +67,7 @@ public class RioSystemDiscovery extends AbstractDiscoveryService {
|
||||
* 120 seconds (depending on how many network interfaces there are)
|
||||
*/
|
||||
public RioSystemDiscovery() {
|
||||
super(Collections.singleton(RioConstants.BRIDGE_TYPE_RIO), 120);
|
||||
super(Set.of(RioConstants.BRIDGE_TYPE_RIO), 120);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -292,15 +292,15 @@ public class SocketChannelSession implements SocketSession {
|
||||
final Object response = responses.poll(1, TimeUnit.SECONDS);
|
||||
|
||||
if (response != null) {
|
||||
if (response instanceof String) {
|
||||
if (response instanceof String stringCommand) {
|
||||
logger.debug("Dispatching response: {}", response);
|
||||
for (SocketSessionListener listener : listeners) {
|
||||
listener.responseReceived((String) response);
|
||||
listener.responseReceived(stringCommand);
|
||||
}
|
||||
} else if (response instanceof IOException) {
|
||||
} else if (response instanceof IOException ioException) {
|
||||
logger.debug("Dispatching exception: {}", response);
|
||||
for (SocketSessionListener listener : listeners) {
|
||||
listener.responseException((IOException) response);
|
||||
listener.responseException(ioException);
|
||||
}
|
||||
} else {
|
||||
logger.warn("Unknown response class: {}", response);
|
||||
|
||||
@@ -44,10 +44,10 @@ public class WaitingSessionListener implements SocketSessionListener {
|
||||
// will not come in until the other commands have been processed. So we need a large wait
|
||||
// time for it to be sent to us
|
||||
final Object lastResponse = responses.poll(60, TimeUnit.SECONDS);
|
||||
if (lastResponse instanceof String) {
|
||||
return (String) lastResponse;
|
||||
} else if (lastResponse instanceof IOException) {
|
||||
throw (IOException) lastResponse;
|
||||
if (lastResponse instanceof String stringCommand) {
|
||||
return stringCommand;
|
||||
} else if (lastResponse instanceof IOException ioException) {
|
||||
throw ioException;
|
||||
} else if (lastResponse == null) {
|
||||
throw new IOException("Didn't receive response in time");
|
||||
} else {
|
||||
|
||||
@@ -193,8 +193,8 @@ public abstract class AbstractBridgeHandler<E extends AbstractRioProtocol> exten
|
||||
public void channelUnlinked(ChannelUID channelUID) {
|
||||
// Remove any state when unlinking (that way if it is relinked - we get it)
|
||||
final RioHandlerCallback callback = getProtocolHandler().getCallback();
|
||||
if (callback instanceof StatefulHandlerCallback) {
|
||||
((StatefulHandlerCallback) callback).removeState(channelUID.getId());
|
||||
if (callback instanceof StatefulHandlerCallback handlerCallback) {
|
||||
handlerCallback.removeState(channelUID.getId());
|
||||
}
|
||||
super.channelUnlinked(channelUID);
|
||||
}
|
||||
|
||||
@@ -116,8 +116,8 @@ public abstract class AbstractThingHandler<E extends AbstractRioProtocol> extend
|
||||
public void channelUnlinked(ChannelUID channelUID) {
|
||||
// Remove any state when unlinking (that way if it is relinked - we get it)
|
||||
final RioHandlerCallback callback = getProtocolHandler().getCallback();
|
||||
if (callback instanceof StatefulHandlerCallback) {
|
||||
((StatefulHandlerCallback) callback).removeState(channelUID.getId());
|
||||
if (callback instanceof StatefulHandlerCallback handlerCallback) {
|
||||
handlerCallback.removeState(channelUID.getId());
|
||||
}
|
||||
super.channelUnlinked(channelUID);
|
||||
}
|
||||
|
||||
@@ -231,8 +231,8 @@ public class RioControllerHandler extends AbstractBridgeHandler<RioControllerPro
|
||||
if (childHandler == null) {
|
||||
throw new IllegalArgumentException("childHandler cannot be null");
|
||||
}
|
||||
if (childHandler instanceof RioZoneHandler) {
|
||||
final RioHandlerCallback callback = ((RioZoneHandler) childHandler).getRioHandlerCallback();
|
||||
if (childHandler instanceof RioZoneHandler zoneHandler) {
|
||||
final RioHandlerCallback callback = zoneHandler.getRioHandlerCallback();
|
||||
if (callback != null) {
|
||||
if (added) {
|
||||
callback.addListener(RioConstants.CHANNEL_ZONENAME, handlerCallbackListener);
|
||||
|
||||
@@ -40,11 +40,10 @@ public class AtomicStringTypeAdapter extends TypeAdapter<AtomicReference<String>
|
||||
|
||||
JsonElement je = JsonParser.parseReader(in);
|
||||
|
||||
if (je instanceof JsonPrimitive) {
|
||||
if (je instanceof JsonPrimitive jsonPrimitive) {
|
||||
value = new AtomicReference<>();
|
||||
value.set(((JsonPrimitive) je).getAsString());
|
||||
} else if (je instanceof JsonObject) {
|
||||
JsonObject jsonObject = (JsonObject) je;
|
||||
value.set(jsonPrimitive.getAsString());
|
||||
} else if (je instanceof JsonObject jsonObject) {
|
||||
value = new AtomicReference<>();
|
||||
value.set(jsonObject.get("value").getAsString());
|
||||
}
|
||||
|
||||
@@ -468,8 +468,8 @@ class RioSourceProtocol extends AbstractRioProtocol {
|
||||
|
||||
infoLock.lock();
|
||||
try {
|
||||
infoText.append(infoTextValue.toString());
|
||||
if (attr != null && attr.toString().indexOf("E") >= 0) {
|
||||
infoText.append(infoTextValue);
|
||||
if (attr != null && attr.toString().contains("E")) {
|
||||
final String text = infoText.toString();
|
||||
|
||||
infoText.setLength(0);
|
||||
|
||||
@@ -180,8 +180,8 @@ public class RioSystemHandler extends AbstractBridgeHandler<RioSystemProtocol> {
|
||||
}
|
||||
|
||||
if (id.equals(RioConstants.CHANNEL_SYSLANG)) {
|
||||
if (command instanceof StringType) {
|
||||
getProtocolHandler().setSystemLanguage(((StringType) command).toString());
|
||||
if (command instanceof StringType stringCommand) {
|
||||
getProtocolHandler().setSystemLanguage(stringCommand.toString());
|
||||
} else {
|
||||
logger.debug("Received a SYSTEM LANGUAGE channel command with a non StringType: {}", command);
|
||||
}
|
||||
@@ -489,8 +489,8 @@ public class RioSystemHandler extends AbstractBridgeHandler<RioSystemProtocol> {
|
||||
if (childHandler == null) {
|
||||
throw new IllegalArgumentException("childHandler cannot be null");
|
||||
}
|
||||
if (childHandler instanceof RioSourceHandler) {
|
||||
final RioHandlerCallback callback = ((RioSourceHandler) childHandler).getRioHandlerCallback();
|
||||
if (childHandler instanceof RioSourceHandler sourceHandler) {
|
||||
final RioHandlerCallback callback = sourceHandler.getRioHandlerCallback();
|
||||
if (callback != null) {
|
||||
if (added) {
|
||||
callback.addListener(RioConstants.CHANNEL_SOURCENAME, handlerCallbackListener);
|
||||
|
||||
@@ -139,31 +139,31 @@ public class RioZoneHandler extends AbstractThingHandler<RioZoneProtocol>
|
||||
}
|
||||
|
||||
if (id.equals(RioConstants.CHANNEL_ZONEBASS)) {
|
||||
if (command instanceof DecimalType) {
|
||||
getProtocolHandler().setZoneBass(((DecimalType) command).intValue());
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
getProtocolHandler().setZoneBass(decimalCommand.intValue());
|
||||
} else {
|
||||
logger.debug("Received a ZONE BASS channel command with a non DecimalType: {}", command);
|
||||
}
|
||||
|
||||
} else if (id.equals(RioConstants.CHANNEL_ZONETREBLE)) {
|
||||
if (command instanceof DecimalType) {
|
||||
getProtocolHandler().setZoneTreble(((DecimalType) command).intValue());
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
getProtocolHandler().setZoneTreble(decimalCommand.intValue());
|
||||
} else {
|
||||
logger.debug("Received a ZONE TREBLE channel command with a non DecimalType: {}", command);
|
||||
}
|
||||
|
||||
} else if (id.equals(RioConstants.CHANNEL_ZONEBALANCE)) {
|
||||
if (command instanceof DecimalType) {
|
||||
getProtocolHandler().setZoneBalance(((DecimalType) command).intValue());
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
getProtocolHandler().setZoneBalance(decimalCommand.intValue());
|
||||
} else {
|
||||
logger.debug("Received a ZONE BALANCE channel command with a non DecimalType: {}", command);
|
||||
}
|
||||
|
||||
} else if (id.equals(RioConstants.CHANNEL_ZONETURNONVOLUME)) {
|
||||
if (command instanceof PercentType) {
|
||||
getProtocolHandler().setZoneTurnOnVolume(((PercentType) command).intValue() / 100d);
|
||||
} else if (command instanceof DecimalType) {
|
||||
getProtocolHandler().setZoneTurnOnVolume(((DecimalType) command).doubleValue());
|
||||
if (command instanceof PercentType percentCommand) {
|
||||
getProtocolHandler().setZoneTurnOnVolume(percentCommand.intValue() / 100d);
|
||||
} else if (command instanceof DecimalType decimalCommand) {
|
||||
getProtocolHandler().setZoneTurnOnVolume(decimalCommand.doubleValue());
|
||||
} else {
|
||||
logger.debug("Received a ZONE TURN ON VOLUME channel command with a non PercentType/DecimalType: {}",
|
||||
command);
|
||||
@@ -177,15 +177,15 @@ public class RioZoneHandler extends AbstractThingHandler<RioZoneProtocol>
|
||||
}
|
||||
|
||||
} else if (id.equals(RioConstants.CHANNEL_ZONESLEEPTIMEREMAINING)) {
|
||||
if (command instanceof DecimalType) {
|
||||
getProtocolHandler().setZoneSleepTimeRemaining(((DecimalType) command).intValue());
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
getProtocolHandler().setZoneSleepTimeRemaining(decimalCommand.intValue());
|
||||
} else {
|
||||
logger.debug("Received a ZONE SLEEP TIME REMAINING channel command with a non DecimalType: {}",
|
||||
command);
|
||||
}
|
||||
} else if (id.equals(RioConstants.CHANNEL_ZONESOURCE)) {
|
||||
if (command instanceof DecimalType) {
|
||||
getProtocolHandler().setZoneSource(((DecimalType) command).intValue());
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
getProtocolHandler().setZoneSource(decimalCommand.intValue());
|
||||
} else {
|
||||
logger.debug("Received a ZONE SOURCE channel command with a non DecimalType: {}", command);
|
||||
}
|
||||
@@ -197,15 +197,15 @@ public class RioZoneHandler extends AbstractThingHandler<RioZoneProtocol>
|
||||
logger.debug("Received a ZONE STATUS channel command with a non OnOffType: {}", command);
|
||||
}
|
||||
} else if (id.equals(RioConstants.CHANNEL_ZONEPARTYMODE)) {
|
||||
if (command instanceof StringType) {
|
||||
getProtocolHandler().setZonePartyMode(((StringType) command).toString());
|
||||
if (command instanceof StringType stringCommand) {
|
||||
getProtocolHandler().setZonePartyMode(stringCommand.toString());
|
||||
} else {
|
||||
logger.debug("Received a ZONE PARTY MODE channel command with a non StringType: {}", command);
|
||||
}
|
||||
|
||||
} else if (id.equals(RioConstants.CHANNEL_ZONEDONOTDISTURB)) {
|
||||
if (command instanceof StringType) {
|
||||
getProtocolHandler().setZoneDoNotDisturb(((StringType) command).toString());
|
||||
if (command instanceof StringType stringCommand) {
|
||||
getProtocolHandler().setZoneDoNotDisturb(stringCommand.toString());
|
||||
} else {
|
||||
logger.debug("Received a ZONE DO NOT DISTURB channel command with a non StringType: {}", command);
|
||||
}
|
||||
@@ -236,10 +236,10 @@ public class RioZoneHandler extends AbstractThingHandler<RioZoneProtocol>
|
||||
getProtocolHandler().setZoneStatus(command == OnOffType.ON);
|
||||
} else if (command instanceof IncreaseDecreaseType) {
|
||||
getProtocolHandler().setZoneVolume(command == IncreaseDecreaseType.INCREASE);
|
||||
} else if (command instanceof PercentType) {
|
||||
getProtocolHandler().setZoneVolume(((PercentType) command).intValue() / 100d);
|
||||
} else if (command instanceof DecimalType) {
|
||||
getProtocolHandler().setZoneVolume(((DecimalType) command).doubleValue());
|
||||
} else if (command instanceof PercentType percentCommand) {
|
||||
getProtocolHandler().setZoneVolume(percentCommand.intValue() / 100d);
|
||||
} else if (command instanceof DecimalType decimalCommand) {
|
||||
getProtocolHandler().setZoneVolume(decimalCommand.doubleValue());
|
||||
} else {
|
||||
logger.debug(
|
||||
"Received a ZONE VOLUME channel command with a non OnOffType/IncreaseDecreaseType/PercentType/DecimalTye: {}",
|
||||
@@ -254,36 +254,36 @@ public class RioZoneHandler extends AbstractThingHandler<RioZoneProtocol>
|
||||
}
|
||||
|
||||
} else if (id.equals(RioConstants.CHANNEL_ZONEKEYPRESS)) {
|
||||
if (command instanceof StringType) {
|
||||
getProtocolHandler().sendKeyPress(((StringType) command).toString());
|
||||
if (command instanceof StringType stringCommand) {
|
||||
getProtocolHandler().sendKeyPress(stringCommand.toString());
|
||||
} else {
|
||||
logger.debug("Received a ZONE KEYPRESS channel command with a non StringType: {}", command);
|
||||
}
|
||||
|
||||
} else if (id.equals(RioConstants.CHANNEL_ZONEKEYRELEASE)) {
|
||||
if (command instanceof StringType) {
|
||||
getProtocolHandler().sendKeyRelease(((StringType) command).toString());
|
||||
if (command instanceof StringType stringCommand) {
|
||||
getProtocolHandler().sendKeyRelease(stringCommand.toString());
|
||||
} else {
|
||||
logger.debug("Received a ZONE KEYRELEASE channel command with a non StringType: {}", command);
|
||||
}
|
||||
|
||||
} else if (id.equals(RioConstants.CHANNEL_ZONEKEYHOLD)) {
|
||||
if (command instanceof StringType) {
|
||||
getProtocolHandler().sendKeyHold(((StringType) command).toString());
|
||||
if (command instanceof StringType stringCommand) {
|
||||
getProtocolHandler().sendKeyHold(stringCommand.toString());
|
||||
} else {
|
||||
logger.debug("Received a ZONE KEYHOLD channel command with a non StringType: {}", command);
|
||||
}
|
||||
|
||||
} else if (id.equals(RioConstants.CHANNEL_ZONEKEYCODE)) {
|
||||
if (command instanceof StringType) {
|
||||
getProtocolHandler().sendKeyCode(((StringType) command).toString());
|
||||
if (command instanceof StringType stringCommand) {
|
||||
getProtocolHandler().sendKeyCode(stringCommand.toString());
|
||||
} else {
|
||||
logger.debug("Received a ZONE KEYCODE channel command with a non StringType: {}", command);
|
||||
}
|
||||
|
||||
} else if (id.equals(RioConstants.CHANNEL_ZONEEVENT)) {
|
||||
if (command instanceof StringType) {
|
||||
getProtocolHandler().sendEvent(((StringType) command).toString());
|
||||
if (command instanceof StringType stringCommand) {
|
||||
getProtocolHandler().sendEvent(stringCommand.toString());
|
||||
} else {
|
||||
logger.debug("Received a ZONE EVENT channel command with a non StringType: {}", command);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user