From 7174d000e0351f6dfe5fad09414ee1d3ef838527 Mon Sep 17 00:00:00 2001 From: Lakshman Date: Wed, 6 Apr 2016 19:05:11 +0530 Subject: [PATCH 1/2] override hash and equals function in Device to avoid duplicates in collections --- .../wso2/carbon/device/mgt/common/Device.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java index be6f7bf951..473ea559b6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java @@ -147,4 +147,21 @@ public class Device implements Serializable{ "]"; } + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (!(o instanceof Device)) + return false; + + Device device = (Device) o; + + return getDeviceIdentifier().equals(device.getDeviceIdentifier()); + + } + + @Override + public int hashCode() { + return getDeviceIdentifier().hashCode(); + } } From 551aaf172b8c680bc75eadd7a216cb6825b6ad37 Mon Sep 17 00:00:00 2001 From: Lakshman Date: Wed, 6 Apr 2016 19:32:41 +0530 Subject: [PATCH 2/2] formatting change --- .../src/main/java/org/wso2/carbon/device/mgt/common/Device.java | 1 + 1 file changed, 1 insertion(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java index 473ea559b6..feb5f987a2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java @@ -164,4 +164,5 @@ public class Device implements Serializable{ public int hashCode() { return getDeviceIdentifier().hashCode(); } + }