Skip to content

Commit 016326c

Browse files
committed
Remove change to consistently use LinkedHashMap
The change to `LinkedHashMap<>` should not cause any issues, even with serialization, since we copy the map contents into our chosen implementation anyways. However, it does mean that new campaigns files with have `<linked-hash-map>` as the values under `<lightSourcesMap>`, where they used to have `<map>`. So to avoid any possible issues, and to meet the goal of zero campaign file changes in 1.18, we're going back to consistent `HashMap<>` for light source maps. The ubiquitous copying of light source maps remains.
1 parent d578f3d commit 016326c

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

src/main/java/net/rptools/maptool/client/ui/campaignproperties/CampaignPropertiesDialog.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.util.Arrays;
3030
import java.util.Collections;
3131
import java.util.HashMap;
32-
import java.util.LinkedHashMap;
3332
import java.util.List;
3433
import java.util.Map;
3534
import java.util.TreeMap;
@@ -270,7 +269,7 @@ private void copyCampaignToUI(CampaignProperties campaignProperties) {
270269
case NORMAL -> lightSources;
271270
case AURA -> auras;
272271
};
273-
targetMap.computeIfAbsent(category, c -> new LinkedHashMap<>()).put(guid, source);
272+
targetMap.computeIfAbsent(category, c -> new HashMap<>()).put(guid, source);
274273
}
275274
}
276275

@@ -323,7 +322,7 @@ private void copyUIToCampaign() {
323322
var guid = sourceEntry.getKey();
324323
var source = sourceEntry.getValue();
325324

326-
newLights.computeIfAbsent(category, c -> new LinkedHashMap<>()).put(guid, source);
325+
newLights.computeIfAbsent(category, c -> new HashMap<>()).put(guid, source);
327326
}
328327
}
329328

src/main/java/net/rptools/maptool/model/CampaignProperties.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public CampaignProperties(CampaignProperties properties) {
126126

127127
// Play it safe. Don't keep the provided implementations but copy them.
128128
for (var entry : properties.lightSourcesMap.entrySet()) {
129-
lightSourcesMap.put(entry.getKey(), new LinkedHashMap<>(entry.getValue()));
129+
lightSourcesMap.put(entry.getKey(), new HashMap<>(entry.getValue()));
130130
}
131131

132132
for (BooleanTokenOverlay overlay : properties.tokenStates.values()) {
@@ -164,7 +164,7 @@ public void mergeInto(CampaignProperties properties) {
164164

165165
// Play it safe. Don't keep the provided implementations but copy them.
166166
for (var entry : lightSourcesMap.entrySet()) {
167-
properties.lightSourcesMap.put(entry.getKey(), new LinkedHashMap<>(entry.getValue()));
167+
properties.lightSourcesMap.put(entry.getKey(), new HashMap<>(entry.getValue()));
168168
}
169169
properties.lookupTableMap.putAll(lookupTableMap);
170170
properties.sightTypeMap.putAll(sightTypeMap);
@@ -237,7 +237,7 @@ public void setRemoteRepositoryList(List<String> list) {
237237
public Map<String, Map<GUID, LightSource>> getLightSourcesMap() {
238238
var copy = new TreeMap<String, Map<GUID, LightSource>>();
239239
for (var entry : lightSourcesMap.entrySet()) {
240-
copy.put(entry.getKey(), new LinkedHashMap<>(entry.getValue()));
240+
copy.put(entry.getKey(), new HashMap<>(entry.getValue()));
241241
}
242242
return copy;
243243
}
@@ -246,7 +246,7 @@ public void setLightSourcesMap(Map<String, Map<GUID, LightSource>> map) {
246246
lightSourcesMap.clear();
247247
// Play it safe. Don't keep the provided implementations but copy them.
248248
for (var entry : map.entrySet()) {
249-
lightSourcesMap.put(entry.getKey(), new LinkedHashMap<>(entry.getValue()));
249+
lightSourcesMap.put(entry.getKey(), new HashMap<>(entry.getValue()));
250250
}
251251
}
252252

@@ -295,7 +295,7 @@ private void initLightSourcesMap() {
295295
Map<String, List<LightSource>> map = LightSource.getDefaultLightSources();
296296
for (var entry : map.entrySet()) {
297297
String key = entry.getKey();
298-
Map<GUID, LightSource> lightSourceMap = new LinkedHashMap<>();
298+
Map<GUID, LightSource> lightSourceMap = new HashMap<>();
299299
for (LightSource source : entry.getValue()) {
300300
lightSourceMap.put(source.getId(), source);
301301
}
@@ -492,7 +492,7 @@ protected Object readResolve() {
492492
lightSourcesMap = new TreeMap<>();
493493
if (oldLightSourcesMap != null) {
494494
for (var entry : oldLightSourcesMap.entrySet()) {
495-
lightSourcesMap.put(entry.getKey(), new LinkedHashMap<>(entry.getValue()));
495+
lightSourcesMap.put(entry.getKey(), new HashMap<>(entry.getValue()));
496496
}
497497
}
498498

@@ -564,7 +564,7 @@ public static CampaignProperties fromDto(CampaignPropertiesDto dto) {
564564
dto.getLightSourcesMap()
565565
.forEach(
566566
(k, v) -> {
567-
var map = new LinkedHashMap<GUID, LightSource>();
567+
var map = new HashMap<GUID, LightSource>();
568568
v.getLightSourcesList()
569569
.forEach(
570570
l -> {

src/main/java/net/rptools/maptool/util/AuraSyntax.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class AuraSyntax {
4646
private static final Logger log = LogManager.getLogger(AuraSyntax.class);
4747

4848
public Map<GUID, LightSource> parseAuras(String text, Iterable<LightSource> original) {
49-
final var aurasMap = new LinkedHashMap<GUID, LightSource>();
49+
final var aurasMap = new HashMap<GUID, LightSource>();
5050
final var reader = new LineNumberReader(new BufferedReader(new StringReader(text)));
5151
List<String> errlog = new LinkedList<>();
5252

@@ -98,7 +98,7 @@ public Map<String, Map<GUID, LightSource>> parseCategorizedAuras(
9898
final var currentGroupName = line;
9999
currentGroupOriginalAuras =
100100
originalAuraMap.getOrDefault(currentGroupName, Collections.emptyMap()).values();
101-
auraGroupMap = new LinkedHashMap<>();
101+
auraGroupMap = new HashMap<>();
102102
auraMap.put(currentGroupName, auraGroupMap);
103103
continue;
104104
}

src/main/java/net/rptools/maptool/util/LightSyntax.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class LightSyntax {
4646
private static final Logger log = LogManager.getLogger(LightSyntax.class);
4747

4848
public Map<GUID, LightSource> parseLights(String text, Iterable<LightSource> original) {
49-
final var lightSourceMap = new LinkedHashMap<GUID, LightSource>();
49+
final var lightSourceMap = new HashMap<GUID, LightSource>();
5050
final var reader = new LineNumberReader(new BufferedReader(new StringReader(text)));
5151
List<String> errlog = new LinkedList<>();
5252

@@ -100,7 +100,7 @@ public Map<String, Map<GUID, LightSource>> parseCategorizedLights(
100100
originalLightSourcesMap
101101
.getOrDefault(currentGroupName, Collections.emptyMap())
102102
.values();
103-
lightSourceMap = new LinkedHashMap<>();
103+
lightSourceMap = new HashMap<>();
104104
lightMap.put(currentGroupName, lightSourceMap);
105105
continue;
106106
}

0 commit comments

Comments
 (0)