diff options
Diffstat (limited to 'src/org/traccar')
-rw-r--r-- | src/org/traccar/database/DriversManager.java | 13 | ||||
-rw-r--r-- | src/org/traccar/database/SimpleObjectManager.java | 2 |
2 files changed, 11 insertions, 4 deletions
diff --git a/src/org/traccar/database/DriversManager.java b/src/org/traccar/database/DriversManager.java index 349e5dccf..14b74bab1 100644 --- a/src/org/traccar/database/DriversManager.java +++ b/src/org/traccar/database/DriversManager.java @@ -24,16 +24,23 @@ import org.traccar.model.BaseModel; public class DriversManager extends ExtendedObjectManager { - private final Map<String, Driver> driversByUniqueId = new ConcurrentHashMap<>(); + private Map<String, Driver> driversByUniqueId; public DriversManager(DataManager dataManager) { super(dataManager, Driver.class); } + private void putUniqueDriverId(Driver driver) { + if (driversByUniqueId == null) { + driversByUniqueId = new ConcurrentHashMap<>(); + } + driversByUniqueId.put(driver.getUniqueId(), driver); + } + @Override protected void addNewItem(BaseModel item) { super.addNewItem(item); - driversByUniqueId.put(((Driver) item).getUniqueId(), (Driver) item); + putUniqueDriverId((Driver) item); } @Override @@ -44,7 +51,7 @@ public class DriversManager extends ExtendedObjectManager { if (!driver.getUniqueId().equals(cachedDriver.getUniqueId())) { driversByUniqueId.remove(cachedDriver.getUniqueId()); cachedDriver.setUniqueId(driver.getUniqueId()); - driversByUniqueId.put(cachedDriver.getUniqueId(), cachedDriver); + putUniqueDriverId(cachedDriver); } cachedDriver.setAttributes(driver.getAttributes()); } diff --git a/src/org/traccar/database/SimpleObjectManager.java b/src/org/traccar/database/SimpleObjectManager.java index 0f6a9e6a4..6cb7ff260 100644 --- a/src/org/traccar/database/SimpleObjectManager.java +++ b/src/org/traccar/database/SimpleObjectManager.java @@ -162,7 +162,7 @@ public abstract class SimpleObjectManager { return result; } - public Set<Long> getAllItems() { + public final Set<Long> getAllItems() { return items.keySet(); } |