Java 17 features (H-M) (#15520)

- 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
- remove null check before instanceof

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich
2023-09-08 14:36:59 +02:00
committed by GitHub
parent 3751fd0646
commit edaf17b345
519 changed files with 2703 additions and 2660 deletions

View File

@@ -46,14 +46,11 @@ public class MelCloudHandlerFactory extends BaseThingHandlerFactory {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
if (THING_TYPE_MELCLOUD_ACCOUNT.equals(thingTypeUID)) {
MelCloudAccountHandler handler = new MelCloudAccountHandler((Bridge) thing);
return handler;
return new MelCloudAccountHandler((Bridge) thing);
} else if (THING_TYPE_ACDEVICE.equals(thingTypeUID)) {
MelCloudDeviceHandler handler = new MelCloudDeviceHandler(thing);
return handler;
return new MelCloudDeviceHandler(thing);
} else if (THING_TYPE_HEATPUMPDEVICE.equals(thingTypeUID)) {
MelCloudHeatpumpDeviceHandler handler = new MelCloudHeatpumpDeviceHandler(thing);
return handler;
return new MelCloudHeatpumpDeviceHandler(thing);
}
return null;

View File

@@ -137,8 +137,7 @@ public class MelCloudConnection {
try {
String response = HttpUtil.executeUrl("GET", url, getHeaderProperties(), null, null, TIMEOUT_MILLISECONDS);
logger.debug("Device status response: {}", response);
DeviceStatus deviceStatus = gson.fromJson(response, DeviceStatus.class);
return deviceStatus;
return gson.fromJson(response, DeviceStatus.class);
} catch (IOException | JsonSyntaxException e) {
setConnected(false);
throw new MelCloudCommException("Error occurred during device status fetch", e);
@@ -167,8 +166,7 @@ public class MelCloudConnection {
try {
String response = HttpUtil.executeUrl("GET", url, getHeaderProperties(), null, null, TIMEOUT_MILLISECONDS);
logger.debug("Device heatpump status response: {}", response);
HeatpumpDeviceStatus heatpumpDeviceStatus = gson.fromJson(response, HeatpumpDeviceStatus.class);
return heatpumpDeviceStatus;
return gson.fromJson(response, HeatpumpDeviceStatus.class);
} catch (IOException | JsonSyntaxException e) {
setConnected(false);
throw new MelCloudCommException("Error occurred during heatpump device status fetch", e);

View File

@@ -130,9 +130,9 @@ public class MelCloudDiscoveryService extends AbstractDiscoveryService
Map<String, Object> deviceProperties = new HashMap<>();
deviceProperties.put(PROPERTY_DEVICE_ID, device.getDeviceID().toString());
deviceProperties.put(Thing.PROPERTY_SERIAL_NUMBER, device.getSerialNumber().toString());
deviceProperties.put(Thing.PROPERTY_MAC_ADDRESS, device.getMacAddress().toString());
deviceProperties.put("deviceName", device.getDeviceName().toString());
deviceProperties.put(Thing.PROPERTY_SERIAL_NUMBER, device.getSerialNumber());
deviceProperties.put(Thing.PROPERTY_MAC_ADDRESS, device.getMacAddress());
deviceProperties.put("deviceName", device.getDeviceName());
deviceProperties.put("buildingID", device.getBuildingID().toString());
String label = createLabel(device);
@@ -158,7 +158,7 @@ public class MelCloudDiscoveryService extends AbstractDiscoveryService
} else if (device.getType() == 1) {
sb.append("Heatpump Device - ");
}
if (device.getBuildingName() != null && device.getBuildingName() instanceof String) {
if (device.getBuildingName() instanceof String) {
sb.append(device.getBuildingName()).append(" - ");
}
sb.append(device.getDeviceName());
@@ -167,8 +167,8 @@ public class MelCloudDiscoveryService extends AbstractDiscoveryService
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof MelCloudAccountHandler) {
melCloudHandler = (MelCloudAccountHandler) handler;
if (handler instanceof MelCloudAccountHandler accountHandler) {
melCloudHandler = accountHandler;
}
}

View File

@@ -16,6 +16,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@@ -61,7 +62,7 @@ public class MelCloudAccountHandler extends BaseBridgeHandler {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(MelCloudDiscoveryService.class);
return Set.of(MelCloudDiscoveryService.class);
}
@Override