From 822974aadc69be4482b710505fae4b220eecf29c Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Tue, 15 Oct 2024 16:33:15 +0000 Subject: [PATCH] make static maps final git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1921340 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/xwpf/usermodel/Borders.java | 2 +- .../org/apache/poi/xwpf/usermodel/BreakType.java | 7 +++++-- .../poi/xwpf/usermodel/LineSpacingRule.java | 7 +++++-- .../apache/poi/xwpf/usermodel/TableRowAlign.java | 7 +++++-- .../poi/xwpf/usermodel/TableRowHeightRule.java | 7 +++++-- .../apache/poi/xwpf/usermodel/TextAlignment.java | 7 +++++-- .../apache/poi/hmef/attribute/TNEFProperty.java | 2 +- .../apache/poi/hsmf/datatypes/MAPIProperty.java | 2 +- .../poi/ss/formula/functions/LookupUtils.java | 15 ++++++++++----- .../apache/poi/ss/usermodel/ConditionType.java | 2 +- 10 files changed, 39 insertions(+), 19 deletions(-) diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/Borders.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/Borders.java index 2ab27d37da..6b08e0ee25 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/Borders.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/Borders.java @@ -604,7 +604,7 @@ public enum Borders { static { final Map tempMap = new HashMap<>(); for (Borders p : values()) { - tempMap.put(Integer.valueOf(p.getValue()), p); + tempMap.put(p.getValue(), p); } imap = Collections.unmodifiableMap(tempMap); } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/BreakType.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/BreakType.java index f86a89e25f..5eaebd9b68 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/BreakType.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/BreakType.java @@ -16,6 +16,7 @@ ==================================================================== */ package org.apache.poi.xwpf.usermodel; +import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -54,12 +55,14 @@ public enum BreakType { */ TEXT_WRAPPING(3); - private static Map imap = new HashMap<>(); + private static final Map imap; static { + final Map tempMap = new HashMap<>(); for (BreakType p : values()) { - imap.put(p.getValue(), p); + tempMap.put(p.getValue(), p); } + imap = Collections.unmodifiableMap(tempMap); } private final int value; diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/LineSpacingRule.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/LineSpacingRule.java index b8b6fbde71..4b9cb9804e 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/LineSpacingRule.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/LineSpacingRule.java @@ -16,6 +16,7 @@ ==================================================================== */ package org.apache.poi.xwpf.usermodel; +import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -47,12 +48,14 @@ public enum LineSpacingRule { AT_LEAST(3); - private static Map imap = new HashMap<>(); + private static final Map imap; static { + final Map tempMap = new HashMap<>(); for (LineSpacingRule p : values()) { - imap.put(p.getValue(), p); + tempMap.put(p.getValue(), p); } + imap = Collections.unmodifiableMap(tempMap); } private final int value; diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/TableRowAlign.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/TableRowAlign.java index 35e80d33b1..06653cdb33 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/TableRowAlign.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/TableRowAlign.java @@ -18,6 +18,7 @@ package org.apache.poi.xwpf.usermodel; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJcTable; +import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -30,12 +31,14 @@ public enum TableRowAlign { CENTER(STJcTable.INT_CENTER), RIGHT(STJcTable.INT_END); - private static Map imap = new HashMap<>(); + private static final Map imap; static { + final Map tempMap = new HashMap<>(); for (TableRowAlign p : values()) { - imap.put(p.getValue(), p); + tempMap.put(p.getValue(), p); } + imap = Collections.unmodifiableMap(tempMap); } private final int value; diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/TableRowHeightRule.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/TableRowHeightRule.java index 2a42c76baf..cbe41afc6e 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/TableRowHeightRule.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/TableRowHeightRule.java @@ -16,6 +16,7 @@ ==================================================================== */ package org.apache.poi.xwpf.usermodel; +import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -28,12 +29,14 @@ public enum TableRowHeightRule { EXACT(2), AT_LEAST(3); - private static Map imap = new HashMap<>(); + private static final Map imap; static { + final Map tempMap = new HashMap<>(); for (TableRowHeightRule p : values()) { - imap.put(p.getValue(), p); + tempMap.put(p.getValue(), p); } + imap = Collections.unmodifiableMap(tempMap); } private final int value; diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/TextAlignment.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/TextAlignment.java index 3fb8231589..97d9e3cd53 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/TextAlignment.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/TextAlignment.java @@ -16,6 +16,7 @@ ==================================================================== */ package org.apache.poi.xwpf.usermodel; +import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -50,12 +51,14 @@ public enum TextAlignment { */ AUTO(5); - private static Map imap = new HashMap<>(); + private static final Map imap; static { + final Map tempMap = new HashMap<>(); for (TextAlignment p : values()) { - imap.put(p.getValue(), p); + tempMap.put(p.getValue(), p); } + imap = Collections.unmodifiableMap(tempMap); } private final int value; diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hmef/attribute/TNEFProperty.java b/poi-scratchpad/src/main/java/org/apache/poi/hmef/attribute/TNEFProperty.java index e90c910470..151ac152ff 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hmef/attribute/TNEFProperty.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hmef/attribute/TNEFProperty.java @@ -30,7 +30,7 @@ import java.util.Map; * ones, so we can't just re-use the HSMF ones. */ public final class TNEFProperty { - private static Map> properties = new HashMap<>(); + private static final Map> properties = new HashMap<>(); // Types taken from http://msdn.microsoft.com/en-us/library/microsoft.exchange.data.contenttypes.tnef.tnefattributetype%28v=EXCHG.140%29.aspx public static final int TYPE_TRIPLES = 0x0000; diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hsmf/datatypes/MAPIProperty.java b/poi-scratchpad/src/main/java/org/apache/poi/hsmf/datatypes/MAPIProperty.java index b09e39cc7a..5afe53b6bf 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hsmf/datatypes/MAPIProperty.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hsmf/datatypes/MAPIProperty.java @@ -46,7 +46,7 @@ import static org.apache.poi.hsmf.datatypes.Types.TIME; */ @SuppressWarnings("unused") public class MAPIProperty { - private static Map attributes = new HashMap<>(); + private static final Map attributes = new HashMap<>(); public static final MAPIProperty AB_DEFAULT_DIR = new MAPIProperty(0x3d06, BINARY, "AbDefaultDir", "PR_AB_DEFAULT_DIR"); diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/LookupUtils.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/LookupUtils.java index d36ae34b7a..0c260e3975 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/LookupUtils.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/LookupUtils.java @@ -17,6 +17,7 @@ package org.apache.poi.ss.formula.functions; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -75,16 +76,20 @@ public final class LookupUtils { public int getIntValue() { return intValue; } } - private static Map matchModeMap = new HashMap<>(); - private static Map searchModeMap = new HashMap<>(); + private static final Map matchModeMap; + private static final Map searchModeMap; static { + final Map mmMap = new HashMap<>(); for (MatchMode mode : MatchMode.values()) { - matchModeMap.put(mode.getIntValue(), mode); + mmMap.put(mode.getIntValue(), mode); } + matchModeMap = Collections.unmodifiableMap(mmMap); + final Map smMap = new HashMap<>(); for (SearchMode mode : SearchMode.values()) { - searchModeMap.put(mode.getIntValue(), mode); + smMap.put(mode.getIntValue(), mode); } + searchModeMap = Collections.unmodifiableMap(smMap); } public static MatchMode matchMode(int m) { @@ -588,7 +593,7 @@ public final class LookupUtils { if (valEval instanceof StringEval) { String stringValue = ((StringEval) valEval).getStringValue(); - if(stringValue.length() < 1) { + if(stringValue.isEmpty()) { // More trickiness: // Empty string is not the same as BlankEval. It causes #VALUE! error throw EvaluationException.invalidValue(); diff --git a/poi/src/main/java/org/apache/poi/ss/usermodel/ConditionType.java b/poi/src/main/java/org/apache/poi/ss/usermodel/ConditionType.java index a5681cd4b9..111cc93f1a 100644 --- a/poi/src/main/java/org/apache/poi/ss/usermodel/ConditionType.java +++ b/poi/src/main/java/org/apache/poi/ss/usermodel/ConditionType.java @@ -26,7 +26,7 @@ import java.util.Map; * Represents a type of a conditional formatting rule */ public class ConditionType { - private static Map lookup = new HashMap<>(); + private static final Map lookup = new HashMap<>(); /** * This conditional formatting rule compares a cell value -- 2.39.5