You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by jo...@apache.org on 2008/12/03 06:07:31 UTC
svn commit: r722778 - in /poi/trunk/src: java/org/apache/poi/hssf/usermodel/
java/org/apache/poi/ss/formula/ ooxml/java/org/apache/poi/xssf/usermodel/
Author: josh
Date: Tue Dec 2 21:07:31 2008
New Revision: 722778
URL: http://svn.apache.org/viewvc?rev=722778&view=rev
Log:
modified EvaluationCell to make Evaluation API more easily wrapable.
Modified:
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java
poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationCell.java
poi/trunk/src/java/org/apache/poi/ss/formula/FormulaCellCache.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationCell.java
Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java?rev=722778&r1=722777&r2=722778&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java Tue Dec 2 21:07:31 2008
@@ -34,15 +34,12 @@
_evalSheet = evalSheet;
}
public HSSFEvaluationCell(HSSFCell cell) {
- _cell = cell;
- _evalSheet = new HSSFEvaluationSheet(cell.getSheet());
+ this(cell, new HSSFEvaluationSheet(cell.getSheet()));
}
- // Note - hashCode and equals defined according to underlying cell
- public int hashCode() {
- return _cell.hashCode();
- }
- public boolean equals(Object obj) {
- return _cell == ((HSSFEvaluationCell)obj)._cell;
+ public Object getIdentityKey() {
+ // save memory by just using the cell itself as the identity key
+ // Note - this assumes HSSFCell has not overridden hashCode and equals
+ return _cell;
}
public HSSFCell getHSSFCell() {
Modified: poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationCell.java?rev=722778&r1=722777&r2=722778&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationCell.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationCell.java Tue Dec 2 21:07:31 2008
@@ -17,19 +17,22 @@
package org.apache.poi.ss.formula;
+import java.util.HashMap;
+
/**
* Abstracts a cell for the purpose of formula evaluation. This interface represents both formula
* and non-formula cells.<br/>
*
- * Implementors of this class must implement {@link Object#hashCode()} and {@link Object#equals(Object)}
- * to provide an <em>identity</em> relationship based on the underlying HSSF or XSSF cell <p/>
- *
* For POI internal use only
*
* @author Josh Micich
*/
public interface EvaluationCell {
- // consider method Object getUnderlyingCell() to reduce memory consumption in formula cell cache
+ /**
+ * @return an Object that identifies the underlying cell, suitable for use as a key in a {@link HashMap}
+ */
+ Object getIdentityKey();
+
EvaluationSheet getSheet();
int getRowIndex();
int getColumnIndex();
Modified: poi/trunk/src/java/org/apache/poi/ss/formula/FormulaCellCache.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/FormulaCellCache.java?rev=722778&r1=722777&r2=722778&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/FormulaCellCache.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/FormulaCellCache.java Tue Dec 2 21:07:31 2008
@@ -31,11 +31,11 @@
void processEntry(FormulaCellCacheEntry entry);
}
- private Map _formulaEntriesByCell;
+ private final Map<Object, FormulaCellCacheEntry> _formulaEntriesByCell;
public FormulaCellCache() {
- // assumes HSSFCell does not override hashCode or equals, otherwise we need IdentityHashMap
- _formulaEntriesByCell = new HashMap();
+ // assumes the object returned by EvaluationCell.getIdentityKey() has a well behaved hashCode+equals
+ _formulaEntriesByCell = new HashMap<Object, FormulaCellCacheEntry>();
}
public CellCacheEntry[] getCacheEntries() {
@@ -53,15 +53,15 @@
* @return <code>null</code> if not found
*/
public FormulaCellCacheEntry get(EvaluationCell cell) {
- return (FormulaCellCacheEntry) _formulaEntriesByCell.get(cell);
+ return _formulaEntriesByCell.get(cell.getIdentityKey());
}
public void put(EvaluationCell cell, FormulaCellCacheEntry entry) {
- _formulaEntriesByCell.put(cell, entry);
+ _formulaEntriesByCell.put(cell.getIdentityKey(), entry);
}
public FormulaCellCacheEntry remove(EvaluationCell cell) {
- return (FormulaCellCacheEntry) _formulaEntriesByCell.remove(cell);
+ return _formulaEntriesByCell.remove(cell.getIdentityKey());
}
public void applyOperation(IEntryOperation operation) {
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationCell.java?rev=722778&r1=722777&r2=722778&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationCell.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationCell.java Tue Dec 2 21:07:31 2008
@@ -30,22 +30,19 @@
private final EvaluationSheet _evalSheet;
private final XSSFCell _cell;
- public XSSFEvaluationCell(XSSFCell cell) {
- _cell = cell;
- _evalSheet = new XSSFEvaluationSheet(cell.getSheet());
- }
-
public XSSFEvaluationCell(XSSFCell cell, XSSFEvaluationSheet evaluationSheet) {
_cell = cell;
_evalSheet = evaluationSheet;
}
- // Note - hashCode and equals defined according to underlying cell
- public int hashCode() {
- return _cell.hashCode();
+ public XSSFEvaluationCell(XSSFCell cell) {
+ this(cell, new XSSFEvaluationSheet(cell.getSheet()));
}
- public boolean equals(Object obj) {
- return _cell == ((XSSFEvaluationCell)obj)._cell;
+
+ public Object getIdentityKey() {
+ // save memory by just using the cell itself as the identity key
+ // Note - this assumes HSSFCell has not overridden hashCode and equals
+ return _cell;
}
public XSSFCell getXSSFCell() {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org