Java 17 features (T-Z) (#15576)
- 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:
@@ -41,8 +41,8 @@ public class VeluxActions implements ThingActions {
|
||||
|
||||
@Override
|
||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||
if (handler instanceof VeluxBridgeHandler) {
|
||||
this.bridgeHandler = (VeluxBridgeHandler) handler;
|
||||
if (handler instanceof VeluxBridgeHandler veluxBridgeHandler) {
|
||||
this.bridgeHandler = veluxBridgeHandler;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +156,6 @@ class JCgetFirmware extends GetFirmware implements JsonBridgeCommunicationProtoc
|
||||
*/
|
||||
@Override
|
||||
public VeluxGwFirmware getFirmware() {
|
||||
VeluxGwFirmware gwFirmware = new VeluxGwFirmware(response.data.version);
|
||||
return gwFirmware;
|
||||
return new VeluxGwFirmware(response.data.version);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,8 +179,7 @@ class JCgetLANConfig extends GetLANConfig implements BridgeCommunicationProtocol
|
||||
*/
|
||||
@Override
|
||||
public VeluxGwLAN getLANConfig() {
|
||||
VeluxGwLAN gwLAN = new VeluxGwLAN(response.data.ipAddress, response.data.subnetMask,
|
||||
response.data.defaultGateway, response.data.dhcp);
|
||||
return gwLAN;
|
||||
return new VeluxGwLAN(response.data.ipAddress, response.data.subnetMask, response.data.defaultGateway,
|
||||
response.data.dhcp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +175,6 @@ class JCgetWLANConfig extends GetWLANConfig implements JsonBridgeCommunicationPr
|
||||
*/
|
||||
@Override
|
||||
public VeluxGwWLAN getWLANConfig() {
|
||||
VeluxGwWLAN gwWLAN = new VeluxGwWLAN(response.data.name, response.data.password);
|
||||
return gwWLAN;
|
||||
return new VeluxGwWLAN(response.data.name, response.data.password);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,10 +199,10 @@ public class VeluxHandlerFactory extends BaseThingHandlerFactory {
|
||||
veluxBindingHandlers.remove(thingHandler);
|
||||
} else
|
||||
// Handle Bridge removal
|
||||
if (thingHandler instanceof VeluxBridgeHandler) {
|
||||
if (thingHandler instanceof VeluxBridgeHandler veluxBridgeHandler) {
|
||||
logger.trace("removeHandler() removing bridge '{}'.", thingHandler.toString());
|
||||
veluxBridgeHandlers.remove(thingHandler);
|
||||
unregisterDeviceDiscoveryService((VeluxBridgeHandler) thingHandler);
|
||||
unregisterDeviceDiscoveryService(veluxBridgeHandler);
|
||||
} else
|
||||
// Handle removal of Things behind the Bridge
|
||||
if (thingHandler instanceof VeluxHandler) {
|
||||
|
||||
@@ -228,10 +228,10 @@ final class ChannelActuatorPosition extends ChannelHandlerTemplate {
|
||||
|
||||
switch (channelId) {
|
||||
case CHANNEL_VANE_POSITION:
|
||||
if (command instanceof PercentType) {
|
||||
if (command instanceof PercentType percentCommand) {
|
||||
VeluxProduct existingProductClone = existingProducts.get(productBridgeIndex).clone();
|
||||
existingProductClone.setVanePosition(
|
||||
new VeluxProductPosition((PercentType) command).getPositionAsVeluxType());
|
||||
existingProductClone
|
||||
.setVanePosition(new VeluxProductPosition(percentCommand).getPositionAsVeluxType());
|
||||
functionalParameters = existingProductClone.getFunctionalParameters();
|
||||
}
|
||||
break;
|
||||
@@ -243,12 +243,12 @@ final class ChannelActuatorPosition extends ChannelHandlerTemplate {
|
||||
: new VeluxProductPosition(PercentType.HUNDRED);
|
||||
} else if (command instanceof StopMoveType) {
|
||||
mainParameter = StopMoveType.STOP.equals(command) ? new VeluxProductPosition() : mainParameter;
|
||||
} else if (command instanceof PercentType) {
|
||||
PercentType ptCommand = (PercentType) command;
|
||||
} else if (command instanceof PercentType percentCommand) {
|
||||
if (veluxActuator.isInverted()) {
|
||||
ptCommand = new PercentType(PercentType.HUNDRED.intValue() - ptCommand.intValue());
|
||||
percentCommand = new PercentType(
|
||||
PercentType.HUNDRED.intValue() - percentCommand.intValue());
|
||||
}
|
||||
mainParameter = new VeluxProductPosition(ptCommand);
|
||||
mainParameter = new VeluxProductPosition(percentCommand);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -268,7 +268,7 @@ final class ChannelActuatorPosition extends ChannelHandlerTemplate {
|
||||
LOGGER.debug("handleCommand(): sending command '{}' for channel id '{}'.", command, channelId);
|
||||
RunProductCommand bcp = thisBridgeHandler.thisBridge.bridgeAPI().runProductCommand();
|
||||
boolean success = false;
|
||||
if (bcp instanceof SCrunProductCommand) {
|
||||
if (bcp instanceof SCrunProductCommand productCommand) {
|
||||
synchronized (bcp) {
|
||||
if (bcp.setNodeIdAndParameters(productBridgeIndex.toInt(), mainParameter, functionalParameters)
|
||||
&& thisBridgeHandler.thisBridge.bridgeCommunicate(bcp)
|
||||
@@ -278,7 +278,7 @@ final class ChannelActuatorPosition extends ChannelHandlerTemplate {
|
||||
.autoRefresh(thisBridgeHandler.thisBridge)) {
|
||||
LOGGER.trace("handleCommand(): actuator position will be updated via polling.");
|
||||
}
|
||||
if (existingProducts.update(((SCrunProductCommand) bcp).getProduct())) {
|
||||
if (existingProducts.update(productCommand.getProduct())) {
|
||||
LOGGER.trace("handleCommand(): actuator position immediate update requested.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1029,8 +1029,8 @@ public class VeluxBridgeHandler extends ExtendedBaseBridgeHandler implements Vel
|
||||
private void updateDynamicChannels() {
|
||||
getThing().getThings().stream().forEach(thing -> {
|
||||
ThingHandler thingHandler = thing.getHandler();
|
||||
if (thingHandler instanceof VeluxHandler) {
|
||||
((VeluxHandler) thingHandler).updateDynamicChannels(this);
|
||||
if (thingHandler instanceof VeluxHandler veluxHandler) {
|
||||
veluxHandler.updateDynamicChannels(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class VeluxProduct {
|
||||
*
|
||||
* @author AndrewFG - Initial contribution.
|
||||
*/
|
||||
public static enum ProductState {
|
||||
public enum ProductState {
|
||||
NON_EXECUTING(0),
|
||||
ERROR(1),
|
||||
NOT_USED(2),
|
||||
@@ -137,9 +137,9 @@ public class VeluxProduct {
|
||||
*
|
||||
* @author AndrewFG - Initial contribution.
|
||||
*/
|
||||
public static enum DataSource {
|
||||
public enum DataSource {
|
||||
GATEWAY,
|
||||
BINDING;
|
||||
BINDING
|
||||
}
|
||||
|
||||
// Class internal
|
||||
|
||||
@@ -73,7 +73,7 @@ public class VeluxProductPosition {
|
||||
*
|
||||
* @author AndrewFG - Initial contribution.
|
||||
*/
|
||||
public static enum PositionType {
|
||||
public enum PositionType {
|
||||
ABSOLUTE_VALUE(0f),
|
||||
OFFSET_POSITIVE(1f),
|
||||
OFFSET_NEGATIVE(-1f);
|
||||
|
||||
@@ -44,7 +44,7 @@ public enum VeluxProductType {
|
||||
SWITCH,
|
||||
UNDEFTYPE;
|
||||
|
||||
public static enum ActuatorType {
|
||||
public enum ActuatorType {
|
||||
UNDEFTYPE((short) 0xffff, VeluxBindingConstants.UNKNOWN, VeluxProductType.SWITCH),
|
||||
BLIND_1_0((short) 0x0040, "Interior Venetian Blind", VeluxProductType.SLIDER_SHUTTER),
|
||||
ROLLERSHUTTER_2_0((short) 0x0080, "Roller Shutter", VeluxProductType.SLIDER_SHUTTER),
|
||||
|
||||
@@ -49,8 +49,6 @@ public class ManifestInformation {
|
||||
* @return <B>bundleVersion</B> the resulted bundle version as {@link String}.
|
||||
*/
|
||||
public static String getBundleVersion() {
|
||||
String osgiBundleVersion = FrameworkUtil.getBundle(ManifestInformation.class).getBundleContext().getBundle()
|
||||
.toString();
|
||||
return osgiBundleVersion;
|
||||
return FrameworkUtil.getBundle(ManifestInformation.class).getBundleContext().getBundle().toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,10 +107,12 @@ public class TestNotificationsAndDatabase {
|
||||
@Order(3)
|
||||
public void testSCgetProduct() {
|
||||
// initialise the test parameters
|
||||
final String packet = "06 00 06 00 48 6F 62 62 79 6B 61 6D 65 72 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
|
||||
+ " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
|
||||
+ " 00 00 00 00 00 01 04 40 00 00 00 00 00 00 00 00 00 00 00 00 00 2D C8 00 C8 00 F7 FF F7 FF 00 00 F7 FF 00"
|
||||
+ " 00 4F 00 4A EA 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00";
|
||||
final String packet = """
|
||||
06 00 06 00 48 6F 62 62 79 6B 61 6D 65 72 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
|
||||
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
|
||||
00 00 00 00 00 01 04 40 00 00 00 00 00 00 00 00 00 00 00 00 00 2D C8 00 C8 00 F7 FF F7 FF 00 00 F7 FF 00\
|
||||
00 4F 00 4A EA 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
|
||||
""";
|
||||
final Command command = VeluxKLFAPI.Command.GW_GET_NODE_INFORMATION_NTF;
|
||||
|
||||
// initialise the BCP
|
||||
@@ -198,8 +200,10 @@ public class TestNotificationsAndDatabase {
|
||||
@Order(5)
|
||||
public void testSCgetProductStatus() {
|
||||
// initialise the test parameters
|
||||
final String packet = "00 D8 01 06 00 01 01 02 00 C8 00 03 63 4F 00 00 00 00 00 00 00 00 00 00 00 00 00"
|
||||
+ " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00";
|
||||
final String packet = """
|
||||
00 D8 01 06 00 01 01 02 00 C8 00 03 63 4F 00 00 00 00 00 00 00 00 00 00 00 00 00\
|
||||
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
|
||||
""";
|
||||
final Command command = VeluxKLFAPI.Command.GW_STATUS_REQUEST_NTF;
|
||||
|
||||
// initialise the BCP
|
||||
@@ -334,10 +338,12 @@ public class TestNotificationsAndDatabase {
|
||||
@Order(9)
|
||||
public void testSCgetProductOnVelux() {
|
||||
// initialise the test parameters
|
||||
final String packet = "00 00 00 00 53 68 65 64 20 57 69 6E 64 6F 77 00 00 00 00 00 00 00 00 00 00 00 00 00"
|
||||
+ " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
|
||||
+ " 00 00 00 00 00 00 00 00 01 01 01 03 07 00 01 16 56 24 5C 26 14 19 00 FC 05 46 00 46 00 F7 FF F7"
|
||||
+ " FF F7 FF F7 FF 00 00 4F 05 B3 5F 01 D8 03 B2 1C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00";
|
||||
final String packet = """
|
||||
00 00 00 00 53 68 65 64 20 57 69 6E 64 6F 77 00 00 00 00 00 00 00 00 00 00 00 00 00\
|
||||
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
|
||||
00 00 00 00 00 00 00 00 01 01 01 03 07 00 01 16 56 24 5C 26 14 19 00 FC 05 46 00 46 00 F7 FF F7\
|
||||
FF F7 FF F7 FF 00 00 4F 05 B3 5F 01 D8 03 B2 1C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
|
||||
""";
|
||||
final short command = VeluxKLFAPI.Command.GW_GET_NODE_INFORMATION_NTF.getShort();
|
||||
|
||||
// initialise the BCP
|
||||
@@ -454,9 +460,11 @@ public class TestNotificationsAndDatabase {
|
||||
@Test
|
||||
@Order(12)
|
||||
public void testSCrunProductA() {
|
||||
final String expectedString = "02 1C 08 05 00 20 00 90 00 00 00 00 00 A0 00 00 00 00 00 00 00 00 00 00 00"
|
||||
+ " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
|
||||
+ " 00 00 00 00 00 00 00 00 00";
|
||||
final String expectedString = """
|
||||
02 1C 08 05 00 20 00 90 00 00 00 00 00 A0 00 00 00 00 00 00 00 00 00 00 00\
|
||||
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
|
||||
00 00 00 00 00 00 00 00 00\
|
||||
""";
|
||||
final byte[] expectedPacket = toByteArray(expectedString);
|
||||
final int targetMainPosition = 0x9000;
|
||||
final int targetVanePosition = 0xA000;
|
||||
@@ -885,9 +893,11 @@ public class TestNotificationsAndDatabase {
|
||||
@Order(21)
|
||||
public void testErrorStateMapping() {
|
||||
// initialise the test parameters
|
||||
final String packet = "0F A3 01 06 01 00 01 02 00 9A 36 03 00 00 00 00 00 00 00 00 00 00 00 00 00"
|
||||
+ " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
|
||||
+ " 00 00 00 00 00";
|
||||
final String packet = """
|
||||
0F A3 01 06 01 00 01 02 00 9A 36 03 00 00 00 00 00 00 00 00 00 00 00 00 00\
|
||||
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
|
||||
00 00 00 00 00\
|
||||
""";
|
||||
final Command command = VeluxKLFAPI.Command.GW_STATUS_REQUEST_NTF;
|
||||
|
||||
// initialise the BCP
|
||||
|
||||
Reference in New Issue
Block a user