[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:
Holger Friedrich 2023-08-24 06:44:56 +02:00 committed by GitHub
parent 6e49c6e6ec
commit 56e7daf898
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 50 additions and 59 deletions

View File

@ -61,7 +61,7 @@ public class HomekitTelevisionSpeakerImpl extends AbstractHomekitAccessoryImpl {
var volumeCharacteristic = getCharacteristic(VolumeCharacteristic.class); var volumeCharacteristic = getCharacteristic(VolumeCharacteristic.class);
var volumeSelectorCharacteristic = getCharacteristic(VolumeSelectorCharacteristic.class); var volumeSelectorCharacteristic = getCharacteristic(VolumeSelectorCharacteristic.class);
if (!volumeControlTypeCharacteristic.isPresent()) { if (volumeControlTypeCharacteristic.isEmpty()) {
VolumeControlTypeEnum type; VolumeControlTypeEnum type;
if (volumeCharacteristic.isPresent()) { if (volumeCharacteristic.isPresent()) {
type = VolumeControlTypeEnum.ABSOLUTE; type = VolumeControlTypeEnum.ABSOLUTE;

View File

@ -17,8 +17,8 @@ import java.net.NetworkInterface;
import java.net.SocketException; import java.net.SocketException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder; import javax.ws.rs.core.Response.ResponseBuilder;
@ -95,7 +95,7 @@ public class NetworkUtils {
public static Response singleError(Gson gson, UriInfo uri, int type, @Nullable String message) { public static Response singleError(Gson gson, UriInfo uri, int type, @Nullable String message) {
HueResponse e = new HueResponse( HueResponse e = new HueResponse(
new HueErrorMessage(type, uri.getPath().replace("/api", ""), message != null ? message : "")); new HueErrorMessage(type, uri.getPath().replace("/api", ""), message != null ? message : ""));
String str = gson.toJson(Collections.singleton(e), new TypeToken<List<?>>() { String str = gson.toJson(Set.of(e), new TypeToken<List<?>>() {
}.getType()); }.getType());
int httpCode = 500; int httpCode = 500;
switch (type) { switch (type) {

View File

@ -12,8 +12,8 @@
*/ */
package org.openhab.io.hueemulation.internal.rest; package org.openhab.io.hueemulation.internal.rest;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.PUT; import javax.ws.rs.PUT;
@ -132,7 +132,7 @@ public class ConfigurationAccess {
public Response catchAll(@Context UriInfo uri) { public Response catchAll(@Context UriInfo uri) {
HueResponse e = new HueResponse( HueResponse e = new HueResponse(
new HueErrorMessage(HueResponse.INVALID_JSON, uri.getPath().replace("/api", ""), "Invalid request: ")); new HueErrorMessage(HueResponse.INVALID_JSON, uri.getPath().replace("/api", ""), "Invalid request: "));
String str = cs.gson.toJson(Collections.singleton(e), new TypeToken<List<?>>() { String str = cs.gson.toJson(Set.of(e), new TypeToken<List<?>>() {
}.getType()); }.getType());
return Response.status(404).entity(str).build(); return Response.status(404).entity(str).build();
} }

View File

@ -14,7 +14,6 @@ package org.openhab.io.hueemulation.internal.rest;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -358,8 +357,7 @@ public class Scenes implements RegistryChangeListener<Rule> {
if (groupItem == null) { if (groupItem == null) {
return NetworkUtils.singleError(cs.gson, uri, HueResponse.ARGUMENTS_INVALID, "Group does not exist!"); return NetworkUtils.singleError(cs.gson, uri, HueResponse.ARGUMENTS_INVALID, "Group does not exist!");
} }
List<Action> actions = Collections List<Action> actions = List.of(actionFromState(cs.mapItemUIDtoHueID(groupItem), groupItem.getState()));
.singletonList(actionFromState(cs.mapItemUIDtoHueID(groupItem), groupItem.getState()));
builder.withActions(actions); builder.withActions(actions);
} }

View File

@ -14,8 +14,8 @@ package org.openhab.io.hueemulation.internal.rest;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
@ -172,7 +172,7 @@ public class UserManagement extends DefaultAbstractManagedProvider<HueUserAuthWi
String clientKey = UUID.randomUUID().toString(); String clientKey = UUID.randomUUID().toString();
addUser(apiKey, clientKey, userRequest.devicetype); addUser(apiKey, clientKey, userRequest.devicetype);
HueSuccessResponseCreateUser h = new HueSuccessResponseCreateUser(apiKey, clientKey); HueSuccessResponseCreateUser h = new HueSuccessResponseCreateUser(apiKey, clientKey);
String result = cs.gson.toJson(Collections.singleton(new HueResponse(h)), new TypeToken<List<?>>() { String result = cs.gson.toJson(Set.of(new HueResponse(h)), new TypeToken<List<?>>() {
}.getType()); }.getType());
return Response.ok(result).build(); return Response.ok(result).build();

View File

@ -19,9 +19,10 @@ import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.URI; import java.net.URI;
import java.util.Collections;
import java.util.Dictionary; import java.util.Dictionary;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
@ -126,10 +127,10 @@ public class CommonSetup {
} else { } else {
cs = new ConfigStoreWithoutMetadata(networkAddressService, configAdmin, scheduler); cs = new ConfigStoreWithoutMetadata(networkAddressService, configAdmin, scheduler);
} }
cs.activate(Collections.singletonMap("uuid", "a668dc9b-7172-49c3-832f-acb07dda2a20")); cs.activate(Map.of("uuid", "a668dc9b-7172-49c3-832f-acb07dda2a20"));
cs.switchFilter = Collections.singleton("Switchable"); cs.switchFilter = Set.of("Switchable");
cs.whiteFilter = Collections.singleton("Switchable"); cs.whiteFilter = Set.of("Switchable");
cs.colorFilter = Collections.singleton("ColorLighting"); cs.colorFilter = Set.of("ColorLighting");
userManagement = Mockito.spy(new UserManagement(storageService, cs)); userManagement = Mockito.spy(new UserManagement(storageService, cs));

View File

@ -17,7 +17,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Map;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
@ -73,7 +73,7 @@ public class ItemUIDtoHueIDMappingTests {
// Pretend there is a metadata entry for the imaginary item "demo1" with hueid 10 // Pretend there is a metadata entry for the imaginary item "demo1" with hueid 10
commonSetup.metadataRegistry.add(new Metadata(new MetadataKey(ConfigStore.METAKEY, "demo1"), "10", null)); commonSetup.metadataRegistry.add(new Metadata(new MetadataKey(ConfigStore.METAKEY, "demo1"), "10", null));
cs.activate(Collections.singletonMap("uuid", "demouuid")); cs.activate(Map.of("uuid", "demouuid"));
assertThat(cs.getHighestAssignedHueID(), CoreMatchers.is(10)); assertThat(cs.getHighestAssignedHueID(), CoreMatchers.is(10));
} }

View File

@ -20,7 +20,7 @@ import static org.mockito.Mockito.*;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.Collections; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Random; import java.util.Random;
@ -341,7 +341,7 @@ public class ScheduleTests {
configuration.put("time", "12:12:00"); configuration.put("time", "12:12:00");
trigger = TriggerBuilder.create().withId("absolutetrigger").withTypeUID("timer.AbsoluteDateTimeTrigger") trigger = TriggerBuilder.create().withId("absolutetrigger").withTypeUID("timer.AbsoluteDateTimeTrigger")
.withConfiguration(configuration).build(); .withConfiguration(configuration).build();
timeString = RuleUtils.timeStringFromTrigger(Collections.singletonList(trigger)); timeString = RuleUtils.timeStringFromTrigger(List.of(trigger));
assertThat(timeString, is("2020-02-01T12:12:00")); assertThat(timeString, is("2020-02-01T12:12:00"));
@ -352,7 +352,7 @@ public class ScheduleTests {
configuration.put("randomizeTime", "14:12:34"); configuration.put("randomizeTime", "14:12:34");
trigger = TriggerBuilder.create().withId("absolutetrigger").withTypeUID("timer.AbsoluteDateTimeTrigger") trigger = TriggerBuilder.create().withId("absolutetrigger").withTypeUID("timer.AbsoluteDateTimeTrigger")
.withConfiguration(configuration).build(); .withConfiguration(configuration).build();
timeString = RuleUtils.timeStringFromTrigger(Collections.singletonList(trigger)); timeString = RuleUtils.timeStringFromTrigger(List.of(trigger));
assertThat(timeString, is("2020-02-01T12:12:00A14:12:34")); assertThat(timeString, is("2020-02-01T12:12:00A14:12:34"));
@ -362,7 +362,7 @@ public class ScheduleTests {
configuration.put("cronExpression", "15 12 * * 6,7"); configuration.put("cronExpression", "15 12 * * 6,7");
trigger = TriggerBuilder.create().withId("crontrigger").withTypeUID("timer.GenericCronTrigger") trigger = TriggerBuilder.create().withId("crontrigger").withTypeUID("timer.GenericCronTrigger")
.withConfiguration(configuration).build(); .withConfiguration(configuration).build();
timeString = RuleUtils.timeStringFromTrigger(Collections.singletonList(trigger)); timeString = RuleUtils.timeStringFromTrigger(List.of(trigger));
assertThat(timeString, is("W3/T12:15:00")); assertThat(timeString, is("W3/T12:15:00"));
@ -371,7 +371,7 @@ public class ScheduleTests {
configuration.put("cronExpression", "15 14 * * 1,2,3,4,5,6,7"); configuration.put("cronExpression", "15 14 * * 1,2,3,4,5,6,7");
trigger = TriggerBuilder.create().withId("crontrigger").withTypeUID("timer.GenericCronTrigger") trigger = TriggerBuilder.create().withId("crontrigger").withTypeUID("timer.GenericCronTrigger")
.withConfiguration(configuration).build(); .withConfiguration(configuration).build();
timeString = RuleUtils.timeStringFromTrigger(Collections.singletonList(trigger)); timeString = RuleUtils.timeStringFromTrigger(List.of(trigger));
assertThat(timeString, is("W127/T14:15:00")); assertThat(timeString, is("W127/T14:15:00"));
@ -380,7 +380,7 @@ public class ScheduleTests {
configuration.put("time", "12:12:00"); configuration.put("time", "12:12:00");
trigger = TriggerBuilder.create().withId("timertrigger").withTypeUID("timer.TimerTrigger") trigger = TriggerBuilder.create().withId("timertrigger").withTypeUID("timer.TimerTrigger")
.withConfiguration(configuration).build(); .withConfiguration(configuration).build();
timeString = RuleUtils.timeStringFromTrigger(Collections.singletonList(trigger)); timeString = RuleUtils.timeStringFromTrigger(List.of(trigger));
assertThat(timeString, is("PT12:12:00")); assertThat(timeString, is("PT12:12:00"));
@ -390,7 +390,7 @@ public class ScheduleTests {
configuration.put("randomizeTime", "14:12:34"); configuration.put("randomizeTime", "14:12:34");
trigger = TriggerBuilder.create().withId("timertrigger").withTypeUID("timer.TimerTrigger") trigger = TriggerBuilder.create().withId("timertrigger").withTypeUID("timer.TimerTrigger")
.withConfiguration(configuration).build(); .withConfiguration(configuration).build();
timeString = RuleUtils.timeStringFromTrigger(Collections.singletonList(trigger)); timeString = RuleUtils.timeStringFromTrigger(List.of(trigger));
assertThat(timeString, is("PT12:12:00A14:12:34")); assertThat(timeString, is("PT12:12:00A14:12:34"));
@ -400,7 +400,7 @@ public class ScheduleTests {
configuration.put("repeat", -1); configuration.put("repeat", -1);
trigger = TriggerBuilder.create().withId("timertrigger").withTypeUID("timer.TimerTrigger") trigger = TriggerBuilder.create().withId("timertrigger").withTypeUID("timer.TimerTrigger")
.withConfiguration(configuration).build(); .withConfiguration(configuration).build();
timeString = RuleUtils.timeStringFromTrigger(Collections.singletonList(trigger)); timeString = RuleUtils.timeStringFromTrigger(List.of(trigger));
assertThat(timeString, is("R/PT12:12:00")); assertThat(timeString, is("R/PT12:12:00"));
@ -411,7 +411,7 @@ public class ScheduleTests {
configuration.put("repeat", 12); configuration.put("repeat", 12);
trigger = TriggerBuilder.create().withId("timertrigger").withTypeUID("timer.TimerTrigger") trigger = TriggerBuilder.create().withId("timertrigger").withTypeUID("timer.TimerTrigger")
.withConfiguration(configuration).build(); .withConfiguration(configuration).build();
timeString = RuleUtils.timeStringFromTrigger(Collections.singletonList(trigger)); timeString = RuleUtils.timeStringFromTrigger(List.of(trigger));
assertThat(timeString, is("R12/PT12:12:00A14:12:34")); assertThat(timeString, is("R12/PT12:12:00A14:12:34"));
} }

View File

@ -407,7 +407,7 @@ public class NeeoService implements EventSubscriber, NetworkAddressChangeListene
*/ */
@Override @Override
public Set<String> getSubscribedEventTypes() { public Set<String> getSubscribedEventTypes() {
return Collections.singleton(ItemStateChangedEvent.TYPE); return Set.of(ItemStateChangedEvent.TYPE);
} }
@Override @Override

View File

@ -80,8 +80,7 @@ public class NeeoItemValueConverter {
final String format = channel.getValue(); final String format = channel.getValue();
// HSBType must be done before the others since it inherits from DecimalType // HSBType must be done before the others since it inherits from DecimalType
if (state instanceof HSBType) { if (state instanceof HSBType hsb) {
final HSBType hsb = (HSBType) state;
switch (channel.getSubType()) { switch (channel.getSubType()) {
case HUE: case HUE:
return new NeeoItemValue(hsb.getHue().toBigDecimal()); return new NeeoItemValue(hsb.getHue().toBigDecimal());
@ -106,8 +105,8 @@ public class NeeoItemValueConverter {
convertedState = UnDefType.UNDEF; convertedState = UnDefType.UNDEF;
break; break;
case SLIDER: case SLIDER:
if (state instanceof PercentType) { if (state instanceof PercentType type) {
convertedState = new DecimalType(((PercentType) state).toBigDecimal()); convertedState = new DecimalType(type.toBigDecimal());
} else { } else {
convertedState = state.as(DecimalType.class); convertedState = state.as(DecimalType.class);
} }
@ -136,9 +135,9 @@ public class NeeoItemValueConverter {
} else if (convertedState instanceof UpDownType) { } else if (convertedState instanceof UpDownType) {
return new NeeoItemValue(convertedState == UpDownType.UP); return new NeeoItemValue(convertedState == UpDownType.UP);
} else if (convertedState instanceof DecimalType) { } else if (convertedState instanceof DecimalType type) {
if (format == null || format.isEmpty() || channel.getType() == NeeoCapabilityType.SLIDER) { if (format == null || format.isEmpty() || channel.getType() == NeeoCapabilityType.SLIDER) {
return new NeeoItemValue(((DecimalType) convertedState).toBigDecimal()); return new NeeoItemValue(type.toBigDecimal());
} }
} else if (convertedState instanceof UnDefType) { } else if (convertedState instanceof UnDefType) {
return new NeeoItemValue("-"); return new NeeoItemValue("-");

View File

@ -203,8 +203,7 @@ public class NeeoBrainDeviceSerializer implements JsonSerializer<NeeoDevice> {
compPath + "/textlabel/actor", new JsonPrimitive(sensorItemName)); compPath + "/textlabel/actor", new JsonPrimitive(sensorItemName));
capObj.addProperty("isLabelVisible", capObj.addProperty("isLabelVisible",
channel instanceof NeeoDeviceChannelText ? ((NeeoDeviceChannelText) channel).isLabelVisible() channel instanceof NeeoDeviceChannelText ndct ? ndct.isLabelVisible() : true);
: true);
capabilities.add(capObj); capabilities.add(capObj);

View File

@ -153,10 +153,10 @@ public class NeeoDeviceChannelSerializer
} }
if (chnl instanceof NeeoDeviceChannelText) { if (chnl instanceof NeeoDeviceChannelText text) {
jo.addProperty("labelVisible", ((NeeoDeviceChannelText) chnl).isLabelVisible()); jo.addProperty("labelVisible", text.isLabelVisible());
} else if (chnl instanceof NeeoDeviceChannelDirectory) { } else if (chnl instanceof NeeoDeviceChannelDirectory directory) {
jo.add("listItems", jsonContext.serialize(((NeeoDeviceChannelDirectory) chnl).getListItems())); jo.add("listItems", jsonContext.serialize(directory.getListItems()));
} }
return jo; return jo;

View File

@ -404,10 +404,9 @@ public class NeeoBrainService extends DefaultServletService {
} }
} else { } else {
if (channel instanceof NeeoDeviceChannelDirectory) { if (channel instanceof NeeoDeviceChannelDirectory directoryChannel) {
final NeeoDirectoryRequest discoveryRequest = gson.fromJson(req.getReader(), final NeeoDirectoryRequest discoveryRequest = gson.fromJson(req.getReader(),
NeeoDirectoryRequest.class); NeeoDirectoryRequest.class);
final NeeoDeviceChannelDirectory directoryChannel = (NeeoDeviceChannelDirectory) channel;
NeeoUtil.write(resp, gson.toJson(new NeeoDirectoryResult(discoveryRequest, directoryChannel))); NeeoUtil.write(resp, gson.toJson(new NeeoDirectoryResult(discoveryRequest, directoryChannel)));
} else { } else {
logger.debug("Channel definition for '{}' not found to directory set value ({})", logger.debug("Channel definition for '{}' not found to directory set value ({})",

View File

@ -237,8 +237,7 @@ public class CloudClient {
})// })//
.on(Manager.EVENT_CONNECT_ERROR, args -> { .on(Manager.EVENT_CONNECT_ERROR, args -> {
if (args.length > 0) { if (args.length > 0) {
if (args[0] instanceof Exception) { if (args[0] instanceof Exception e) {
Exception e = (Exception) args[0];
logger.debug( logger.debug(
"Error connecting to the openHAB Cloud instance: {} {}. Should reconnect automatically.", "Error connecting to the openHAB Cloud instance: {} {}. Should reconnect automatically.",
e.getClass().getSimpleName(), e.getMessage()); e.getClass().getSimpleName(), e.getMessage());
@ -256,8 +255,8 @@ public class CloudClient {
.on(Manager.EVENT_PACKET, args -> { .on(Manager.EVENT_PACKET, args -> {
int packetTypeIndex = -1; int packetTypeIndex = -1;
String type = "<unexpected packet type>"; String type = "<unexpected packet type>";
if (args.length == 1 && args[0] instanceof Packet<?>) { if (args.length == 1 && args[0] instanceof Packet<?> packet) {
packetTypeIndex = ((Packet<?>) args[0]).type; packetTypeIndex = packet.type;
if (packetTypeIndex < Parser.types.length) { if (packetTypeIndex < Parser.types.length) {
type = Parser.types[packetTypeIndex]; type = Parser.types[packetTypeIndex];
@ -282,8 +281,7 @@ public class CloudClient {
.on(Socket.EVENT_RECONNECT, .on(Socket.EVENT_RECONNECT,
args -> logger.debug("Socket.IO re-connected successfully (attempt {})", args[0]))// args -> logger.debug("Socket.IO re-connected successfully (attempt {})", args[0]))//
.on(Socket.EVENT_RECONNECT_ERROR, args -> { .on(Socket.EVENT_RECONNECT_ERROR, args -> {
if (args[0] instanceof Exception) { if (args[0] instanceof Exception e) {
Exception e = (Exception) args[0];
logger.debug("Socket.IO re-connect attempt error: {} {}", e.getClass().getSimpleName(), logger.debug("Socket.IO re-connect attempt error: {} {}", e.getClass().getSimpleName(),
e.getMessage()); e.getMessage());
} else { } else {
@ -308,8 +306,7 @@ public class CloudClient {
.on(Socket.EVENT_ERROR, args -> { .on(Socket.EVENT_ERROR, args -> {
if (CloudClient.this.socket.connected()) { if (CloudClient.this.socket.connected()) {
if (args.length > 0) { if (args.length > 0) {
if (args[0] instanceof Exception) { if (args[0] instanceof Exception e) {
Exception e = (Exception) args[0];
logger.warn("Error during communication: {} {}", e.getClass().getSimpleName(), logger.warn("Error during communication: {} {}", e.getClass().getSimpleName(),
e.getMessage()); e.getMessage());
} else { } else {
@ -335,8 +332,7 @@ public class CloudClient {
long delay = reconnectBackoff.duration(); long delay = reconnectBackoff.duration();
// Try reconnecting on connection errors // Try reconnecting on connection errors
if (args.length > 0) { if (args.length > 0) {
if (args[0] instanceof Exception) { if (args[0] instanceof Exception e) {
Exception e = (Exception) args[0];
logger.warn( logger.warn(
"Error connecting to the openHAB Cloud instance: {} {}. Reconnecting after {} ms.", "Error connecting to the openHAB Cloud instance: {} {}. Reconnecting after {} ms.",
e.getClass().getSimpleName(), e.getMessage(), delay); e.getClass().getSimpleName(), e.getMessage(), delay);

View File

@ -211,8 +211,7 @@ public class CloudService implements ActionService, CloudClientListener, EventSu
exposedItems = new HashSet<>(); exposedItems = new HashSet<>();
Object expCfg = config.get(CFG_EXPOSE); Object expCfg = config.get(CFG_EXPOSE);
if (expCfg instanceof String) { if (expCfg instanceof String value) {
String value = (String) expCfg;
while (value.startsWith("[")) { while (value.startsWith("[")) {
value = value.substring(1); value = value.substring(1);
} }
@ -222,8 +221,8 @@ public class CloudService implements ActionService, CloudClientListener, EventSu
for (String itemName : Arrays.asList((value).split(","))) { for (String itemName : Arrays.asList((value).split(","))) {
exposedItems.add(itemName.trim()); exposedItems.add(itemName.trim());
} }
} else if (expCfg instanceof Iterable) { } else if (expCfg instanceof Iterable iterable) {
for (Object entry : ((Iterable<?>) expCfg)) { for (Object entry : iterable) {
exposedItems.add(entry.toString()); exposedItems.add(entry.toString());
} }
} }

View File

@ -62,17 +62,17 @@ public class NotificationModuleHandlerFactory extends BaseModuleHandlerFactory {
@Override @Override
protected @Nullable ModuleHandler internalCreate(Module module, String ruleUID) { protected @Nullable ModuleHandler internalCreate(Module module, String ruleUID) {
if (module instanceof Action) { if (module instanceof Action action) {
switch (module.getTypeUID()) { switch (module.getTypeUID()) {
case SendNotificationActionHandler.TYPE_ID: case SendNotificationActionHandler.TYPE_ID:
case SendNotificationActionHandler.EXTENDED_TYPE_ID: case SendNotificationActionHandler.EXTENDED_TYPE_ID:
return new SendNotificationActionHandler((Action) module, cloudService); return new SendNotificationActionHandler(action, cloudService);
case SendBroadcastNotificationActionHandler.TYPE_ID: case SendBroadcastNotificationActionHandler.TYPE_ID:
case SendBroadcastNotificationActionHandler.EXTENDED_TYPE_ID: case SendBroadcastNotificationActionHandler.EXTENDED_TYPE_ID:
return new SendBroadcastNotificationActionHandler((Action) module, cloudService); return new SendBroadcastNotificationActionHandler(action, cloudService);
case SendLogNotificationActionHandler.TYPE_ID: case SendLogNotificationActionHandler.TYPE_ID:
case SendLogNotificationActionHandler.EXTENDED_TYPE_ID: case SendLogNotificationActionHandler.EXTENDED_TYPE_ID:
return new SendLogNotificationActionHandler((Action) module, cloudService); return new SendLogNotificationActionHandler(action, cloudService);
default: default:
break; break;
} }