Java 17 features (N-S) (#15565)

- 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:
Holger Friedrich
2023-09-13 08:03:31 +02:00
committed by GitHub
parent 641b482551
commit ab58f4ffb4
471 changed files with 1624 additions and 1868 deletions

View File

@@ -201,8 +201,8 @@ public class NikoHomeControlDiscoveryService extends AbstractDiscoveryService im
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof NikoHomeControlBridgeHandler) {
this.handler = (NikoHomeControlBridgeHandler) handler;
if (handler instanceof NikoHomeControlBridgeHandler homeControlBridgeHandler) {
this.handler = homeControlBridgeHandler;
bridgeUID = handler.getThing().getUID();
}
}

View File

@@ -125,9 +125,8 @@ public class NikoHomeControlActionHandler extends BaseThingHandler implements Nh
return;
}
if (command instanceof OnOffType) {
OnOffType s = (OnOffType) command;
if (OnOffType.OFF.equals(s)) {
if (command instanceof OnOffType onOffCommand) {
if (OnOffType.OFF.equals(onOffCommand)) {
nhcAction.execute(NHCOFF);
} else {
nhcAction.execute(NHCON);
@@ -142,18 +141,16 @@ public class NikoHomeControlActionHandler extends BaseThingHandler implements Nh
return;
}
if (command instanceof OnOffType) {
OnOffType s = (OnOffType) command;
if (OnOffType.OFF.equals(s)) {
if (command instanceof OnOffType onOffCommand) {
if (OnOffType.OFF.equals(onOffCommand)) {
nhcAction.execute(NHCOFF);
} else {
nhcAction.execute(NHCON);
}
} else if (command instanceof IncreaseDecreaseType) {
IncreaseDecreaseType s = (IncreaseDecreaseType) command;
} else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) {
int currentValue = nhcAction.getState();
int newValue;
if (IncreaseDecreaseType.INCREASE.equals(s)) {
if (IncreaseDecreaseType.INCREASE.equals(increaseDecreaseCommand)) {
newValue = currentValue + stepValue;
// round down to step multiple
newValue = newValue - newValue % stepValue;
@@ -168,12 +165,11 @@ public class NikoHomeControlActionHandler extends BaseThingHandler implements Nh
nhcAction.execute(Integer.toString(newValue));
}
}
} else if (command instanceof PercentType) {
PercentType p = (PercentType) command;
if (PercentType.ZERO.equals(p)) {
} else if (command instanceof PercentType percentCommand) {
if (PercentType.ZERO.equals(percentCommand)) {
nhcAction.execute(NHCOFF);
} else {
nhcAction.execute(Integer.toString(p.intValue()));
nhcAction.execute(Integer.toString(percentCommand.intValue()));
}
}
}
@@ -185,18 +181,17 @@ public class NikoHomeControlActionHandler extends BaseThingHandler implements Nh
return;
}
if (command instanceof UpDownType) {
UpDownType s = (UpDownType) command;
if (UpDownType.UP.equals(s)) {
if (command instanceof UpDownType upDownCommand) {
if (UpDownType.UP.equals(upDownCommand)) {
nhcAction.execute(!invert ? NHCUP : NHCDOWN);
} else {
nhcAction.execute(!invert ? NHCDOWN : NHCUP);
}
} else if (command instanceof StopMoveType) {
nhcAction.execute(NHCSTOP);
} else if (command instanceof PercentType) {
PercentType p = (PercentType) command;
nhcAction.execute(!invert ? Integer.toString(100 - p.intValue()) : Integer.toString(p.intValue()));
} else if (command instanceof PercentType percentCommand) {
nhcAction.execute(!invert ? Integer.toString(100 - percentCommand.intValue())
: Integer.toString(percentCommand.intValue()));
}
}
@@ -300,8 +295,7 @@ public class NikoHomeControlActionHandler extends BaseThingHandler implements Nh
properties.put("timeToClose", String.valueOf(nhcAction.getCloseTime()));
}
if (nhcAction instanceof NhcAction2) {
NhcAction2 action = (NhcAction2) nhcAction;
if (nhcAction instanceof NhcAction2 action) {
properties.put(PROPERTY_DEVICE_TYPE, action.getDeviceType());
properties.put(PROPERTY_DEVICE_TECHNOLOGY, action.getDeviceTechnology());
properties.put(PROPERTY_DEVICE_MODEL, action.getDeviceModel());

View File

@@ -163,8 +163,7 @@ public class NikoHomeControlEnergyMeterHandler extends BaseThingHandler implemen
private void updateProperties(NhcEnergyMeter nhcEnergyMeter) {
Map<String, String> properties = new HashMap<>();
if (nhcEnergyMeter instanceof NhcEnergyMeter2) {
NhcEnergyMeter2 energyMeter = (NhcEnergyMeter2) nhcEnergyMeter;
if (nhcEnergyMeter instanceof NhcEnergyMeter2 energyMeter) {
properties.put(PROPERTY_DEVICE_TYPE, energyMeter.getDeviceType());
properties.put(PROPERTY_DEVICE_TECHNOLOGY, energyMeter.getDeviceTechnology());
properties.put(PROPERTY_DEVICE_MODEL, energyMeter.getDeviceModel());

View File

@@ -110,8 +110,8 @@ public class NikoHomeControlThermostatHandler extends BaseThingHandler implement
updateStatus(ThingStatus.ONLINE);
break;
case CHANNEL_MODE:
if (command instanceof DecimalType) {
nhcThermostat.executeMode(((DecimalType) command).intValue());
if (command instanceof DecimalType decimalCommand) {
nhcThermostat.executeMode(decimalCommand.intValue());
}
updateStatus(ThingStatus.ONLINE);
break;
@@ -128,20 +128,20 @@ public class NikoHomeControlThermostatHandler extends BaseThingHandler implement
if (time <= 0) {
time = overruleTime;
}
if (command instanceof QuantityType<?>) {
QuantityType<?> setpoint = ((QuantityType<?>) command).toUnit(CELSIUS);
if (command instanceof QuantityType<?> quantityCommand) {
QuantityType<?> setpoint = quantityCommand.toUnit(CELSIUS);
if (setpoint != null) {
nhcThermostat.executeOverrule(Math.round(setpoint.floatValue() * 10), time);
}
} else if (command instanceof DecimalType) {
BigDecimal setpoint = ((DecimalType) command).toBigDecimal();
} else if (command instanceof DecimalType decimalCommand) {
BigDecimal setpoint = decimalCommand.toBigDecimal();
nhcThermostat.executeOverrule(Math.round(setpoint.floatValue() * 10), time);
}
updateStatus(ThingStatus.ONLINE);
break;
case CHANNEL_OVERRULETIME:
if (command instanceof DecimalType) {
int overruletime = ((DecimalType) command).intValue();
if (command instanceof DecimalType decimalCommand) {
int overruletime = decimalCommand.intValue();
int overrule = nhcThermostat.getOverrule();
if (overruletime <= 0) {
overruletime = 0;
@@ -244,8 +244,7 @@ public class NikoHomeControlThermostatHandler extends BaseThingHandler implement
private void updateProperties(NhcThermostat nhcThermostat) {
Map<String, String> properties = new HashMap<>();
if (nhcThermostat instanceof NhcThermostat2) {
NhcThermostat2 thermostat = (NhcThermostat2) nhcThermostat;
if (nhcThermostat instanceof NhcThermostat2 thermostat) {
properties.put(PROPERTY_DEVICE_TYPE, thermostat.getDeviceType());
properties.put(PROPERTY_DEVICE_TECHNOLOGY, thermostat.getDeviceTechnology());
properties.put(PROPERTY_DEVICE_MODEL, thermostat.getDeviceModel());

View File

@@ -23,7 +23,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
public class NikoHomeControlConstants {
// Action types abstracted from NhcI and NhcII action types
public static enum ActionType {
public enum ActionType {
TRIGGER,
RELAY,
DIMMER,

View File

@@ -62,7 +62,7 @@ public class NhcMqttConnection2 implements MqttActionCallback {
private MqttMessageSubscriber messageSubscriber;
private MqttConnectionObserver connectionObserver;
private TrustManager trustManagers[];
private TrustManager[] trustManagers;
private String clientId;
private volatile String cocoAddress = "";