[knx] Java17 instanceof pattern matching (#14718)
Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
parent
2c2ba4bed1
commit
dba83a33e5
|
@ -78,8 +78,7 @@ public class DPTUnits {
|
|||
for (Field field : fields) {
|
||||
try {
|
||||
Object o = field.get(null);
|
||||
if (o instanceof DPT) {
|
||||
DPT dpt = (DPT) o;
|
||||
if (o instanceof DPT dpt) {
|
||||
String unit = dpt.getUnit().replaceAll(" ", "");
|
||||
// Calimero provides some units (like "ms⁻²") that can't be parsed by our library because of the
|
||||
// negative exponent
|
||||
|
|
|
@ -87,8 +87,8 @@ public class ValueEncoder {
|
|||
DPT dpt = translator.getType();
|
||||
|
||||
// check for HSBType first, because it extends PercentType as well
|
||||
if (value instanceof HSBType) {
|
||||
return handleHSBType(dptId, (HSBType) value);
|
||||
if (value instanceof HSBType type) {
|
||||
return handleHSBType(dptId, type);
|
||||
} else if (value instanceof OnOffType) {
|
||||
return OnOffType.OFF.equals(value) ? dpt.getLowerValue() : dpt.getUpperValue();
|
||||
} else if (value instanceof UpDownType) {
|
||||
|
@ -101,15 +101,15 @@ public class ValueEncoder {
|
|||
return OpenClosedType.CLOSED.equals(value) ? dpt.getLowerValue() : dpt.getUpperValue();
|
||||
} else if (value instanceof StopMoveType) {
|
||||
return StopMoveType.STOP.equals(value) ? dpt.getLowerValue() : dpt.getUpperValue();
|
||||
} else if (value instanceof PercentType) {
|
||||
int intValue = ((PercentType) value).intValue();
|
||||
} else if (value instanceof PercentType type) {
|
||||
int intValue = type.intValue();
|
||||
return "251.600".equals(dptId) ? String.format("- - - %d %%", intValue) : String.valueOf(intValue);
|
||||
} else if (value instanceof DecimalType || value instanceof QuantityType<?>) {
|
||||
return handleNumericTypes(dptId, mainNumber, dpt, value);
|
||||
} else if (value instanceof StringType) {
|
||||
return value.toString();
|
||||
} else if (value instanceof DateTimeType) {
|
||||
return handleDateTimeType(dptId, (DateTimeType) value);
|
||||
} else if (value instanceof DateTimeType type) {
|
||||
return handleDateTimeType(dptId, type);
|
||||
}
|
||||
} catch (KNXException e) {
|
||||
return null;
|
||||
|
|
|
@ -366,9 +366,9 @@ public class DeviceThingHandler extends BaseThingHandler implements GroupAddress
|
|||
if (oldFuture != null) {
|
||||
oldFuture.cancel(true);
|
||||
}
|
||||
if (value instanceof IncreaseDecreaseType) {
|
||||
if (value instanceof IncreaseDecreaseType type) {
|
||||
channelFutures.put(channelUID, scheduler.scheduleWithFixedDelay(
|
||||
() -> postCommand(channelUID, (Command) value), 0, frequency, TimeUnit.MILLISECONDS));
|
||||
() -> postCommand(channelUID, type), 0, frequency, TimeUnit.MILLISECONDS));
|
||||
}
|
||||
} else {
|
||||
if (value instanceof Command command) {
|
||||
|
|
Loading…
Reference in New Issue