From 9185ec02c5d814ae22bed7d2348650fb1bbf7ec8 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sat, 26 Oct 2024 16:34:40 +0000 Subject: immutable maps git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1921575 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/java/org/apache/poi/hslf/record/RecordTypes.java | 6 ++++-- .../src/main/java/org/apache/poi/hslf/util/LocaleDateFormat.java | 9 +++++---- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'poi-scratchpad') diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/RecordTypes.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/RecordTypes.java index f3cbf0b106..74e7ccf846 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/RecordTypes.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/RecordTypes.java @@ -17,6 +17,7 @@ package org.apache.poi.hslf.record; +import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -181,10 +182,11 @@ public enum RecordTypes { private static final Map LOOKUP; static { - LOOKUP = new HashMap<>(); + final Map map = new HashMap<>(); for(RecordTypes s : values()) { - LOOKUP.put(s.typeID, s); + map.put(s.typeID, s); } + LOOKUP = Collections.unmodifiableMap(map); } public final short typeID; diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/util/LocaleDateFormat.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/util/LocaleDateFormat.java index eb156e0177..3542fbf264 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/util/LocaleDateFormat.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/util/LocaleDateFormat.java @@ -21,6 +21,7 @@ import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; import java.time.format.FormatStyle; import java.util.AbstractMap; +import java.util.Collections; import java.util.Locale; import java.util.Map; import java.util.function.Function; @@ -64,8 +65,8 @@ public final class LocaleDateFormat { private final LocaleID lcid; private final Object[] mapping; - private static final Map LCID_LOOKUP = - Stream.of(values()).collect(Collectors.toMap(MapFormatPPT::getLocaleID, Function.identity())); + private static final Map LCID_LOOKUP = Collections.unmodifiableMap( + Stream.of(values()).collect(Collectors.toMap(MapFormatPPT::getLocaleID, Function.identity()))); MapFormatPPT(LocaleID lcid, Object... mapping) { this.lcid = lcid; @@ -195,9 +196,9 @@ public final class LocaleDateFormat { private final LocaleID[] lcid; private final Object[] mapping; - private static final Map LCID_LOOKUP = + private static final Map LCID_LOOKUP = Collections.unmodifiableMap( Stream.of(values()).flatMap(m -> Stream.of(m.lcid).map(l -> new AbstractMap.SimpleEntry<>(l, m))) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); MapFormatException(LocaleID[] lcid, Object... mapping) { this.lcid = lcid; -- cgit v1.2.3