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:
@@ -171,7 +171,7 @@ public class SunspecDiscoveryProcess {
|
||||
|
||||
Optional<DecimalType> id = ModbusBitUtilities.extractStateFromRegisters(registers, 0, ValueType.UINT32);
|
||||
|
||||
if (!id.isPresent() || id.get().longValue() != SUNSPEC_ID) {
|
||||
if (id.isEmpty() || id.get().longValue() != SUNSPEC_ID) {
|
||||
logger.debug("Could not find SunSpec DID at address {}, received: {}, expected: {}", baseAddress, id,
|
||||
SUNSPEC_ID);
|
||||
detectModel();
|
||||
@@ -207,7 +207,7 @@ public class SunspecDiscoveryProcess {
|
||||
Optional<DecimalType> blockLength = ModbusBitUtilities.extractStateFromRegisters(registers, 1,
|
||||
ValueType.UINT16);
|
||||
|
||||
if (!moduleID.isPresent() || !blockLength.isPresent()) {
|
||||
if (moduleID.isEmpty() || blockLength.isEmpty()) {
|
||||
logger.info("Could not find valid module id or block length field.");
|
||||
parsingFinished();
|
||||
return;
|
||||
|
||||
@@ -257,9 +257,8 @@ public abstract class AbstractSunSpecHandler extends BaseThingHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (handler instanceof ModbusEndpointThingHandler) {
|
||||
ModbusEndpointThingHandler slaveEndpoint = (ModbusEndpointThingHandler) handler;
|
||||
return slaveEndpoint;
|
||||
if (handler instanceof ModbusEndpointThingHandler thingHandler) {
|
||||
return thingHandler;
|
||||
} else {
|
||||
logger.debug("Unexpected bridge handler: {}", handler);
|
||||
return null;
|
||||
@@ -433,7 +432,7 @@ public abstract class AbstractSunSpecHandler extends BaseThingHandler {
|
||||
* @return the scaled value as a DecimalType
|
||||
*/
|
||||
protected State getScaled(Optional<? extends Number> value, Optional<Short> scaleFactor, Unit<?> unit) {
|
||||
if (!value.isPresent() || !scaleFactor.isPresent()) {
|
||||
if (value.isEmpty() || scaleFactor.isEmpty()) {
|
||||
return UnDefType.UNDEF;
|
||||
}
|
||||
return getScaled(value.get().longValue(), scaleFactor.get(), unit);
|
||||
|
||||
Reference in New Issue
Block a user