Fix duplicate devices during scanning

parent 8e92a3fd
......@@ -65,6 +65,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
......@@ -203,7 +204,10 @@ public class IotivityRepository {
deviceDao.insert(new DeviceEntity(deviceId, device.getName(), endpoints, DeviceType.UNOWNED, Device.NOTHING_PERMITS));
}
unownedDevices.add(new Device(DeviceType.UNOWNED, deviceId, new OcDeviceInfo(), endpoints, Device.NOTHING_PERMITS));
Device device1 = new Device(DeviceType.UNOWNED, deviceId, new OcDeviceInfo(), endpoints, Device.NOTHING_PERMITS);
if (!unownedDevices.contains(device1)) {
unownedDevices.add(device1);
}
};
int ret;
......@@ -241,7 +245,10 @@ public class IotivityRepository {
deviceDao.insert(new DeviceEntity(deviceId, device.getName(), endpoints, DeviceType.OWNED_BY_SELF, Device.FULL_PERMITS));
}
ownedDevices.add(new Device(DeviceType.OWNED_BY_SELF, deviceId, new OcDeviceInfo(), endpoints, Device.FULL_PERMITS));
Device device1 = new Device(DeviceType.OWNED_BY_SELF, deviceId, new OcDeviceInfo(), endpoints, Device.FULL_PERMITS);
if (!ownedDevices.contains(device1)) {
ownedDevices.add(device1);
}
};
int ret;
......
......@@ -239,4 +239,14 @@ public class Device implements Comparable<Device>, Serializable {
return res;
}
@Override
public boolean equals(Object device) {
boolean same = false;
if (device != null && device instanceof Device) {
same = this.deviceId.equals(((Device)device).getDeviceId());
}
return same;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment