]> source.dussan.org Git - poi.git/commitdiff
make it harder to modify metadata in maps
authorPJ Fanning <fanningpj@apache.org>
Tue, 15 Oct 2024 16:08:07 +0000 (16:08 +0000)
committerPJ Fanning <fanningpj@apache.org>
Tue, 15 Oct 2024 16:08:07 +0000 (16:08 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1921337 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDataValidation.java
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/VerticalAlign.java

index 4cc723ee2ca1b8709beb1c75875f83cefa0ed71d..a284c96bde84a79a5fe80da926175fa5b71d2586 100644 (file)
@@ -16,6 +16,7 @@
 ==================================================================== */
 package org.apache.poi.xssf.usermodel;
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -34,49 +35,53 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.STDataValidationOpera
 public class XSSFDataValidation implements DataValidation {
     private static final int MAX_TEXT_LENGTH = 255;
 
-    private CTDataValidation ctDataValidation;
-    private XSSFDataValidationConstraint validationConstraint;
-    private CellRangeAddressList regions;
+    private final CTDataValidation ctDataValidation;
+    private final XSSFDataValidationConstraint validationConstraint;
+    private final CellRangeAddressList regions;
 
-    static Map<Integer, STDataValidationOperator.Enum> operatorTypeMappings = new HashMap<>();
-    static Map<STDataValidationOperator.Enum, Integer> operatorTypeReverseMappings = new HashMap<>();
-    static Map<Integer, STDataValidationType.Enum> validationTypeMappings = new HashMap<>();
-    static Map<STDataValidationType.Enum, Integer> validationTypeReverseMappings = new HashMap<>();
-    static Map<Integer, STDataValidationErrorStyle.Enum> errorStyleMappings = new HashMap<>();
-    static Map<STDataValidationErrorStyle.Enum, Integer> reverseErrorStyleMappings;
+    static final Map<Integer, STDataValidationOperator.Enum> operatorTypeMappings;
+    static final Map<STDataValidationOperator.Enum, Integer> operatorTypeReverseMappings;
+    static final Map<Integer, STDataValidationType.Enum> validationTypeMappings;
+    static final Map<STDataValidationType.Enum, Integer> validationTypeReverseMappings;
+    static final Map<Integer, STDataValidationErrorStyle.Enum> errorStyleMappings;
+    static final Map<STDataValidationErrorStyle.Enum, Integer> reverseErrorStyleMappings;
 
     static {
-        errorStyleMappings.put(DataValidation.ErrorStyle.INFO, STDataValidationErrorStyle.INFORMATION);
-        errorStyleMappings.put(DataValidation.ErrorStyle.STOP, STDataValidationErrorStyle.STOP);
-        errorStyleMappings.put(DataValidation.ErrorStyle.WARNING, STDataValidationErrorStyle.WARNING);
-
-        reverseErrorStyleMappings = MapUtils.invertMap(errorStyleMappings);
-
-        operatorTypeMappings.put(DataValidationConstraint.OperatorType.BETWEEN,STDataValidationOperator.BETWEEN);
-        operatorTypeMappings.put(DataValidationConstraint.OperatorType.NOT_BETWEEN,STDataValidationOperator.NOT_BETWEEN);
-        operatorTypeMappings.put(DataValidationConstraint.OperatorType.EQUAL,STDataValidationOperator.EQUAL);
-        operatorTypeMappings.put(DataValidationConstraint.OperatorType.NOT_EQUAL,STDataValidationOperator.NOT_EQUAL);
-        operatorTypeMappings.put(DataValidationConstraint.OperatorType.GREATER_THAN,STDataValidationOperator.GREATER_THAN);
-        operatorTypeMappings.put(DataValidationConstraint.OperatorType.GREATER_OR_EQUAL,STDataValidationOperator.GREATER_THAN_OR_EQUAL);
-        operatorTypeMappings.put(DataValidationConstraint.OperatorType.LESS_THAN,STDataValidationOperator.LESS_THAN);
-        operatorTypeMappings.put(DataValidationConstraint.OperatorType.LESS_OR_EQUAL,STDataValidationOperator.LESS_THAN_OR_EQUAL);
-
-        for( Map.Entry<Integer,STDataValidationOperator.Enum> entry : operatorTypeMappings.entrySet() ) {
-            operatorTypeReverseMappings.put(entry.getValue(),entry.getKey());
-        }
 
-        validationTypeMappings.put(DataValidationConstraint.ValidationType.FORMULA,STDataValidationType.CUSTOM);
-        validationTypeMappings.put(DataValidationConstraint.ValidationType.DATE,STDataValidationType.DATE);
-        validationTypeMappings.put(DataValidationConstraint.ValidationType.DECIMAL,STDataValidationType.DECIMAL);
-        validationTypeMappings.put(DataValidationConstraint.ValidationType.LIST,STDataValidationType.LIST);
-        validationTypeMappings.put(DataValidationConstraint.ValidationType.ANY,STDataValidationType.NONE);
-        validationTypeMappings.put(DataValidationConstraint.ValidationType.TEXT_LENGTH,STDataValidationType.TEXT_LENGTH);
-        validationTypeMappings.put(DataValidationConstraint.ValidationType.TIME,STDataValidationType.TIME);
-        validationTypeMappings.put(DataValidationConstraint.ValidationType.INTEGER,STDataValidationType.WHOLE);
-
-        for( Map.Entry<Integer,STDataValidationType.Enum> entry : validationTypeMappings.entrySet() ) {
-            validationTypeReverseMappings.put(entry.getValue(),entry.getKey());
-        }
+        final HashMap<Integer, STDataValidationErrorStyle.Enum> esMappings = new HashMap<>();
+        esMappings.put(DataValidation.ErrorStyle.INFO, STDataValidationErrorStyle.INFORMATION);
+        esMappings.put(DataValidation.ErrorStyle.STOP, STDataValidationErrorStyle.STOP);
+        esMappings.put(DataValidation.ErrorStyle.WARNING, STDataValidationErrorStyle.WARNING);
+        errorStyleMappings = Collections.unmodifiableMap(esMappings);
+
+        reverseErrorStyleMappings = Collections.unmodifiableMap(MapUtils.invertMap(esMappings));
+
+        final Map<Integer, STDataValidationOperator.Enum> otMappings = new HashMap<>();
+        otMappings.put(DataValidationConstraint.OperatorType.BETWEEN,STDataValidationOperator.BETWEEN);
+        otMappings.put(DataValidationConstraint.OperatorType.NOT_BETWEEN,STDataValidationOperator.NOT_BETWEEN);
+        otMappings.put(DataValidationConstraint.OperatorType.EQUAL,STDataValidationOperator.EQUAL);
+        otMappings.put(DataValidationConstraint.OperatorType.NOT_EQUAL,STDataValidationOperator.NOT_EQUAL);
+        otMappings.put(DataValidationConstraint.OperatorType.GREATER_THAN,STDataValidationOperator.GREATER_THAN);
+        otMappings.put(DataValidationConstraint.OperatorType.GREATER_OR_EQUAL,STDataValidationOperator.GREATER_THAN_OR_EQUAL);
+        otMappings.put(DataValidationConstraint.OperatorType.LESS_THAN,STDataValidationOperator.LESS_THAN);
+        otMappings.put(DataValidationConstraint.OperatorType.LESS_OR_EQUAL,STDataValidationOperator.LESS_THAN_OR_EQUAL);
+        operatorTypeMappings = Collections.unmodifiableMap(otMappings);
+
+        operatorTypeReverseMappings = Collections.unmodifiableMap(MapUtils.invertMap(otMappings));
+
+        final Map<Integer, STDataValidationType.Enum> vtMappings = new HashMap<>();
+        vtMappings.put(DataValidationConstraint.ValidationType.FORMULA,STDataValidationType.CUSTOM);
+        vtMappings.put(DataValidationConstraint.ValidationType.DATE,STDataValidationType.DATE);
+        vtMappings.put(DataValidationConstraint.ValidationType.DECIMAL,STDataValidationType.DECIMAL);
+        vtMappings.put(DataValidationConstraint.ValidationType.LIST,STDataValidationType.LIST);
+        vtMappings.put(DataValidationConstraint.ValidationType.ANY,STDataValidationType.NONE);
+        vtMappings.put(DataValidationConstraint.ValidationType.TEXT_LENGTH,STDataValidationType.TEXT_LENGTH);
+        vtMappings.put(DataValidationConstraint.ValidationType.TIME,STDataValidationType.TIME);
+        vtMappings.put(DataValidationConstraint.ValidationType.INTEGER,STDataValidationType.WHOLE);
+        validationTypeMappings = Collections.unmodifiableMap(vtMappings);
+
+        validationTypeReverseMappings = Collections.unmodifiableMap(MapUtils.invertMap(validationTypeMappings));
+
     }
 
     XSSFDataValidation(CellRangeAddressList regions,CTDataValidation ctDataValidation) {
index 64f34cbb2094c59cfc7eb841746f9486e81fbf5b..8e6df981b4e91b12f889f457cb1dd272a3851368 100644 (file)
@@ -45,7 +45,7 @@ public enum VerticalAlign {
      */
     SUBSCRIPT(3);
 
-    private static Map<Integer, VerticalAlign> imap = new HashMap<>();
+    private static final Map<Integer, VerticalAlign> imap = new HashMap<>();
 
     static {
         for (VerticalAlign p : values()) {