100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Added equals override to Attribute and AssetAttribute (needed for ProtocolConfiguration comparison in AgentService comparing only objectvalue field misses name and asset ID)
Rich Turner2da024169c5a
diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.javaindex 40d7b9a40..644746ef3 100644--- a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java@@ -204,7 +204,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons// Check protocol configuration has changed@SuppressWarnings("ConstantConditions")AssetAttribute oldProtocolConfiguration = agent.getAttribute(protocolRef.getAttributeName()).get();- if (oldProtocolConfiguration.getObjectValue().equals(protocolConfiguration.getObjectValue())) {+ if (oldProtocolConfiguration.equals(protocolConfiguration)) {// Protocol configuration hasn't changed so nothing to do herereturn;}@@ -317,8 +317,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons.stream().filter(oldProtocolAttribute -> newProtocolConfigurations.stream()- .noneMatch(newProtocolAttribute ->- oldProtocolAttribute.getObjectValue().equals(newProtocolAttribute.getObjectValue())+ .noneMatch(oldProtocolAttribute::equals)).forEach(this::unlinkProtocolConfiguration);@@ -328,8 +327,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons.stream().filter(newProtocolAttribute -> oldProtocolConfigurations.stream()- .noneMatch(oldProtocolAttribute ->- oldProtocolAttribute.getObjectValue().equals(newProtocolAttribute.getObjectValue())+ .noneMatch(newProtocolAttribute::equals)).forEach(this::linkProtocolConfiguration);diff --git a/model/src/main/java/org/openremote/model/asset/AssetAttribute.java b/model/src/main/java/org/openremote/model/asset/AssetAttribute.javaindex fd3c04672..7f030d74e 100644--- a/model/src/main/java/org/openremote/model/asset/AssetAttribute.java+++ b/model/src/main/java/org/openremote/model/asset/AssetAttribute.java@@ -28,10 +28,7 @@ import org.openremote.model.value.ObjectValue;import org.openremote.model.value.Value;import org.openremote.model.value.Values;-import java.util.Arrays;-import java.util.Collection;-import java.util.List;-import java.util.Optional;+import java.util.*;import java.util.function.Predicate;import java.util.stream.Stream;@@ -393,6 +390,24 @@ public class AssetAttribute extends Attribute {"} " + objectValue.toJson();}+ @Override+ public int hashCode() {+ return Objects.hash(objectValue, name, assetId);+ }++ @Override+ public boolean equals(Object obj) {+ if (obj == null)+ return false;+ if (!(obj instanceof AssetAttribute))+ return false;+ AssetAttribute that = (AssetAttribute) obj;++ return Objects.equals(assetId, that.assetId)+ && Objects.equals(name, that.name)+ && Objects.equals(objectValue, that.objectValue);+ }+// ---------------------------------------------------// FUNCTIONAL METHODS BELOW// ---------------------------------------------------@@ -449,6 +464,7 @@ public class AssetAttribute extends Attribute {if (objectValue == null || objectValue.keys().length == 0) {return Stream.empty();}+ //noinspection ConstantConditionsreturn Arrays.stream(objectValue.keys()).map(key -> new Pair<>(key, objectValue.getObject(key)))diff --git a/model/src/main/java/org/openremote/model/attribute/Attribute.java b/model/src/main/java/org/openremote/model/attribute/Attribute.javaindex 89693abf2..66506aa95 100644--- a/model/src/main/java/org/openremote/model/attribute/Attribute.java+++ b/model/src/main/java/org/openremote/model/attribute/Attribute.java@@ -249,6 +249,21 @@ public abstract class Attribute extends AbstractValueTimestampHolder {return item.getValidationFailures(metaItemDescriptor);}+ @Override+ public int hashCode() {+ return Objects.hash(objectValue, name);+ }++ @Override+ public boolean equals(Object obj) {+ if (obj == null)+ return false;+ if (!(obj instanceof Attribute))+ return false;+ Attribute that = (Attribute) obj;+ return Objects.equals(name, that.name) && Objects.equals(objectValue, that.objectValue);+ }+// ---------------------------------------------------// FUNCTIONAL METHODS BELOW// ---------------------------------------------------