aboutsummaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2011-03-04 12:50:02 +0000
committerNick Burch <nick@apache.org>2011-03-04 12:50:02 +0000
commitd7cc7e582bc7215be659f17879573a8a9417fcc8 (patch)
treec77aabd8e2a707305a8cd594300d4a31ea48c5a6 /src/java
parentce77707b83b197ffd1b7a6be4b06d03ee3c042e4 (diff)
downloadpoi-d7cc7e582bc7215be659f17879573a8a9417fcc8.tar.gz
poi-d7cc7e582bc7215be659f17879573a8a9417fcc8.zip
From bug #50786 - Speed up calls to HSSFColor.getIndexHash() by returning a cached, unmodifiable Map. HSSFColor.getModifiableIndexHash() provides access to the old (slow but modifiable) functionality
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1077920 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
-rw-r--r--src/java/org/apache/poi/hssf/util/HSSFColor.java29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/java/org/apache/poi/hssf/util/HSSFColor.java b/src/java/org/apache/poi/hssf/util/HSSFColor.java
index bca0047dc3..617224bdf6 100644
--- a/src/java/org/apache/poi/hssf/util/HSSFColor.java
+++ b/src/java/org/apache/poi/hssf/util/HSSFColor.java
@@ -18,7 +18,9 @@
package org.apache.poi.hssf.util;
import java.lang.reflect.Field;
+import java.util.Collections;
import java.util.Hashtable;
+import java.util.Map;
import org.apache.poi.ss.usermodel.Color;
@@ -37,7 +39,7 @@ import org.apache.poi.ss.usermodel.Color;
* @author Brian Sanders (bsanders at risklabs dot com) - full default color palette
*/
public class HSSFColor implements Color {
- // TODO make subclass instances immutable
+ private static Map<Integer,HSSFColor> indexHash;
/** Creates a new instance of HSSFColor */
public HSSFColor()
@@ -45,17 +47,26 @@ public class HSSFColor implements Color {
}
/**
- * this function returns all colors in a hastable. Its not implemented as a
- * static member/staticly initialized because that would be dirty in a
- * server environment as it is intended. This means you'll eat the time
- * it takes to create it once per request but you will not hold onto it
- * if you have none of those requests.
+ * This function returns all the colours in an unmodifiable Map.
+ * The map is cached on first use.
*
- * @return a hashtable containing all colors keyed by <tt>Integer</tt> excel-style palette indexes
+ * @return a Map containing all colours keyed by <tt>Integer</tt> excel-style palette indexes
*/
- public final static Hashtable<Integer,HSSFColor> getIndexHash() {
+ public final static Map<Integer,HSSFColor> getIndexHash() {
+ if(indexHash == null) {
+ indexHash = Collections.unmodifiableMap( createColorsByIndexMap() );
+ }
- return createColorsByIndexMap();
+ return indexHash;
+ }
+ /**
+ * This function returns all the Colours, stored in a Hashtable that
+ * can be edited. No caching is performed. If you don't need to edit
+ * the table, then call {@link #getIndexHash()} which returns a
+ * statically cached imuatable map of colours.
+ */
+ public final static Hashtable<Integer,HSSFColor> getMutableIndexHash() {
+ return createColorsByIndexMap();
}
private static Hashtable<Integer,HSSFColor> createColorsByIndexMap() {