From 2e7f4502c010184810c6eaf1171634ed808b328d Mon Sep 17 00:00:00 2001 From: Hilbrand Bouwkamp Date: Wed, 3 Apr 2019 11:56:34 +0200 Subject: [PATCH] Fixed SAT warnings. Signed-off-by: Hilbrand Bouwkamp --- .../dsmr/internal/device/DSMRDevice.java | 3 +++ .../dsmr/internal/device/cosem/CosemDate.java | 2 ++ .../internal/device/cosem/CosemDecimal.java | 2 ++ .../internal/device/cosem/CosemHexString.java | 2 ++ .../internal/device/cosem/CosemObject.java | 2 ++ .../device/cosem/CosemObjectFactory.java | 13 +++++++----- .../internal/device/cosem/CosemQuantity.java | 5 ++++- .../internal/device/cosem/CosemString.java | 2 ++ .../device/cosem/CosemValueDescriptor.java | 2 ++ .../internal/device/cosem/OBISIdentifier.java | 21 ++++++++++++------- .../internal/device/p1telegram/CRC16.java | 4 ++++ .../meter/DSMRMeterConfiguration.java | 3 +++ 12 files changed, 47 insertions(+), 14 deletions(-) diff --git a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/DSMRDevice.java b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/DSMRDevice.java index 2440b3e831ab6..ed0ee99a02c08 100644 --- a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/DSMRDevice.java +++ b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/DSMRDevice.java @@ -12,11 +12,14 @@ */ package org.openhab.binding.dsmr.internal.device; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * Interface for classes controlling DSMR devices. * * @author Hilbrand Bouwkamp - Initial contribution */ +@NonNullByDefault public interface DSMRDevice { /** diff --git a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemDate.java b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemDate.java index 94821fb139c52..54141856ca251 100644 --- a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemDate.java +++ b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemDate.java @@ -20,6 +20,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.smarthome.core.library.types.DateTimeType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,6 +31,7 @@ * @author M. Volaart - Initial contribution * @author Hilbrand Bouwkamp - Class now a factory instead of data containing class */ +@NonNullByDefault class CosemDate extends CosemValueDescriptor { public static final CosemDate INSTANCE = new CosemDate("timestamp"); diff --git a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemDecimal.java b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemDecimal.java index 49b42e135d376..a09f093ac8af7 100644 --- a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemDecimal.java +++ b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemDecimal.java @@ -14,6 +14,7 @@ import java.text.ParseException; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.smarthome.core.library.types.DecimalType; /** @@ -22,6 +23,7 @@ * @author M. Volaart - Initial contribution * @author Hilbrand Bouwkamp - Combined Integer and Double because {@link DecimalType} handles both */ +@NonNullByDefault class CosemDecimal extends CosemValueDescriptor { public static final CosemDecimal INSTANCE = new CosemDecimal(); diff --git a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemHexString.java b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemHexString.java index 7f447af52b89c..9587570f6a9c0 100644 --- a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemHexString.java +++ b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemHexString.java @@ -14,6 +14,7 @@ import java.text.ParseException; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.smarthome.core.library.types.StringType; /** @@ -22,6 +23,7 @@ * @author M. Volaart - Initial contribution * @author Hilbrand Bouwkamp - Class now a factory instead of data containing class */ +@NonNullByDefault class CosemHexString extends CosemValueDescriptor { public static final CosemHexString INSTANCE = new CosemHexString(); diff --git a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemObject.java b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemObject.java index 693fd244eef35..c25caa3857b37 100644 --- a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemObject.java +++ b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemObject.java @@ -19,6 +19,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.smarthome.core.types.State; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,6 +29,7 @@ * * @author M. Volaart - Initial contribution */ +@NonNullByDefault public class CosemObject { /** diff --git a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemObjectFactory.java b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemObjectFactory.java index ff1977efc49df..f2f665992f167 100644 --- a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemObjectFactory.java +++ b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemObjectFactory.java @@ -18,6 +18,8 @@ import java.util.List; import java.util.Map; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,6 +28,7 @@ * * @author M. Volaart - Initial contribution */ +@NonNullByDefault public class CosemObjectFactory { private final Logger logger = LoggerFactory.getLogger(CosemObjectFactory.class); @@ -84,7 +87,7 @@ public CosemObjectFactory() { * @param cosemStringValues String containing Cosem values * @return CosemObject or null if parsing failed */ - public CosemObject getCosemObject(String obisIdString, String cosemStringValues) { + public @Nullable CosemObject getCosemObject(String obisIdString, String cosemStringValues) { OBISIdentifier obisId; OBISIdentifier reducedObisId; @@ -112,7 +115,7 @@ public CosemObject getCosemObject(String obisIdString, String cosemStringValues) cosemObject = getCosemObjectInternal(obisMsgType, obisId, cosemStringValues); if (cosemObject != null) { logger.trace("Searched reducedObisId {} in the wild card type list, result: {}", reducedObisId, - cosemObject); + cosemObject); obisLookupTableDynamic.put(reducedObisId, obisMsgType); break; } @@ -136,8 +139,8 @@ public CosemObject getCosemObject(String obisIdString, String cosemStringValues) * * @return a CosemObject or null if parsing failed */ - private CosemObject getCosemObjectInternal(CosemObjectType cosemObjectType, OBISIdentifier obisIdentifier, - String cosemStringValues) { + private @Nullable CosemObject getCosemObjectInternal(CosemObjectType cosemObjectType, OBISIdentifier obisIdentifier, + String cosemStringValues) { CosemObject obj = new CosemObject(cosemObjectType, obisIdentifier); try { @@ -147,7 +150,7 @@ private CosemObject getCosemObjectInternal(CosemObjectType cosemObjectType, OBIS return obj; } catch (ParseException pe) { logger.trace("Failed to construct Cosem Object for type {}, values: {}", cosemObjectType, cosemStringValues, - pe); + pe); } return null; } diff --git a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemQuantity.java b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemQuantity.java index 84b13ed607c38..60f81748ac2f1 100644 --- a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemQuantity.java +++ b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemQuantity.java @@ -24,6 +24,8 @@ import javax.measure.quantity.Power; import javax.measure.quantity.Volume; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.smarthome.core.library.types.QuantityType; import org.eclipse.smarthome.core.library.unit.MetricPrefix; import org.eclipse.smarthome.core.library.unit.SIUnits; @@ -39,7 +41,8 @@ * * @param The {@link Quantity} type of the unit of this class */ -class CosemQuantity> extends CosemValueDescriptor> { +@NonNullByDefault +class CosemQuantity> extends CosemValueDescriptor> { public static final Unit KILO_VAR_UNIT = MetricPrefix.KILO(new BaseUnit("var")); public static final Unit KILO_VAR_HOUR_UNIT = MetricPrefix.KILO(new BaseUnit("varh")); diff --git a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemString.java b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemString.java index 53bcfe713f35f..424e8a82369fb 100644 --- a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemString.java +++ b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemString.java @@ -12,6 +12,7 @@ */ package org.openhab.binding.dsmr.internal.device.cosem; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.smarthome.core.library.types.StringType; /** @@ -20,6 +21,7 @@ * @author M. Volaart - Initial contribution * @author Hilbrand Bouwkamp - Class now a factory instead of data containing class */ +@NonNullByDefault class CosemString extends CosemValueDescriptor { public static final CosemString INSTANCE = new CosemString(); diff --git a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemValueDescriptor.java b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemValueDescriptor.java index 985674faf3fc1..45af03244ddea 100644 --- a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemValueDescriptor.java +++ b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemValueDescriptor.java @@ -14,6 +14,7 @@ import java.text.ParseException; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.smarthome.core.types.State; /** @@ -21,6 +22,7 @@ * * @author M. Volaart - Initial contribution */ +@NonNullByDefault abstract class CosemValueDescriptor { /** diff --git a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/OBISIdentifier.java b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/OBISIdentifier.java index 6c6bed7517c66..fd5c4aa51303a 100644 --- a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/OBISIdentifier.java +++ b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/OBISIdentifier.java @@ -17,12 +17,16 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + /** * Class representing an OBISIdentifier * * @author M. Volaart - Initial contribution * @author Hilbrand Bouwkamp - Fix bug in regex pattern. */ +@NonNullByDefault public class OBISIdentifier { /** * String representing a-b:c.d.e.f OBIS ID @@ -36,11 +40,11 @@ public class OBISIdentifier { /* the six individual group values of the OBIS ID */ private int groupA; - private Integer groupB; + private @Nullable Integer groupB; private int groupC; private int groupD; - private Integer groupE; - private Integer groupF; + private @Nullable Integer groupE; + private @Nullable Integer groupF; /** * Constructs a new OBIS Identifier (A-B:C.D.E.F) @@ -52,7 +56,8 @@ public class OBISIdentifier { * @param groupE E value * @param groupF F value */ - public OBISIdentifier(int groupA, Integer groupB, int groupC, int groupD, Integer groupE, Integer groupF) { + public OBISIdentifier(int groupA, @Nullable Integer groupB, int groupC, int groupD, @Nullable Integer groupE, + @Nullable Integer groupF) { this.groupA = groupA; this.groupB = groupB; this.groupC = groupC; @@ -109,7 +114,7 @@ public int getGroupA() { /** * @return the groupB */ - public Integer getGroupB() { + public @Nullable Integer getGroupB() { return groupB; } @@ -130,14 +135,14 @@ public int getGroupD() { /** * @return the groupE */ - public Integer getGroupE() { + public @Nullable Integer getGroupE() { return groupE; } /** * @return the groupF */ - public Integer getGroupF() { + public @Nullable Integer getGroupF() { return groupF; } @@ -156,7 +161,7 @@ public String toString() { * @return true if both OBISIdentifiers match, false otherwise */ @Override - public boolean equals(Object other) { + public boolean equals(@Nullable Object other) { OBISIdentifier o; if (other != null && other instanceof OBISIdentifier) { o = (OBISIdentifier) other; diff --git a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/p1telegram/CRC16.java b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/p1telegram/CRC16.java index 0def3d29981a6..d7bc51fac9a78 100644 --- a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/p1telegram/CRC16.java +++ b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/p1telegram/CRC16.java @@ -12,6 +12,8 @@ */ package org.openhab.binding.dsmr.internal.device.p1telegram; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * CRC16 implementation. * @@ -22,7 +24,9 @@ * * @author M. Volaart - Initial contribution */ +@NonNullByDefault public class CRC16 { + public enum Polynom { CRC16_IBM(0xA001), // standard CRC-16 x16+x15+x2+1 (CRC-16-IBM) CRC16_IBM_REVERSE(0xC002), // standard reverse x16+x14+x+1 (CRC-16-IBM) diff --git a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/meter/DSMRMeterConfiguration.java b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/meter/DSMRMeterConfiguration.java index 7931e843aa630..9a4efe1425eb4 100644 --- a/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/meter/DSMRMeterConfiguration.java +++ b/addons/binding/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/meter/DSMRMeterConfiguration.java @@ -12,12 +12,15 @@ */ package org.openhab.binding.dsmr.internal.meter; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * This class describes the configuration for a meter. * * @author M. Volaart - Initial contribution * @author Hilbrand Bouwkamp - Added refresh field */ +@NonNullByDefault public class DSMRMeterConfiguration { /** * M-Bus channel