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

@@ -14,7 +14,6 @@ package org.openhab.binding.modbus.stiebeleltron.internal;
import static org.openhab.binding.modbus.stiebeleltron.internal.StiebelEltronBindingConstants.THING_TYPE_HEATPUMP;
import java.util.Collections;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -37,7 +36,7 @@ import org.osgi.service.component.annotations.Component;
@Component(configurationPid = "binding.stiebeleltron", service = ThingHandlerFactory.class)
public class StiebelEltronHandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_HEATPUMP);
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_HEATPUMP);
@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {

View File

@@ -90,7 +90,6 @@ public class StiebelEltronHandler extends BaseThingHandler {
* Register poll task This is where we set up our regular poller
*/
public synchronized void registerPollTask(int address, int length, ModbusReadFunctionCode readFunctionCode) {
logger.debug("Setting up regular polling");
ModbusCommunicationInterface mycomms = StiebelEltronHandler.this.comms;
@@ -220,16 +219,15 @@ public class StiebelEltronHandler extends BaseThingHandler {
* the stiebel eltron modbus documentation)
*/
private short getScaledInt16Value(Command command) throws StiebelEltronException {
if (command instanceof QuantityType) {
QuantityType<?> c = ((QuantityType<?>) command).toUnit(CELSIUS);
if (command instanceof QuantityType quantityCommand) {
QuantityType<?> c = quantityCommand.toUnit(CELSIUS);
if (c != null) {
return (short) (c.doubleValue() * 10);
} else {
throw new StiebelEltronException("Unsupported unit");
}
}
if (command instanceof DecimalType) {
DecimalType c = (DecimalType) command;
if (command instanceof DecimalType c) {
return (short) (c.doubleValue() * 10);
}
throw new StiebelEltronException("Unsupported command type");
@@ -240,8 +238,7 @@ public class StiebelEltronHandler extends BaseThingHandler {
* @return short the value of the command as short
*/
private short getInt16Value(Command command) throws StiebelEltronException {
if (command instanceof DecimalType) {
DecimalType c = (DecimalType) command;
if (command instanceof DecimalType c) {
return c.shortValue();
}
throw new StiebelEltronException("Unsupported command type");
@@ -327,7 +324,6 @@ public class StiebelEltronHandler extends BaseThingHandler {
* Start the periodic polling1
*/
private void startUp() {
if (comms != null) {
return;
}
@@ -479,9 +475,8 @@ public class StiebelEltronHandler extends BaseThingHandler {
return null;
}
if (handler instanceof ModbusEndpointThingHandler) {
ModbusEndpointThingHandler slaveEndpoint = (ModbusEndpointThingHandler) handler;
return slaveEndpoint;
if (handler instanceof ModbusEndpointThingHandler thingHandler) {
return thingHandler;
} else {
throw new IllegalStateException("Unexpected bridge handler: " + handler.toString());
}