|
25 | 25 | import java.io.StringReader; |
26 | 26 | import java.text.ParseException; |
27 | 27 | import java.util.ArrayList; |
| 28 | +import java.util.HashSet; |
28 | 29 | import java.util.Map.Entry; |
| 30 | +import java.util.Set; |
29 | 31 | import java.util.TreeMap; |
30 | 32 | import javax.json.Json; |
31 | 33 | import javax.json.JsonArray; |
@@ -399,6 +401,8 @@ public StringBuilder toCSV(String csvEntryKey, String[] csvProperties, String se |
399 | 401 |
|
400 | 402 | // Temporary list where we will store the new entries |
401 | 403 | ArrayList<String> newEntries = new ArrayList<String>(); |
| 404 | + // Set of lower-cased paths already added, used for O(1) case-insensitive dedup |
| 405 | + Set<String> seenLowercasePaths = new HashSet<String>(); |
402 | 406 |
|
403 | 407 | for (String existingEntry : entries) { |
404 | 408 | if (isWildcard) { |
@@ -436,18 +440,10 @@ public StringBuilder toCSV(String csvEntryKey, String[] csvProperties, String se |
436 | 440 | childName = remainder.substring(0, Math.min(slashPos, bracketPos)); |
437 | 441 | } |
438 | 442 |
|
439 | | - // Add the child path if it's valid and not already in the list |
| 443 | + // Add the child path if it's valid and not already seen (case-insensitive) |
440 | 444 | if (!childName.isEmpty()) { |
441 | 445 | String childPath = prefix + childName; |
442 | | - // Deduplicate (case-insensitive, consistent with the TreeMap) |
443 | | - boolean alreadyAdded = false; |
444 | | - for (String added : newEntries) { |
445 | | - if (added.equalsIgnoreCase(childPath)) { |
446 | | - alreadyAdded = true; |
447 | | - break; |
448 | | - } |
449 | | - } |
450 | | - if (!alreadyAdded) { |
| 446 | + if (seenLowercasePaths.add(childPath.toLowerCase())) { |
451 | 447 | newEntries.add(childPath); |
452 | 448 | } |
453 | 449 | } |
|
0 commit comments