From db57a3194472acedddb2a9570e8cd605f77f9efb Mon Sep 17 00:00:00 2001 From: "Coral.Chen" Date: Wed, 16 Oct 2024 11:15:11 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-137276=20fix:=20=E5=B9=B6=E5=8F=91?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E4=B8=8B=E7=9A=84hashmap=E6=AD=BB=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../poi/hssf/record/WindowTwoRecord.java | 26 +++++++++---------- .../org/apache/poi/util/BitFieldFactory.java | 19 +++++--------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/fine-poi-old/src/main/java/com/fr/third/org/apache/poi/hssf/record/WindowTwoRecord.java b/fine-poi-old/src/main/java/com/fr/third/org/apache/poi/hssf/record/WindowTwoRecord.java index d6a93e988..6ca0e33bd 100644 --- a/fine-poi-old/src/main/java/com/fr/third/org/apache/poi/hssf/record/WindowTwoRecord.java +++ b/fine-poi-old/src/main/java/com/fr/third/org/apache/poi/hssf/record/WindowTwoRecord.java @@ -39,23 +39,21 @@ public class WindowTwoRecord private short field_1_options; // bitfields - private BitField displayFormulas = BitFieldFactory.getInstance(0x01); - private BitField displayGridlines = BitFieldFactory.getInstance(0x02); - private BitField displayRowColHeadings = BitFieldFactory.getInstance(0x04); - private BitField freezePanes = BitFieldFactory.getInstance(0x08); - private BitField displayZeros = BitFieldFactory.getInstance(0x10); - private BitField defaultHeader = - BitFieldFactory.getInstance(0x20); // if false use color in field 4 + private static final BitField displayFormulas = BitFieldFactory.getInstance(0x01); + private static final BitField displayGridlines = BitFieldFactory.getInstance(0x02); + private static final BitField displayRowColHeadings = BitFieldFactory.getInstance(0x04); + private static final BitField freezePanes = BitFieldFactory.getInstance(0x08); + private static final BitField displayZeros = BitFieldFactory.getInstance(0x10); + private static final BitField defaultHeader = BitFieldFactory.getInstance(0x20); // if false use color in field 4 // if true use default foreground // for headers - private BitField arabic = - BitFieldFactory.getInstance(0x40); // for our desert dwelling friends - private BitField displayGuts = BitFieldFactory.getInstance(0x80); - private BitField freezePanesNoSplit = BitFieldFactory.getInstance(0x100); - private BitField selected = BitFieldFactory.getInstance(0x200); - private BitField active = BitFieldFactory.getInstance(0x400); - private BitField savedInPageBreakPreview = BitFieldFactory.getInstance(0x800); + private static final BitField arabic = BitFieldFactory.getInstance(0x40); // for our desert dwelling friends + private static final BitField displayGuts = BitFieldFactory.getInstance(0x80); + private static final BitField freezePanesNoSplit = BitFieldFactory.getInstance(0x100); + private static final BitField selected = BitFieldFactory.getInstance(0x200); + private static final BitField active = BitFieldFactory.getInstance(0x400); + private static final BitField savedInPageBreakPreview = BitFieldFactory.getInstance(0x800); // 4-7 reserved // end bitfields diff --git a/fine-poi-old/src/main/java/com/fr/third/org/apache/poi/util/BitFieldFactory.java b/fine-poi-old/src/main/java/com/fr/third/org/apache/poi/util/BitFieldFactory.java index ad40eee30..3f4e493ce 100644 --- a/fine-poi-old/src/main/java/com/fr/third/org/apache/poi/util/BitFieldFactory.java +++ b/fine-poi-old/src/main/java/com/fr/third/org/apache/poi/util/BitFieldFactory.java @@ -19,7 +19,7 @@ package com.fr.third.org.apache.poi.util; -import java.util.*; +import java.util.concurrent.ConcurrentHashMap; /** * Returns immutable Btfield instances. @@ -27,18 +27,11 @@ import java.util.*; * @author Jason Height (jheight at apache dot org) */ -public class BitFieldFactory -{ - private static Map instances = new HashMap(); - - public static BitField getInstance(final int mask) { - BitField f = (BitField)instances.get(new Integer(mask)); - if (f == null) { - f = new BitField(mask); - instances.put(new Integer(mask), f); - } - return f; - } +public class BitFieldFactory { + private static final ConcurrentHashMap instances = new ConcurrentHashMap<>(); + public static BitField getInstance(int mask) { + return instances.computeIfAbsent(mask, k -> new BitField(mask)); + } } // end public class BitFieldFactory