Skip to content

Commit

Permalink
make it harder to modify metadata in maps
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1921337 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
pjfanning committed Oct 15, 2024
1 parent ab68210 commit 88a0d4e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
==================================================================== */
package org.apache.poi.xssf.usermodel;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -34,49 +35,53 @@ Licensed to the Apache Software Foundation (ASF) under one or more
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit 88a0d4e

Please sign in to comment.