From 7174d000e0351f6dfe5fad09414ee1d3ef838527 Mon Sep 17 00:00:00 2001 From: Lakshman Date: Wed, 6 Apr 2016 19:05:11 +0530 Subject: [PATCH] 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 be6f7bf951e..473ea559b64 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(); + } }