Java 17 features (A-G) (#15516)
- 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:
@@ -194,8 +194,8 @@ public class OBISIdentifier {
|
||||
@Override
|
||||
public boolean equals(@Nullable final Object other) {
|
||||
OBISIdentifier o;
|
||||
if (other != null && other instanceof OBISIdentifier) {
|
||||
o = (OBISIdentifier) other;
|
||||
if (other != null && other instanceof OBISIdentifier identifier) {
|
||||
o = identifier;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -125,9 +125,11 @@ public class DSMRBridgeDiscoveryService extends DSMRDiscoveryService implements
|
||||
logger.trace("Possible port to check:{}, owned:{} by:{}", currentScannedPortName,
|
||||
portIdentifier.isCurrentlyOwned(), portIdentifier.getCurrentOwner());
|
||||
if (DSMR_PORT_NAME.equals(portIdentifier.getCurrentOwner())) {
|
||||
logger.debug("The port {} is owned by this binding. If no DSMR meters will be found it "
|
||||
+ "might indicate the port is locked by an older instance of this binding. "
|
||||
+ "Restart the system to unlock the port.", currentScannedPortName);
|
||||
logger.debug("""
|
||||
The port {} is owned by this binding. If no DSMR meters will be found it \
|
||||
might indicate the port is locked by an older instance of this binding. \
|
||||
Restart the system to unlock the port.\
|
||||
""", currentScannedPortName);
|
||||
}
|
||||
} else {
|
||||
logger.debug("Start discovery on serial port: {}", currentScannedPortName);
|
||||
|
||||
@@ -76,8 +76,8 @@ public class DSMRMeterDiscoveryService extends DSMRDiscoveryService implements P
|
||||
|
||||
@Override
|
||||
public void setThingHandler(final ThingHandler handler) {
|
||||
if (handler instanceof DSMRBridgeHandler) {
|
||||
dsmrBridgeHandler = (DSMRBridgeHandler) handler;
|
||||
if (handler instanceof DSMRBridgeHandler bridgeHandler) {
|
||||
dsmrBridgeHandler = bridgeHandler;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,14 +124,18 @@ public class DSMRMeterDiscoveryService extends DSMRDiscoveryService implements P
|
||||
reportUnregisteredMeters();
|
||||
} else {
|
||||
reportUnrecognizedCosemObjects(list);
|
||||
logger.info("There are unrecognized cosem values in the data received from the meter,"
|
||||
+ " which means some meters might not be detected. Please report your raw data as reference: {}",
|
||||
telegram.getRawTelegram());
|
||||
logger.info("""
|
||||
There are unrecognized cosem values in the data received from the meter,\
|
||||
which means some meters might not be detected. Please report your raw data as reference: {}\
|
||||
""", telegram.getRawTelegram());
|
||||
}
|
||||
}
|
||||
if (!telegram.getUnknownCosemObjects().isEmpty()) {
|
||||
logger.info("There are unrecognized cosem values in the data received from the meter,"
|
||||
+ " which means you have values that can't be read by a channel: {}. Please report them and your raw data as reference: {}",
|
||||
logger.info(
|
||||
"""
|
||||
There are unrecognized cosem values in the data received from the meter,\
|
||||
which means you have values that can't be read by a channel: {}. Please report them and your raw data as reference: {}\
|
||||
""",
|
||||
telegram.getUnknownCosemObjects().stream()
|
||||
.map(e -> String.format("obis id:%s, value:%s", e.getKey(), e.getValue()))
|
||||
.collect(Collectors.joining(", ")),
|
||||
@@ -196,10 +200,10 @@ public class DSMRMeterDiscoveryService extends DSMRDiscoveryService implements P
|
||||
*/
|
||||
protected void reportConfigurationValidationResults(final List<DSMRMeterType> invalidConfigured,
|
||||
final List<DSMRMeterType> unconfiguredMeters) {
|
||||
logger.info(
|
||||
"Possible incorrect meters configured. These are configured: {}."
|
||||
+ "But the following unconfigured meters are found in the data received from the meter: {}",
|
||||
invalidConfigured.stream().map(m -> m.name()).collect(Collectors.joining(", ")),
|
||||
logger.info("""
|
||||
Possible incorrect meters configured. These are configured: {}.\
|
||||
But the following unconfigured meters are found in the data received from the meter: {}\
|
||||
""", invalidConfigured.stream().map(m -> m.name()).collect(Collectors.joining(", ")),
|
||||
unconfiguredMeters.stream().map(m -> m.name()).collect(Collectors.joining(", ")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,12 +73,11 @@ public class DSMRMeter {
|
||||
*/
|
||||
public List<CosemObject> filterMeterValues(List<CosemObject> cosemObjects, int channel) {
|
||||
logger.trace("supported identifiers: {}, searching for objects {}", supportedIdentifiers, cosemObjects);
|
||||
List<CosemObject> filteredValues = cosemObjects.stream()
|
||||
return cosemObjects.stream()
|
||||
.filter(cosemObject -> (DSMRMeterConstants.UNKNOWN_CHANNEL == channel
|
||||
|| cosemObject.getObisIdentifier().getChannel() == channel)
|
||||
&& supportedIdentifiers.contains(cosemObject.getObisIdentifier().getReducedOBISIdentifier()))
|
||||
.collect(Collectors.toList());
|
||||
return filteredValues;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.openhab.binding.dsmr.internal.TelegramReaderUtil;
|
||||
public class P1TelegramParserTest {
|
||||
|
||||
// @formatter:off
|
||||
public static final List<Object[]> data() {
|
||||
public static List<Object[]> data() {
|
||||
return Arrays.asList(new Object[][] {
|
||||
{ "ace4000", 59, 0},
|
||||
{ "dsmr_40", 39, 0},
|
||||
|
||||
@@ -54,7 +54,7 @@ import org.openhab.binding.dsmr.internal.meter.DSMRMeterType;
|
||||
public class DSMRMeterDetectorTest {
|
||||
|
||||
// @formatter:off
|
||||
public static final List<Object[]> data() {
|
||||
public static List<Object[]> data() {
|
||||
return Arrays.asList(new Object[][] {
|
||||
{ "ace4000", EnumSet.of(ELECTRICITY_ACE4000, GAS_ACE4000)},
|
||||
{ "dsmr_40", EnumSet.of(DEVICE_V4, ELECTRICITY_V4_2, M3_V5_0)},
|
||||
|
||||
Reference in New Issue
Block a user