diff options
author | PJ Fanning <fanningpj@apache.org> | 2024-10-26 16:34:40 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2024-10-26 16:34:40 +0000 |
commit | 9185ec02c5d814ae22bed7d2348650fb1bbf7ec8 (patch) | |
tree | f4907b7064c40cd84afc5eb9748fc83bbd6dac0c /poi-scratchpad | |
parent | 69d935d4dbe348d3b87502479643c4e756e76a70 (diff) | |
download | poi-9185ec02c5d814ae22bed7d2348650fb1bbf7ec8.tar.gz poi-9185ec02c5d814ae22bed7d2348650fb1bbf7ec8.zip |
immutable maps
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1921575 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-scratchpad')
-rw-r--r-- | poi-scratchpad/src/main/java/org/apache/poi/hslf/record/RecordTypes.java | 6 | ||||
-rw-r--r-- | poi-scratchpad/src/main/java/org/apache/poi/hslf/util/LocaleDateFormat.java | 9 |
2 files changed, 9 insertions, 6 deletions
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<Short,RecordTypes> LOOKUP; static { - LOOKUP = new HashMap<>(); + final Map<Short,RecordTypes> 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<LocaleID,MapFormatPPT> LCID_LOOKUP = - Stream.of(values()).collect(Collectors.toMap(MapFormatPPT::getLocaleID, Function.identity())); + private static final Map<LocaleID,MapFormatPPT> 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<LocaleID, MapFormatException> LCID_LOOKUP = + private static final Map<LocaleID, MapFormatException> 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; |