From 88a0d4ecf322be33b7df3ebfc21eff1f176a4efb Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Tue, 15 Oct 2024 16:08:07 +0000 Subject: [PATCH] make it harder to modify metadata in maps git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1921337 13f79535-47bb-0310-9956-ffa450edef68 --- .../xssf/usermodel/XSSFDataValidation.java | 83 ++++++++++--------- .../poi/xwpf/usermodel/VerticalAlign.java | 2 +- 2 files changed, 45 insertions(+), 40 deletions(-) diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDataValidation.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDataValidation.java index 4cc723ee2c..a284c96bde 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDataValidation.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDataValidation.java @@ -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 operatorTypeMappings = new HashMap<>(); - static Map operatorTypeReverseMappings = new HashMap<>(); - static Map validationTypeMappings = new HashMap<>(); - static Map validationTypeReverseMappings = new HashMap<>(); - static Map errorStyleMappings = new HashMap<>(); - static Map reverseErrorStyleMappings; + static final Map operatorTypeMappings; + static final Map operatorTypeReverseMappings; + static final Map validationTypeMappings; + static final Map validationTypeReverseMappings; + static final Map errorStyleMappings; + static final Map 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 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 entry : validationTypeMappings.entrySet() ) { - validationTypeReverseMappings.put(entry.getValue(),entry.getKey()); - } + final HashMap 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 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 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) { diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/VerticalAlign.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/VerticalAlign.java index 64f34cbb20..8e6df981b4 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/VerticalAlign.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/VerticalAlign.java @@ -45,7 +45,7 @@ public enum VerticalAlign { */ SUBSCRIPT(3); - private static Map imap = new HashMap<>(); + private static final Map imap = new HashMap<>(); static { for (VerticalAlign p : values()) { -- 2.39.5