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:
@@ -160,8 +160,8 @@ public class LivisiDeviceDiscoveryService extends AbstractDiscoveryService
|
||||
|
||||
@Override
|
||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||
if (handler instanceof LivisiBridgeHandler) {
|
||||
bridgeHandler = (LivisiBridgeHandler) handler;
|
||||
if (handler instanceof LivisiBridgeHandler livisiBridgeHandler) {
|
||||
bridgeHandler = livisiBridgeHandler;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,10 +20,10 @@ import java.net.URI;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.FormatStyle;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
@@ -137,7 +137,7 @@ public class LivisiBridgeHandler extends BaseBridgeHandler
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||
return Collections.singleton(LivisiDeviceDiscoveryService.class);
|
||||
return Set.of(LivisiDeviceDiscoveryService.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -564,8 +564,8 @@ public class LivisiBridgeHandler extends BaseBridgeHandler
|
||||
|
||||
@Override
|
||||
public void onError(final Throwable cause) {
|
||||
if (cause instanceof Exception) {
|
||||
handleClientException((Exception) cause);
|
||||
if (cause instanceof Exception exception) {
|
||||
handleClientException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -132,8 +132,7 @@ public class LivisiDeviceHandler extends BaseThingHandler implements DeviceStatu
|
||||
}
|
||||
|
||||
private void commandSetDimLevel(Command command, LivisiBridgeHandler bridgeHandler) {
|
||||
if (command instanceof DecimalType) {
|
||||
final DecimalType dimLevel = (DecimalType) command;
|
||||
if (command instanceof DecimalType dimLevel) {
|
||||
bridgeHandler.commandSetDimLevel(deviceId, dimLevel.intValue());
|
||||
} else if (command instanceof OnOffType) {
|
||||
if (OnOffType.ON.equals(command)) {
|
||||
@@ -145,8 +144,7 @@ public class LivisiDeviceHandler extends BaseThingHandler implements DeviceStatu
|
||||
}
|
||||
|
||||
private void commandRollerShutter(Command command, LivisiBridgeHandler bridgeHandler) {
|
||||
if (command instanceof DecimalType) {
|
||||
final DecimalType rollerShutterLevel = (DecimalType) command;
|
||||
if (command instanceof DecimalType rollerShutterLevel) {
|
||||
bridgeHandler.commandSetRollerShutterLevel(deviceId,
|
||||
invertRollerShutterValueIfConfigured(rollerShutterLevel.intValue()));
|
||||
} else if (command instanceof OnOffType) {
|
||||
@@ -169,13 +167,13 @@ public class LivisiDeviceHandler extends BaseThingHandler implements DeviceStatu
|
||||
}
|
||||
|
||||
private void commandUpdatePointTemperature(Command command, LivisiBridgeHandler bridgeHandler) {
|
||||
if (command instanceof QuantityType) {
|
||||
final QuantityType<?> pointTemperatureCommand = ((QuantityType<?>) command).toUnit(SIUnits.CELSIUS);
|
||||
if (command instanceof QuantityType temperatureCommand) {
|
||||
final QuantityType<?> pointTemperatureCommand = temperatureCommand.toUnit(SIUnits.CELSIUS);
|
||||
if (pointTemperatureCommand != null) {
|
||||
commandUpdatePointTemperature(pointTemperatureCommand.doubleValue(), bridgeHandler);
|
||||
}
|
||||
} else if (command instanceof DecimalType) {
|
||||
commandUpdatePointTemperature(((DecimalType) command).doubleValue(), bridgeHandler);
|
||||
} else if (command instanceof DecimalType temperatureCommand) {
|
||||
commandUpdatePointTemperature(temperatureCommand.doubleValue(), bridgeHandler);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -991,8 +989,7 @@ public class LivisiDeviceHandler extends BaseThingHandler implements DeviceStatu
|
||||
}
|
||||
@Nullable
|
||||
final ThingHandler handler = bridge.getHandler();
|
||||
if (handler instanceof LivisiBridgeHandler) {
|
||||
LivisiBridgeHandler bridgeHandler = (LivisiBridgeHandler) handler;
|
||||
if (handler instanceof LivisiBridgeHandler bridgeHandler) {
|
||||
bridgeHandler.registerDeviceStatusListener(deviceId, this);
|
||||
this.bridgeHandler = bridgeHandler;
|
||||
} else {
|
||||
|
||||
@@ -69,14 +69,15 @@ public class LivisiClientTest {
|
||||
|
||||
@Test
|
||||
public void testRefreshStatusSHC2() throws Exception {
|
||||
mockRequest(STATUS_URL,
|
||||
"{\"gateway\": {\"serialNumber\": \"123\","
|
||||
+ "\"appVersion\": \"1.2.37.430\",\"osVersion\": \"8.17\",\"configVersion\": 1200,"
|
||||
+ "\"operationStatus\": \"active\",\"network\": "
|
||||
+ "{\"ethCableAttached\": true,\"inUseAdapter\": \"eth\",\"hotspotActive\": false,"
|
||||
+ "\"wpsActive\": false,\"backendAvailable\": true,\"ethMacAddress\": "
|
||||
+ "[{\"id\": \"456\",\"config\": {\"name\": \"Arbeitszimmer\",\"type\": \"Other\"},"
|
||||
+ "\"desc\": \"/desc/location\"}]}}}");
|
||||
mockRequest(STATUS_URL, """
|
||||
{"gateway": {"serialNumber": "123",\
|
||||
"appVersion": "1.2.37.430","osVersion": "8.17","configVersion": 1200,\
|
||||
"operationStatus": "active","network": \
|
||||
{"ethCableAttached": true,"inUseAdapter": "eth","hotspotActive": false,\
|
||||
"wpsActive": false,"backendAvailable": true,"ethMacAddress": \
|
||||
[{"id": "456","config": {"name": "Arbeitszimmer","type": "Other"},\
|
||||
"desc": "/desc/location"}]}}}\
|
||||
""");
|
||||
assertEquals("1200", client.refreshStatus());
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ public class DeviceDTOTest {
|
||||
assertTrue(device.isReachable());
|
||||
assertFalse(device.hasLowBattery());
|
||||
|
||||
device.setMessageList(Collections.singletonList(createMessage(MessageDTO.TYPE_DEVICE_LOW_BATTERY)));
|
||||
device.setMessageList(List.of(createMessage(MessageDTO.TYPE_DEVICE_LOW_BATTERY)));
|
||||
|
||||
assertTrue(device.isReachable());
|
||||
assertTrue(device.hasLowBattery());
|
||||
@@ -52,7 +52,7 @@ public class DeviceDTOTest {
|
||||
assertTrue(device.isReachable());
|
||||
assertFalse(device.hasLowBattery());
|
||||
|
||||
device.setMessageList(Collections.singletonList(createMessage(MessageDTO.TYPE_DEVICE_UNREACHABLE)));
|
||||
device.setMessageList(List.of(createMessage(MessageDTO.TYPE_DEVICE_UNREACHABLE)));
|
||||
|
||||
assertFalse(device.isReachable());
|
||||
assertFalse(device.hasLowBattery());
|
||||
@@ -126,7 +126,7 @@ public class DeviceDTOTest {
|
||||
assertFalse(device.isReachable());
|
||||
assertTrue(device.hasLowBattery());
|
||||
|
||||
messages = Collections.singletonList(createMessage("UNKNOWN"));
|
||||
messages = List.of(createMessage("UNKNOWN"));
|
||||
device.setMessageList(messages);
|
||||
|
||||
// Nothing should get changed.
|
||||
@@ -144,7 +144,7 @@ public class DeviceDTOTest {
|
||||
assertTrue(device.isReachable());
|
||||
assertFalse(device.hasLowBattery());
|
||||
|
||||
device.setMessageList(Collections.singletonList(createMessage("UNKNOWN")));
|
||||
device.setMessageList(List.of(createMessage("UNKNOWN")));
|
||||
|
||||
assertTrue(device.isReachable());
|
||||
assertFalse(device.hasLowBattery());
|
||||
|
||||
@@ -18,9 +18,9 @@ import static org.openhab.binding.livisismarthome.internal.LivisiBindingConstant
|
||||
import static org.openhab.binding.livisismarthome.internal.client.api.entity.link.LinkDTO.LINK_TYPE_DEVICE;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
@@ -363,7 +363,7 @@ public class LivisiBridgeHandlerTest {
|
||||
|
||||
livisiClientMock = mock(LivisiClient.class);
|
||||
fullDeviceManagerMock = mock(FullDeviceManager.class);
|
||||
when(fullDeviceManagerMock.getFullDevices()).thenReturn(Collections.singletonList(bridgeDevice));
|
||||
when(fullDeviceManagerMock.getFullDevices()).thenReturn(List.of(bridgeDevice));
|
||||
|
||||
schedulerMock = mock(ScheduledExecutorService.class);
|
||||
|
||||
|
||||
@@ -1754,7 +1754,7 @@ public class LivisiDeviceHandlerTest {
|
||||
ThingUID thingUID = new ThingUID(thingTypeUID, device.getId());
|
||||
|
||||
Configuration thingConfiguration = new Configuration();
|
||||
thingConfiguration.setProperties(Collections.singletonMap(PROPERTY_ID, device.getId()));
|
||||
thingConfiguration.setProperties(Map.of(PROPERTY_ID, device.getId()));
|
||||
|
||||
Thing thingMock = mock(Thing.class);
|
||||
when(thingMock.getBridgeUID()).thenReturn(bridgeThingUID);
|
||||
|
||||
Reference in New Issue
Block a user