[io] Use Java 17 features (#15485)
* instanceof matching and multiline strings * use Map/Set/List.of instead of Collections Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
@@ -237,8 +237,7 @@ public class CloudClient {
|
||||
})//
|
||||
.on(Manager.EVENT_CONNECT_ERROR, args -> {
|
||||
if (args.length > 0) {
|
||||
if (args[0] instanceof Exception) {
|
||||
Exception e = (Exception) args[0];
|
||||
if (args[0] instanceof Exception e) {
|
||||
logger.debug(
|
||||
"Error connecting to the openHAB Cloud instance: {} {}. Should reconnect automatically.",
|
||||
e.getClass().getSimpleName(), e.getMessage());
|
||||
@@ -256,8 +255,8 @@ public class CloudClient {
|
||||
.on(Manager.EVENT_PACKET, args -> {
|
||||
int packetTypeIndex = -1;
|
||||
String type = "<unexpected packet type>";
|
||||
if (args.length == 1 && args[0] instanceof Packet<?>) {
|
||||
packetTypeIndex = ((Packet<?>) args[0]).type;
|
||||
if (args.length == 1 && args[0] instanceof Packet<?> packet) {
|
||||
packetTypeIndex = packet.type;
|
||||
|
||||
if (packetTypeIndex < Parser.types.length) {
|
||||
type = Parser.types[packetTypeIndex];
|
||||
@@ -282,8 +281,7 @@ public class CloudClient {
|
||||
.on(Socket.EVENT_RECONNECT,
|
||||
args -> logger.debug("Socket.IO re-connected successfully (attempt {})", args[0]))//
|
||||
.on(Socket.EVENT_RECONNECT_ERROR, args -> {
|
||||
if (args[0] instanceof Exception) {
|
||||
Exception e = (Exception) args[0];
|
||||
if (args[0] instanceof Exception e) {
|
||||
logger.debug("Socket.IO re-connect attempt error: {} {}", e.getClass().getSimpleName(),
|
||||
e.getMessage());
|
||||
} else {
|
||||
@@ -308,8 +306,7 @@ public class CloudClient {
|
||||
.on(Socket.EVENT_ERROR, args -> {
|
||||
if (CloudClient.this.socket.connected()) {
|
||||
if (args.length > 0) {
|
||||
if (args[0] instanceof Exception) {
|
||||
Exception e = (Exception) args[0];
|
||||
if (args[0] instanceof Exception e) {
|
||||
logger.warn("Error during communication: {} {}", e.getClass().getSimpleName(),
|
||||
e.getMessage());
|
||||
} else {
|
||||
@@ -335,8 +332,7 @@ public class CloudClient {
|
||||
long delay = reconnectBackoff.duration();
|
||||
// Try reconnecting on connection errors
|
||||
if (args.length > 0) {
|
||||
if (args[0] instanceof Exception) {
|
||||
Exception e = (Exception) args[0];
|
||||
if (args[0] instanceof Exception e) {
|
||||
logger.warn(
|
||||
"Error connecting to the openHAB Cloud instance: {} {}. Reconnecting after {} ms.",
|
||||
e.getClass().getSimpleName(), e.getMessage(), delay);
|
||||
|
||||
@@ -211,8 +211,7 @@ public class CloudService implements ActionService, CloudClientListener, EventSu
|
||||
|
||||
exposedItems = new HashSet<>();
|
||||
Object expCfg = config.get(CFG_EXPOSE);
|
||||
if (expCfg instanceof String) {
|
||||
String value = (String) expCfg;
|
||||
if (expCfg instanceof String value) {
|
||||
while (value.startsWith("[")) {
|
||||
value = value.substring(1);
|
||||
}
|
||||
@@ -222,8 +221,8 @@ public class CloudService implements ActionService, CloudClientListener, EventSu
|
||||
for (String itemName : Arrays.asList((value).split(","))) {
|
||||
exposedItems.add(itemName.trim());
|
||||
}
|
||||
} else if (expCfg instanceof Iterable) {
|
||||
for (Object entry : ((Iterable<?>) expCfg)) {
|
||||
} else if (expCfg instanceof Iterable iterable) {
|
||||
for (Object entry : iterable) {
|
||||
exposedItems.add(entry.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,17 +62,17 @@ public class NotificationModuleHandlerFactory extends BaseModuleHandlerFactory {
|
||||
|
||||
@Override
|
||||
protected @Nullable ModuleHandler internalCreate(Module module, String ruleUID) {
|
||||
if (module instanceof Action) {
|
||||
if (module instanceof Action action) {
|
||||
switch (module.getTypeUID()) {
|
||||
case SendNotificationActionHandler.TYPE_ID:
|
||||
case SendNotificationActionHandler.EXTENDED_TYPE_ID:
|
||||
return new SendNotificationActionHandler((Action) module, cloudService);
|
||||
return new SendNotificationActionHandler(action, cloudService);
|
||||
case SendBroadcastNotificationActionHandler.TYPE_ID:
|
||||
case SendBroadcastNotificationActionHandler.EXTENDED_TYPE_ID:
|
||||
return new SendBroadcastNotificationActionHandler((Action) module, cloudService);
|
||||
return new SendBroadcastNotificationActionHandler(action, cloudService);
|
||||
case SendLogNotificationActionHandler.TYPE_ID:
|
||||
case SendLogNotificationActionHandler.EXTENDED_TYPE_ID:
|
||||
return new SendLogNotificationActionHandler((Action) module, cloudService);
|
||||
return new SendLogNotificationActionHandler(action, cloudService);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user