diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-07-27 17:00:45 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-27 17:00:45 +1200 |
commit | 495b2aa2d2b17bd1a5803ea0bd7dcc64bc81c598 (patch) | |
tree | 4b65fbe2d6081f31762a0d8aa790b9fcf81e81f7 /src/org/traccar/database/DriversManager.java | |
parent | 194263a9dc8040ebcbf62c80733aca5097eb3e36 (diff) | |
parent | 49fa4893269b1732806f7176c279742291e02edf (diff) | |
download | trackermap-server-495b2aa2d2b17bd1a5803ea0bd7dcc64bc81c598.tar.gz trackermap-server-495b2aa2d2b17bd1a5803ea0bd7dcc64bc81c598.tar.bz2 trackermap-server-495b2aa2d2b17bd1a5803ea0bd7dcc64bc81c598.zip |
Merge pull request #3391 from Abyss777/refactor_drivers_groups
Split Drivers and Groups management
Diffstat (limited to 'src/org/traccar/database/DriversManager.java')
-rw-r--r-- | src/org/traccar/database/DriversManager.java | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/org/traccar/database/DriversManager.java b/src/org/traccar/database/DriversManager.java index 14b74bab1..d3866a5f0 100644 --- a/src/org/traccar/database/DriversManager.java +++ b/src/org/traccar/database/DriversManager.java @@ -20,11 +20,10 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.traccar.model.Driver; -import org.traccar.model.BaseModel; -public class DriversManager extends ExtendedObjectManager { +public class DriversManager extends ExtendedObjectManager<Driver> { - private Map<String, Driver> driversByUniqueId; + private Map<String, Long> driversByUniqueId; public DriversManager(DataManager dataManager) { super(dataManager, Driver.class); @@ -32,21 +31,20 @@ public class DriversManager extends ExtendedObjectManager { private void putUniqueDriverId(Driver driver) { if (driversByUniqueId == null) { - driversByUniqueId = new ConcurrentHashMap<>(); + driversByUniqueId = new ConcurrentHashMap<>(getAllItems().size()); } - driversByUniqueId.put(driver.getUniqueId(), driver); + driversByUniqueId.put(driver.getUniqueId(), driver.getId()); } @Override - protected void addNewItem(BaseModel item) { - super.addNewItem(item); - putUniqueDriverId((Driver) item); + protected void addNewItem(Driver driver) { + super.addNewItem(driver); + putUniqueDriverId(driver); } @Override - protected void updateCachedItem(BaseModel item) { - Driver driver = (Driver) item; - Driver cachedDriver = (Driver) getById(driver.getId()); + protected void updateCachedItem(Driver driver) { + Driver cachedDriver = getById(driver.getId()); cachedDriver.setName(driver.getName()); if (!driver.getUniqueId().equals(cachedDriver.getUniqueId())) { driversByUniqueId.remove(cachedDriver.getUniqueId()); @@ -58,7 +56,7 @@ public class DriversManager extends ExtendedObjectManager { @Override protected void removeCachedItem(long driverId) { - Driver cachedDriver = (Driver) getById(driverId); + Driver cachedDriver = getById(driverId); if (cachedDriver != null) { String driverUniqueId = cachedDriver.getUniqueId(); super.removeCachedItem(driverId); @@ -67,6 +65,6 @@ public class DriversManager extends ExtendedObjectManager { } public Driver getDriverByUniqueId(String uniqueId) { - return driversByUniqueId.get(uniqueId); + return getById(driversByUniqueId.get(uniqueId)); } } |