aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-07-24 18:13:53 +0500
committerAbyss777 <abyss@fox5.ru>2017-07-24 18:20:03 +0500
commit870a919f53986724c023bcde9d0eddf8888e9007 (patch)
tree9e3e191f3ff7cd05bbec00730519439b789595e5
parent4e2fe7bc908e0288345a4aef2f31c357215a7586 (diff)
downloadtraccar-server-870a919f53986724c023bcde9d0eddf8888e9007.tar.gz
traccar-server-870a919f53986724c023bcde9d0eddf8888e9007.tar.bz2
traccar-server-870a919f53986724c023bcde9d0eddf8888e9007.zip
Fix order of objects constructions
-rw-r--r--src/org/traccar/database/DriversManager.java13
-rw-r--r--src/org/traccar/database/SimpleObjectManager.java2
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();
}