From c98f4706e648e835ef7ac460e4a12381562515cd Mon Sep 17 00:00:00 2001 From: Nikolay Vlahovski Date: Sun, 11 Jun 2023 18:02:33 +0300 Subject: Refactor getUniqueSheetName in RouteReportProvider Rename uniqueSheetsTitle to namesCount Increase default namesCount counter to 1 Move namesCount to top --- src/main/java/org/traccar/reports/RouteReportProvider.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/main/java') 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 namesCount = new HashMap<>(); @Inject public RouteReportProvider(Config config, ReportUtils reportUtils, Storage storage) { @@ -69,12 +69,11 @@ public class RouteReportProvider { } return result; } - private final Map 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 deviceIds, Collection groupIds, -- cgit v1.2.3