You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2011/03/04 13:50:02 UTC
svn commit: r1077920 - in /poi/trunk/src: documentation/content/xdocs/
examples/src/org/apache/poi/hssf/view/
examples/src/org/apache/poi/ss/examples/html/ java/org/apache/poi/hssf/util/
Author: nick
Date: Fri Mar 4 12:50:02 2011
New Revision: 1077920
URL: http://svn.apache.org/viewvc?rev=1077920&view=rev
Log:
>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
Modified:
poi/trunk/src/documentation/content/xdocs/status.xml
poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellEditor.java
poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableUtils.java
poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/XSSFHtmlHelper.java
poi/trunk/src/java/org/apache/poi/hssf/util/HSSFColor.java
Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1077920&r1=1077919&r2=1077920&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Fri Mar 4 12:50:02 2011
@@ -34,6 +34,7 @@
<changes>
<release version="3.8-beta2" date="2011-??-??">
+ <action dev="poi-developers" type="fix">50786 - Speed up calls to HSSFColor.getIndexHash() by returning a cached, unmodifiable Map. HSSFColor.getModifiableIndexHash() provides access to the old (slow but modifiable) functionality</action>
<action dev="poi-developers" type="fix">47100 - Change related formulas and named ranges when XSSFWorkbook.setSheetName is called</action>
</release>
<release version="3.8-beta1" date="2011-03-07">
Modified: poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellEditor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellEditor.java?rev=1077920&r1=1077919&r2=1077920&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellEditor.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellEditor.java Fri Mar 4 12:50:02 2011
@@ -37,7 +37,7 @@ import org.apache.poi.hssf.util.HSSFColo
public class SVTableCellEditor extends AbstractCellEditor implements TableCellEditor, ActionListener {
private static final Color black = getAWTColor(new HSSFColor.BLACK());
private static final Color white = getAWTColor(new HSSFColor.WHITE());
- private Hashtable colors = HSSFColor.getIndexHash();
+ private Map<Integer,HSSFColor> colors = HSSFColor.getIndexHash();
private HSSFWorkbook wb;
Modified: poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableUtils.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableUtils.java?rev=1077920&r1=1077919&r2=1077920&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableUtils.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableUtils.java Fri Mar 4 12:50:02 2011
@@ -31,7 +31,7 @@ import org.apache.poi.hssf.util.*;
* @author Jason Height
*/
public class SVTableUtils {
- private final static Hashtable colors = HSSFColor.getIndexHash();
+ private final static Map<Integer,HSSFColor> colors = HSSFColor.getIndexHash();
/** Description of the Field */
public final static Color black = getAWTColor(new HSSFColor.BLACK());
/** Description of the Field */
Modified: poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/XSSFHtmlHelper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/XSSFHtmlHelper.java?rev=1077920&r1=1077919&r2=1077920&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/XSSFHtmlHelper.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/XSSFHtmlHelper.java Fri Mar 4 12:50:02 2011
@@ -16,15 +16,15 @@
==================================================================== */
package org.apache.poi.ss.examples.html;
+import java.util.Formatter;
+import java.util.Map;
+
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import java.util.Formatter;
-import java.util.Hashtable;
-
/**
* Implementation of {@link HtmlHelper} for XSSF files.
*
@@ -33,7 +33,7 @@ import java.util.Hashtable;
public class XSSFHtmlHelper implements HtmlHelper {
private final XSSFWorkbook wb;
- private static final Hashtable colors = HSSFColor.getIndexHash();
+ private static final Map<Integer,HSSFColor> colors = HSSFColor.getIndexHash();
public XSSFHtmlHelper(XSSFWorkbook wb) {
this.wb = wb;
Modified: poi/trunk/src/java/org/apache/poi/hssf/util/HSSFColor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/util/HSSFColor.java?rev=1077920&r1=1077919&r2=1077920&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/util/HSSFColor.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/util/HSSFColor.java Fri Mar 4 12:50:02 2011
@@ -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() {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org