aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolay Vlahovski <nvlahovski@gmail.com>2023-06-11 18:02:33 +0300
committerNikolay Vlahovski <nvlahovski@gmail.com>2023-06-11 18:02:33 +0300
commitc98f4706e648e835ef7ac460e4a12381562515cd (patch)
treedc93a52b303eebcbaa3538e902a21563a7dab4c2
parent873f08a8fd6e5e521e8c81421ebc2c3ea642ee52 (diff)
downloadtrackermap-server-c98f4706e648e835ef7ac460e4a12381562515cd.tar.gz
trackermap-server-c98f4706e648e835ef7ac460e4a12381562515cd.tar.bz2
trackermap-server-c98f4706e648e835ef7ac460e4a12381562515cd.zip
Refactor getUniqueSheetName in RouteReportProvider
Rename uniqueSheetsTitle to namesCount Increase default namesCount counter to 1 Move namesCount to top
-rw-r--r--src/main/java/org/traccar/reports/RouteReportProvider.java9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/main/java/org/traccar/reports/RouteReportProvider.java b/src/main/java/org/traccar/reports/RouteReportProvider.java
index bec1470bd..a1d004dd1 100644
--- a/src/main/java/org/traccar/reports/RouteReportProvider.java
+++ b/src/main/java/org/traccar/reports/RouteReportProvider.java
@@ -44,13 +44,13 @@ import java.util.Collection;
import java.util.Date;
import java.util.Map;
import java.util.HashMap;
-import java.util.concurrent.atomic.AtomicInteger;
public class RouteReportProvider {
private final Config config;
private final ReportUtils reportUtils;
private final Storage storage;
+ private final Map<String, Integer> namesCount = new HashMap<>();
@Inject
public RouteReportProvider(Config config, ReportUtils reportUtils, Storage storage) {
@@ -69,12 +69,11 @@ public class RouteReportProvider {
}
return result;
}
- private final Map<String, Integer> uniqueSheetsTitle = new HashMap<>();
+
private String getUniqueSheetName(String key) {
- AtomicInteger atomic = new AtomicInteger(uniqueSheetsTitle.getOrDefault(key, -1));
- uniqueSheetsTitle.put(key, atomic.incrementAndGet());
- return (uniqueSheetsTitle.get(key) > 0 ? key + "-" + uniqueSheetsTitle.get(key) : key);
+ namesCount.compute(key, (k, value) -> (value == null) ? 1 : (value + 1));
+ return (namesCount.get(key) > 1 ? key + "-" + namesCount.get(key) : key);
}
public void getExcel(OutputStream outputStream,
long userId, Collection<Long> deviceIds, Collection<Long> groupIds,