From 696ac56a6174a5ebfec939871a579ba54ee96963 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 20 Mar 2017 15:54:13 +0500 Subject: Use Iterator for maps cleanup --- src/org/traccar/database/DeviceManager.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java index f70b9b1a2..ae5784b01 100644 --- a/src/org/traccar/database/DeviceManager.java +++ b/src/org/traccar/database/DeviceManager.java @@ -19,6 +19,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -133,19 +134,19 @@ public class DeviceManager implements IdentityManager { device.setStatus(Device.STATUS_OFFLINE); } } - for (Long cachedDeviceId : devicesById.keySet()) { - if (!databaseDevicesIds.contains(cachedDeviceId)) { - devicesById.remove(cachedDeviceId); + for (Iterator iterator = devicesById.keySet().iterator(); iterator.hasNext();) { + if (!databaseDevicesIds.contains(iterator.next())) { + iterator.remove(); } } - for (String cachedDeviceUniqueId : devicesByUniqueId.keySet()) { - if (!databaseDevicesUniqueIds.contains(cachedDeviceUniqueId)) { - devicesByUniqueId.remove(cachedDeviceUniqueId); + for (Iterator iterator = devicesByUniqueId.keySet().iterator(); iterator.hasNext();) { + if (!databaseDevicesUniqueIds.contains(iterator.next())) { + iterator.remove(); } } - for (String cachedDevicePhone : devicesByPhone.keySet()) { - if (!databaseDevicesPhones.contains(cachedDevicePhone)) { - devicesByPhone.remove(cachedDevicePhone); + for (Iterator iterator = devicesByPhone.keySet().iterator(); iterator.hasNext();) { + if (!databaseDevicesPhones.contains(iterator.next())) { + iterator.remove(); } } } -- cgit v1.2.3