diff options
Diffstat (limited to 'poi/src/main')
8 files changed, 61 insertions, 45 deletions
diff --git a/poi/src/main/java/org/apache/poi/ddf/EscherPropertyTypes.java b/poi/src/main/java/org/apache/poi/ddf/EscherPropertyTypes.java index a48972faf3..7502dbc974 100644 --- a/poi/src/main/java/org/apache/poi/ddf/EscherPropertyTypes.java +++ b/poi/src/main/java/org/apache/poi/ddf/EscherPropertyTypes.java @@ -17,6 +17,7 @@ package org.apache.poi.ddf; +import java.util.Collections; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; @@ -365,8 +366,8 @@ public enum EscherPropertyTypes { return propNumber; } - private static final Map<Short, EscherPropertyTypes> LOOKUP = - Stream.of(values()).collect(Collectors.toMap(EscherPropertyTypes::getPropertyId, Function.identity())); + private static final Map<Short, EscherPropertyTypes> LOOKUP = Collections.unmodifiableMap( + Stream.of(values()).collect(Collectors.toMap(EscherPropertyTypes::getPropertyId, Function.identity()))); public static EscherPropertyTypes forPropertyID(int propertyId) { EscherPropertyTypes rt = LOOKUP.get((short)(propertyId & 0x3FFF)); diff --git a/poi/src/main/java/org/apache/poi/ddf/EscherRecordTypes.java b/poi/src/main/java/org/apache/poi/ddf/EscherRecordTypes.java index 4f11dab6c0..a8b589d7cb 100644 --- a/poi/src/main/java/org/apache/poi/ddf/EscherRecordTypes.java +++ b/poi/src/main/java/org/apache/poi/ddf/EscherRecordTypes.java @@ -17,6 +17,7 @@ package org.apache.poi.ddf; +import java.util.Collections; import java.util.Map; import java.util.function.Function; import java.util.function.Supplier; @@ -108,8 +109,8 @@ public enum EscherRecordTypes { return typeID; } - private static final Map<Short, EscherRecordTypes> LOOKUP = - Stream.of(values()).collect(Collectors.toMap(EscherRecordTypes::getTypeId, Function.identity())); + private static final Map<Short, EscherRecordTypes> LOOKUP = Collections.unmodifiableMap( + Stream.of(values()).collect(Collectors.toMap(EscherRecordTypes::getTypeId, Function.identity()))); public static EscherRecordTypes forTypeID(int typeID) { // Section 2.2.23: 0xF02A is treated as 0xF01D diff --git a/poi/src/main/java/org/apache/poi/hssf/record/HSSFRecordTypes.java b/poi/src/main/java/org/apache/poi/hssf/record/HSSFRecordTypes.java index e8edcd9beb..cf96237be4 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/HSSFRecordTypes.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/HSSFRecordTypes.java @@ -20,6 +20,7 @@ package org.apache.poi.hssf.record; import java.util.Arrays; +import java.util.Collections; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; @@ -211,8 +212,8 @@ public enum HSSFRecordTypes { T apply(RecordInputStream in); } - private static final Map<Short,HSSFRecordTypes> LOOKUP = - Arrays.stream(values()).collect(Collectors.toMap(HSSFRecordTypes::getSid, Function.identity())); + private static final Map<Short,HSSFRecordTypes> LOOKUP = Collections.unmodifiableMap( + Arrays.stream(values()).collect(Collectors.toMap(HSSFRecordTypes::getSid, Function.identity()))); public final short sid; public final Class<? extends org.apache.poi.hssf.record.Record> clazz; diff --git a/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java index 230e47b16c..ca16540ec8 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java @@ -18,6 +18,7 @@ package org.apache.poi.hssf.record; import java.util.Arrays; +import java.util.Collections; import java.util.Map; import java.util.function.Function; import java.util.function.Supplier; @@ -64,8 +65,8 @@ public abstract class SubRecord implements Duplicatable, GenericRecord { T apply(LittleEndianInput in, int size, int cmoOt); } - private static final Map<Short,SubRecordTypes> LOOKUP = - Arrays.stream(values()).collect(Collectors.toMap(SubRecordTypes::getSid, Function.identity())); + private static final Map<Short,SubRecordTypes> LOOKUP = Collections.unmodifiableMap( + Arrays.stream(values()).collect(Collectors.toMap(SubRecordTypes::getSid, Function.identity()))); public final short sid; public final RecordConstructor<?> recordConstructor; diff --git a/poi/src/main/java/org/apache/poi/ss/usermodel/FormulaError.java b/poi/src/main/java/org/apache/poi/ss/usermodel/FormulaError.java index 5ffdd6e47e..785bfa6905 100644 --- a/poi/src/main/java/org/apache/poi/ss/usermodel/FormulaError.java +++ b/poi/src/main/java/org/apache/poi/ss/usermodel/FormulaError.java @@ -16,6 +16,7 @@ ==================================================================== */ package org.apache.poi.ss.usermodel; +import java.util.Collections; import java.util.Map; import org.apache.poi.util.Internal; @@ -149,15 +150,21 @@ public enum FormulaError { return repr; } - private static final Map<String, FormulaError> smap = new HashMap<>(); - private static final Map<Byte, FormulaError> bmap = new HashMap<>(); - private static final Map<Integer, FormulaError> imap = new HashMap<>(); - static{ + private static final Map<String, FormulaError> smap; + private static final Map<Byte, FormulaError> bmap; + private static final Map<Integer, FormulaError> imap; + static { + final Map<String, FormulaError> mapS = new HashMap<>(); + final Map<Byte, FormulaError> mapB = new HashMap<>(); + final Map<Integer, FormulaError> mapI = new HashMap<>(); for (FormulaError error : values()) { - bmap.put(error.getCode(), error); - imap.put(error.getLongCode(), error); - smap.put(error.getString(), error); + mapB.put(error.getCode(), error); + mapI.put(error.getLongCode(), error); + mapS.put(error.getString(), error); } + smap = Collections.unmodifiableMap(mapS); + bmap = Collections.unmodifiableMap(mapB); + imap = Collections.unmodifiableMap(mapI); } public static boolean isValidCode(int errorCode) { diff --git a/poi/src/main/java/org/apache/poi/ss/usermodel/PageMargin.java b/poi/src/main/java/org/apache/poi/ss/usermodel/PageMargin.java index 34c732c32f..907886a97d 100644 --- a/poi/src/main/java/org/apache/poi/ss/usermodel/PageMargin.java +++ b/poi/src/main/java/org/apache/poi/ss/usermodel/PageMargin.java @@ -16,6 +16,7 @@ ==================================================================== */ package org.apache.poi.ss.usermodel; +import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -75,11 +76,11 @@ public enum PageMargin { private static final Map<Short, PageMargin> PAGE_MARGIN_BY_LEGACY_API_VALUE; static { - PAGE_MARGIN_BY_LEGACY_API_VALUE = new HashMap<>(); - + final Map<Short, PageMargin> map = new HashMap<>(); for (PageMargin margin : values()) { - PAGE_MARGIN_BY_LEGACY_API_VALUE.put(margin.legacyApiValue, margin); + map.put(margin.legacyApiValue, margin); } + PAGE_MARGIN_BY_LEGACY_API_VALUE = Collections.unmodifiableMap(map); } /** diff --git a/poi/src/main/java/org/apache/poi/ss/util/CellUtil.java b/poi/src/main/java/org/apache/poi/ss/util/CellUtil.java index 593dd6eef9..6d3ebb3678 100644 --- a/poi/src/main/java/org/apache/poi/ss/util/CellUtil.java +++ b/poi/src/main/java/org/apache/poi/ss/util/CellUtil.java @@ -265,31 +265,33 @@ public final class CellUtil { public static final String QUOTE_PREFIXED = "quotePrefixed"; // FIXME Must be deleted along with string constants - static final Map<String, CellPropertyType> namePropertyMap = new HashMap<>(); + static final Map<String, CellPropertyType> namePropertyMap; static { - namePropertyMap.put(ALIGNMENT, CellPropertyType.ALIGNMENT); - namePropertyMap.put(BORDER_BOTTOM, CellPropertyType.BORDER_BOTTOM); - namePropertyMap.put(BORDER_LEFT, CellPropertyType.BORDER_LEFT); - namePropertyMap.put(BORDER_RIGHT, CellPropertyType.BORDER_RIGHT); - namePropertyMap.put(BORDER_TOP, CellPropertyType.BORDER_TOP); - namePropertyMap.put(BOTTOM_BORDER_COLOR, CellPropertyType.BOTTOM_BORDER_COLOR); - namePropertyMap.put(LEFT_BORDER_COLOR, CellPropertyType.LEFT_BORDER_COLOR); - namePropertyMap.put(RIGHT_BORDER_COLOR, CellPropertyType.RIGHT_BORDER_COLOR); - namePropertyMap.put(TOP_BORDER_COLOR, CellPropertyType.TOP_BORDER_COLOR); - namePropertyMap.put(FILL_BACKGROUND_COLOR, CellPropertyType.FILL_BACKGROUND_COLOR); - namePropertyMap.put(FILL_FOREGROUND_COLOR, CellPropertyType.FILL_FOREGROUND_COLOR); - namePropertyMap.put(FILL_BACKGROUND_COLOR_COLOR, CellPropertyType.FILL_BACKGROUND_COLOR_COLOR); - namePropertyMap.put(FILL_FOREGROUND_COLOR_COLOR, CellPropertyType.FILL_FOREGROUND_COLOR_COLOR); - namePropertyMap.put(FILL_PATTERN, CellPropertyType.FILL_PATTERN); - namePropertyMap.put(FONT, CellPropertyType.FONT); - namePropertyMap.put(HIDDEN, CellPropertyType.HIDDEN); - namePropertyMap.put(INDENTION, CellPropertyType.INDENTION); - namePropertyMap.put(LOCKED, CellPropertyType.LOCKED); - namePropertyMap.put(ROTATION, CellPropertyType.ROTATION); - namePropertyMap.put(VERTICAL_ALIGNMENT, CellPropertyType.VERTICAL_ALIGNMENT); - namePropertyMap.put(SHRINK_TO_FIT, CellPropertyType.SHRINK_TO_FIT); - namePropertyMap.put(QUOTE_PREFIXED, CellPropertyType.QUOTE_PREFIXED); + final Map<String, CellPropertyType> map = new HashMap<>(); + map.put(ALIGNMENT, CellPropertyType.ALIGNMENT); + map.put(BORDER_BOTTOM, CellPropertyType.BORDER_BOTTOM); + map.put(BORDER_LEFT, CellPropertyType.BORDER_LEFT); + map.put(BORDER_RIGHT, CellPropertyType.BORDER_RIGHT); + map.put(BORDER_TOP, CellPropertyType.BORDER_TOP); + map.put(BOTTOM_BORDER_COLOR, CellPropertyType.BOTTOM_BORDER_COLOR); + map.put(LEFT_BORDER_COLOR, CellPropertyType.LEFT_BORDER_COLOR); + map.put(RIGHT_BORDER_COLOR, CellPropertyType.RIGHT_BORDER_COLOR); + map.put(TOP_BORDER_COLOR, CellPropertyType.TOP_BORDER_COLOR); + map.put(FILL_BACKGROUND_COLOR, CellPropertyType.FILL_BACKGROUND_COLOR); + map.put(FILL_FOREGROUND_COLOR, CellPropertyType.FILL_FOREGROUND_COLOR); + map.put(FILL_BACKGROUND_COLOR_COLOR, CellPropertyType.FILL_BACKGROUND_COLOR_COLOR); + map.put(FILL_FOREGROUND_COLOR_COLOR, CellPropertyType.FILL_FOREGROUND_COLOR_COLOR); + map.put(FILL_PATTERN, CellPropertyType.FILL_PATTERN); + map.put(FONT, CellPropertyType.FONT); + map.put(HIDDEN, CellPropertyType.HIDDEN); + map.put(INDENTION, CellPropertyType.INDENTION); + map.put(LOCKED, CellPropertyType.LOCKED); + map.put(ROTATION, CellPropertyType.ROTATION); + map.put(VERTICAL_ALIGNMENT, CellPropertyType.VERTICAL_ALIGNMENT); + map.put(SHRINK_TO_FIT, CellPropertyType.SHRINK_TO_FIT); + map.put(QUOTE_PREFIXED, CellPropertyType.QUOTE_PREFIXED); + namePropertyMap = Collections.unmodifiableMap(map); } private static final UnicodeMapping[] unicodeMappings; diff --git a/poi/src/main/java/org/apache/poi/util/LocaleID.java b/poi/src/main/java/org/apache/poi/util/LocaleID.java index 6438adf535..9b843e05ed 100644 --- a/poi/src/main/java/org/apache/poi/util/LocaleID.java +++ b/poi/src/main/java/org/apache/poi/util/LocaleID.java @@ -21,6 +21,7 @@ import static java.util.Calendar.SATURDAY; import static java.util.Calendar.SUNDAY; import java.util.Calendar; +import java.util.Collections; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; @@ -508,11 +509,12 @@ public enum LocaleID { private final int defaultCodepage; private final int firstWeekday; - private static final Map<String, LocaleID> languageTagLookup = - Stream.of(values()).filter(LocaleID::isValid).collect(Collectors.toMap(LocaleID::getLanguageTag, Function.identity())); + private static final Map<String, LocaleID> languageTagLookup = Collections.unmodifiableMap( + Stream.of(values()).filter(LocaleID::isValid) + .collect(Collectors.toMap(LocaleID::getLanguageTag, Function.identity()))); - private static final Map<Integer, LocaleID> lcidLookup = - Stream.of(values()).collect(Collectors.toMap(LocaleID::getLcid, Function.identity())); + private static final Map<Integer, LocaleID> lcidLookup = Collections.unmodifiableMap( + Stream.of(values()).collect(Collectors.toMap(LocaleID::getLcid, Function.identity()))); LocaleID(int lcid, String windowsId, String languageTag, String description, int defaultCodepage, int firstWeekday) { this.lcid = lcid; |