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:
@@ -136,7 +136,7 @@ public class ElroConnectsBindingConstants {
|
||||
.collect(Collectors.toUnmodifiableMap(Map.Entry::getValue, Map.Entry::getKey));
|
||||
|
||||
// ELRO device types
|
||||
public static enum ElroDeviceType {
|
||||
public enum ElroDeviceType {
|
||||
ENTRY_SENSOR,
|
||||
CO_ALARM,
|
||||
CXSM_ALARM,
|
||||
@@ -197,7 +197,7 @@ public class ElroConnectsBindingConstants {
|
||||
.collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
|
||||
// ELRO device status
|
||||
public static enum ElroDeviceStatus {
|
||||
public enum ElroDeviceStatus {
|
||||
NORMAL,
|
||||
TRIGGERED,
|
||||
TEST,
|
||||
|
||||
@@ -52,8 +52,7 @@ public class ElroConnectsDynamicStateDescriptionProvider implements DynamicState
|
||||
@Override
|
||||
public @Nullable StateDescription getStateDescription(Channel channel,
|
||||
@Nullable StateDescription originalStateDescription, @Nullable Locale locale) {
|
||||
StateDescription description = descriptions.get(channel.getUID());
|
||||
return description;
|
||||
return descriptions.get(channel.getUID());
|
||||
}
|
||||
|
||||
@Deactivate
|
||||
|
||||
@@ -110,7 +110,7 @@ public abstract class ElroConnectsDevice {
|
||||
typeName = getDeviceType();
|
||||
}
|
||||
|
||||
return deviceName.isEmpty() ? typeName + "-" + String.valueOf(deviceId) : deviceName;
|
||||
return deviceName.isEmpty() ? typeName + "-" + deviceId : deviceName;
|
||||
}
|
||||
|
||||
public String getDeviceType() {
|
||||
|
||||
@@ -85,7 +85,7 @@ public class ElroConnectsBridgeDiscoveryService extends AbstractDiscoveryService
|
||||
String firmwareVersion = c.getValue().binVersion;
|
||||
boolean legacy = false;
|
||||
try {
|
||||
legacy = !(Integer.valueOf(firmwareVersion.substring(firmwareVersion.lastIndexOf(".") + 1)) > 14);
|
||||
legacy = Integer.valueOf(firmwareVersion.substring(firmwareVersion.lastIndexOf(".") + 1)) <= 14;
|
||||
} catch (NumberFormatException e) {
|
||||
// Assume new firmware if we cannot decode firmwareVersion
|
||||
logger.debug("Cannot get firmware version from {}, assume new firmware", firmwareVersion);
|
||||
@@ -141,14 +141,9 @@ public class ElroConnectsBridgeDiscoveryService extends AbstractDiscoveryService
|
||||
|
||||
@Override
|
||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||
ElroConnectsAccountHandler account = null;
|
||||
if (handler instanceof ElroConnectsAccountHandler) {
|
||||
account = (ElroConnectsAccountHandler) handler;
|
||||
accountHandler = account;
|
||||
}
|
||||
|
||||
if (account != null) {
|
||||
account.setDiscoveryService(this);
|
||||
if (handler instanceof ElroConnectsAccountHandler accountHandler) {
|
||||
this.accountHandler = accountHandler;
|
||||
accountHandler.setDiscoveryService(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -121,14 +121,9 @@ public class ElroConnectsDiscoveryService extends AbstractDiscoveryService imple
|
||||
|
||||
@Override
|
||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||
ElroConnectsBridgeHandler bridge = null;
|
||||
if (handler instanceof ElroConnectsBridgeHandler) {
|
||||
bridge = (ElroConnectsBridgeHandler) handler;
|
||||
bridgeHandler = bridge;
|
||||
}
|
||||
|
||||
if (bridge != null) {
|
||||
bridge.setDiscoveryService(this);
|
||||
if (handler instanceof ElroConnectsBridgeHandler bridgeHandler) {
|
||||
this.bridgeHandler = bridgeHandler;
|
||||
bridgeHandler.setDiscoveryService(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,10 @@ import java.lang.reflect.Type;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.URI;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
@@ -349,7 +349,7 @@ public class ElroConnectsAccountHandler extends BaseBridgeHandler {
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||
return Collections.singleton(ElroConnectsBridgeDiscoveryService.class);
|
||||
return Set.of(ElroConnectsBridgeDiscoveryService.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,9 +23,9 @@ import java.net.UnknownHostException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@@ -864,9 +864,9 @@ public class ElroConnectsBridgeHandler extends BaseBridgeHandler {
|
||||
if (SCENE.equals(channelUID.getId())) {
|
||||
if (command instanceof RefreshType) {
|
||||
updateState(SCENE, new StringType(String.valueOf(currentScene)));
|
||||
} else if (command instanceof StringType) {
|
||||
} else if (command instanceof StringType stringCommand) {
|
||||
try {
|
||||
selectScene(Integer.valueOf(((StringType) command).toString()));
|
||||
selectScene(Integer.valueOf(stringCommand.toString()));
|
||||
} catch (NumberFormatException nfe) {
|
||||
logger.debug("Cannot interpret scene command {}", command);
|
||||
}
|
||||
@@ -965,7 +965,7 @@ public class ElroConnectsBridgeHandler extends BaseBridgeHandler {
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||
return Collections.singleton(ElroConnectsDiscoveryService.class);
|
||||
return Set.of(ElroConnectsDiscoveryService.class);
|
||||
}
|
||||
|
||||
public Map<Integer, String> listDevicesFromConsole() {
|
||||
|
||||
Reference in New Issue
Block a user