ASF Bugzilla – Attachment 1745 Details for
Bug 8665
[PATCH] formulas:- cleanup, javadocs, and float test
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
The patch - now formula viewer also works
formula5.patch (text/plain), 53.15 KB, created by
Avik Sengupta
on 2002-04-30 19:20:33 UTC
(
hide
)
Description:
The patch - now formula viewer also works
Filename:
MIME Type:
Creator:
Avik Sengupta
Created:
2002-04-30 19:20:33 UTC
Size:
53.15 KB
patch
obsolete
>? formula5.patch >? test.xls >? src/documentation/xdocs/.nbattrs >? src/documentation/xdocs/hdf/.nbattrs >? src/documentation/xdocs/hpsf/.nbattrs >? src/documentation/xdocs/hssf/.nbattrs >? src/documentation/xdocs/news/.nbattrs >? src/documentation/xdocs/plan/.nbattrs >? src/documentation/xdocs/poifs/.nbattrs >? src/documentation/xdocs/resolutions/.nbattrs >? src/documentation/xdocs/utils/.nbattrs >? src/java/org/apache/poi/hssf/model/.nbattrs >? src/java/org/apache/poi/hssf/record/.nbattrs >? src/java/org/apache/poi/hssf/record/formula/.nbattrs >? src/java/org/apache/poi/hssf/usermodel/.nbattrs >? src/testcases/org/apache/poi/hssf/usermodel/.nbattrs >? tools/antipede/lib/temp >Index: src/java/org/apache/poi/hssf/dev/FormulaViewer.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/dev/FormulaViewer.java,v >retrieving revision 1.1.1.1 >diff -u -r1.1.1.1 FormulaViewer.java >--- src/java/org/apache/poi/hssf/dev/FormulaViewer.java 31 Jan 2002 02:23:41 -0000 1.1.1.1 >+++ src/java/org/apache/poi/hssf/dev/FormulaViewer.java 30 Apr 2002 19:17:50 -0000 >@@ -82,6 +82,7 @@ > * FormulaViewer - finds formulas in a BIFF8 file and attempts to read them/display > * data from them. Only works if Formulas are enabled in "RecordFactory" > * @author andy >+ * @author Avik > */ > > public class FormulaViewer >@@ -132,40 +133,34 @@ > > public void parseFormulaRecord(FormulaRecord record) > { >- System.out.println("In ParseFormula Record"); >- System.out.println("row = " + record.getRow()); >- System.out.println("col = " + record.getColumn()); >+ System.out.println("=============================="); >+ System.out.print("row = " + record.getRow()); >+ System.out.println(", col = " + record.getColumn()); > System.out.println("value = " + record.getValue()); >- System.out.println("xf = " + record.getXFIndex()); >- System.out.println("number of ptgs = " >+ System.out.print("xf = " + record.getXFIndex()); >+ System.out.print(", number of ptgs = " > + record.getNumberOfExpressionTokens()); >- System.out.println("options = " + record.getOptions()); >- System.out.println(composeForumla(record)); >+ System.out.println(", options = " + record.getOptions()); >+ System.out.println("RPN List = "+formulaString(record)); >+ System.out.println("Formula text = "+ composeForumla(record)); > } > >- public String composeForumla(FormulaRecord record) >- { >+ private String formulaString(FormulaRecord record) { > StringBuffer formula = new StringBuffer("="); > int numptgs = record.getNumberOfExpressionTokens(); >- List ptgs = record.getParsedExpression(); >- >- for (int ptgnum = numptgs - 1; ptgnum > (-1); ptgnum--) >- { >- Ptg ptg = ( Ptg ) ptgs.get(ptgnum); >- OperationPtg optg = ( OperationPtg ) ptg; >- int numops = optg.getNumberOfOperands(); >- Ptg[] ops = new Ptg[ numops ]; >- int opoffset = 1; >- >- for (int opnum = ops.length - 1; opnum > -1; opnum--) >- { >- ops[ opnum ] = ( Ptg ) ptgs.get(ptgnum - opoffset); >- opoffset++; >- } >- formula.append(optg.toFormulaString(ops)); >- ptgnum -= ops.length; >- } >- return formula.toString(); >+ List tokens = record.getParsedExpression(); >+ StringBuffer buf = new StringBuffer(); >+ for (int i=0;i<numptgs;i++) { >+ buf.append( ( (Ptg)tokens.get(i)).toFormulaString()); >+ buf.append(' '); >+ } >+ return buf.toString(); >+ } >+ >+ >+ private String composeForumla(FormulaRecord record) >+ { >+ return FormulaParser.toFormulaString(record.getParsedExpression()); > } > > /** >Index: src/java/org/apache/poi/hssf/model/Sheet.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/model/Sheet.java,v >retrieving revision 1.6 >diff -u -r1.6 Sheet.java >--- src/java/org/apache/poi/hssf/model/Sheet.java 12 Apr 2002 08:26:29 -0000 1.6 >+++ src/java/org/apache/poi/hssf/model/Sheet.java 30 Apr 2002 19:17:56 -0000 >@@ -64,7 +64,7 @@ > import org.apache.poi.util.POILogFactory; > import org.apache.poi.hssf > .record.*; // normally I don't do this, buy we literally mean ALL >-import org.apache.poi.hssf.record.formula.FormulaUtil; >+import org.apache.poi.hssf.record.formula.FormulaParser; > import org.apache.poi.hssf.record.formula.Ptg; > import org.apache.poi.util.IntList; > import org.apache.poi.util.POILogger; >@@ -706,7 +706,9 @@ > rec.setOptions(( short ) 2); > rec.setValue(0); > rec.setXFIndex(( short ) 0x0f); >- Ptg[] ptg = FormulaUtil.parseFormula(formula); >+ FormulaParser fp = new FormulaParser(formula); >+ fp.parse(); >+ Ptg[] ptg = fp.getRPNPtg(); > int size = 0; > > for (int k = 0; k < ptg.length; k++) >Index: src/java/org/apache/poi/hssf/record/formula/AddPtg.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/AddPtg.java,v >retrieving revision 1.8 >diff -u -r1.8 AddPtg.java >--- src/java/org/apache/poi/hssf/record/formula/AddPtg.java 30 Apr 2002 04:43:17 -0000 1.8 >+++ src/java/org/apache/poi/hssf/record/formula/AddPtg.java 30 Apr 2002 19:17:57 -0000 >@@ -78,7 +78,7 @@ > > /** Creates new AddPtg */ > >- public AddPtg() >+ protected AddPtg() > { > } > >@@ -88,10 +88,7 @@ > // doesn't need anything > } > >- protected AddPtg(String formula, int offset) { >- >- } >- >+ > public void writeBytes(byte [] array, int offset) > { > array[ offset + 0 ] = sid; >@@ -111,32 +108,19 @@ > { > return 2; > } >- >+ >+ /** Implementation of method from Ptg */ > public String toFormulaString() > { > return "+"; > } > >- public String toFormulaString(Ptg [] operands) >- { >- StringBuffer buffer = new StringBuffer(); >- >- buffer.append(operands[ 0 ].toFormulaString()); >- buffer.append("+"); >- buffer.append(operands[ 1 ].toFormulaString()); >- return buffer.toString(); >- } >- >- public int getStringLength() { >- return 1; >- } >- >- >+ /** implementation of method from OperationsPtg*/ > public String toFormulaString(String[] operands) { > StringBuffer buffer = new StringBuffer(); > > buffer.append(operands[ 0 ]); >- buffer.append("+"); >+ buffer.append(toFormulaString()); > buffer.append(operands[ 1 ]); > return buffer.toString(); > } >Index: src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java,v >retrieving revision 1.2 >diff -u -r1.2 Area3DPtg.java >--- src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java 30 Apr 2002 04:43:17 -0000 1.2 >+++ src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java 30 Apr 2002 19:17:58 -0000 >@@ -1,247 +1,494 @@ >- >-/* ==================================================================== >- * The Apache Software License, Version 1.1 >- * >- * Copyright (c) 2002 The Apache Software Foundation. All rights >- * reserved. >- * >- * Redistribution and use in source and binary forms, with or without >- * modification, are permitted provided that the following conditions >- * are met: >- * >- * 1. Redistributions of source code must retain the above copyright >- * notice, this list of conditions and the following disclaimer. >- * >- * 2. Redistributions in binary form must reproduce the above copyright >- * notice, this list of conditions and the following disclaimer in >- * the documentation and/or other materials provided with the >- * distribution. >- * >- * 3. The end-user documentation included with the redistribution, >- * if any, must include the following acknowledgment: >- * "This product includes software developed by the >- * Apache Software Foundation (http://www.apache.org/)." >- * Alternately, this acknowledgment may appear in the software itself, >- * if and wherever such third-party acknowledgments normally appear. >- * >- * 4. The names "Apache" and "Apache Software Foundation" and >- * "Apache POI" must not be used to endorse or promote products >- * derived from this software without prior written permission. For >- * written permission, please contact apache@apache.org. >- * >- * 5. Products derived from this software may not be called "Apache", >- * "Apache POI", nor may "Apache" appear in their name, without >- * prior written permission of the Apache Software Foundation. >- * >- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED >- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES >- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE >- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR >- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, >- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT >- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF >- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND >- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, >- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT >- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF >- * SUCH DAMAGE. >- * ==================================================================== >- * >- * This software consists of voluntary contributions made by many >- * individuals on behalf of the Apache Software Foundation. For more >- * information on the Apache Software Foundation, please see >- * <http://www.apache.org/>. >- */ >- >-package org.apache.poi.hssf.record.formula; >- >-import org.apache.poi.util.LittleEndian; >-import org.apache.poi.hssf.util.RangeAddress; >- >-/** >- * Title: Area 3D Ptg - 3D referecnce (Sheet + Area)<P> >- * Description: Defined a area in Extern Sheet. <P> >- * REFERENCE: <P> >- * @author Libin Roman (Vista Portal LDT. Developer) >- * @version 1.0-pre >- */ >- >-public class Area3DPtg extends Ptg >-{ >- public final static short sid = 0x3b; >- private final static int SIZE = 11; // 10 + 1 for Ptg >- private short field_1_index_extern_sheet; >- private short field_2_first_row; >- private short field_3_last_row; >- private short field_4_first_column; >- private short field_5_last_column; >- >- /** Creates new AreaPtg */ >- >- public Area3DPtg() >- { >- } >- >- public Area3DPtg(byte[] data, int offset) >- { >- offset++; >- field_1_index_extern_sheet = LittleEndian.getShort(data, 0 + offset); >- field_2_first_row = LittleEndian.getShort(data, 2 + offset); >- field_3_last_row = LittleEndian.getShort(data, 4 + offset); >- field_4_first_column = LittleEndian.getShort(data, 6 + offset); >- field_5_last_column = LittleEndian.getShort(data, 8 + offset); >- } >- >- public String toString() >- { >- StringBuffer buffer = new StringBuffer(); >- >- buffer.append("AreaPtg\n"); >- buffer.append("Index to Extern Sheet = " + getExternSheetIndex()).append("\n"); >- buffer.append("firstRow = " + getFirstRow()).append("\n"); >- buffer.append("lastRow = " + getLastRow()).append("\n"); >- buffer.append("firstCol = " + getFirstColumn()).append("\n"); >- buffer.append("lastCol = " + getLastColumn()).append("\n"); >- buffer.append("firstColRowRel= " >- + isFirstColRowRelative()).append("\n"); >- buffer.append("lastColRowRel = " >- + isLastColRowRelative()).append("\n"); >- buffer.append("firstColRel = " + isFirstColRelative()).append("\n"); >- buffer.append("lastColRel = " + isLastColRelative()).append("\n"); >- return buffer.toString(); >- } >- >- public void writeBytes(byte [] array, int offset) >- { >- array[ 0 + offset ] = sid; >- LittleEndian.putShort(array, 1 + offset , getExternSheetIndex()); >- LittleEndian.putShort(array, 3 + offset , getFirstRow()); >- LittleEndian.putShort(array, 5 + offset , getLastRow()); >- LittleEndian.putShort(array, 7 + offset , getFirstColumnRaw()); >- LittleEndian.putShort(array, 9 + offset , getLastColumnRaw()); >- } >- >- public int getSize() >- { >- return SIZE; >- } >- >- public short getExternSheetIndex(){ >- return field_1_index_extern_sheet; >- } >- >- public void setExternSheetIndex(short index){ >- field_1_index_extern_sheet = index; >- } >- >- public short getFirstRow() >- { >- return field_2_first_row; >- } >- >- public void setFirstRow(short row) >- { >- field_2_first_row = row; >- } >- >- public short getLastRow() >- { >- return field_3_last_row; >- } >- >- public void setLastRow(short row) >- { >- field_3_last_row = row; >- } >- >- public short getFirstColumn() >- { >- return ( short ) (field_4_first_column & 0xFF); >- } >- >- public short getFirstColumnRaw() >- { >- return field_4_first_column; >- } >- >- public boolean isFirstColRowRelative() >- { >- return (((getFirstColumnRaw()) & 0x8000) == 0x8000); >- } >- >- public boolean isFirstColRelative() >- { >- return (((getFirstColumnRaw()) & 0x4000) == 0x4000); >- } >- >- public void setFirstColumn(short column) >- { >- field_4_first_column &= 0xFF00; >- field_4_first_column |= column & 0xFF; >- } >- >- public void setFirstColumnRaw(short column) >- { >- field_4_first_column = column; >- } >- >- public short getLastColumn() >- { >- return ( short ) (field_5_last_column & 0xFF); >- } >- >- public short getLastColumnRaw() >- { >- return field_5_last_column; >- } >- >- public boolean isLastColRowRelative() >- { >- return (((getLastColumnRaw()) & 0x8000) == 1); >- } >- >- public boolean isLastColRelative() >- { >- return (((getFirstColumnRaw()) & 0x4000) == 1); >- } >- >- public void setLastColumn(short column) >- { >- field_5_last_column &= 0xFF00; >- field_5_last_column |= column & 0xFF; >- } >- >- public void setLastColumnRaw(short column) >- { >- field_5_last_column = column; >- } >- >- public String getArea(){ >- RangeAddress ra = new RangeAddress( getFirstColumn(),getFirstRow() + 1, getLastColumn(), getLastRow() + 1); >- String result = ra.getAddress(); >- >- return result; >- } >- >- public void setArea(String ref){ >- RangeAddress ra = new RangeAddress(ref); >- >- String from = ra.getFromCell(); >- String to = ra.getToCell(); >- >- setFirstColumn((short) (ra.getXPosition(from) -1)); >- setFirstRow((short) (ra.getYPosition(from) -1)); >- setLastColumn((short) (ra.getXPosition(to) -1)); >- setLastRow((short) (ra.getYPosition(to) -1)); >- >- } >- >- public String toFormulaString() >- { >- String result = getArea(); >- >- return result; >- } >- >- >-} >+ >+ >+/* ==================================================================== >+ >+ * The Apache Software License, Version 1.1 >+ >+ * >+ >+ * Copyright (c) 2002 The Apache Software Foundation. All rights >+ >+ * reserved. >+ >+ * >+ >+ * Redistribution and use in source and binary forms, with or without >+ >+ * modification, are permitted provided that the following conditions >+ >+ * are met: >+ >+ * >+ >+ * 1. Redistributions of source code must retain the above copyright >+ >+ * notice, this list of conditions and the following disclaimer. >+ >+ * >+ >+ * 2. Redistributions in binary form must reproduce the above copyright >+ >+ * notice, this list of conditions and the following disclaimer in >+ >+ * the documentation and/or other materials provided with the >+ >+ * distribution. >+ >+ * >+ >+ * 3. The end-user documentation included with the redistribution, >+ >+ * if any, must include the following acknowledgment: >+ >+ * "This product includes software developed by the >+ >+ * Apache Software Foundation (http://www.apache.org/)." >+ >+ * Alternately, this acknowledgment may appear in the software itself, >+ >+ * if and wherever such third-party acknowledgments normally appear. >+ >+ * >+ >+ * 4. The names "Apache" and "Apache Software Foundation" and >+ >+ * "Apache POI" must not be used to endorse or promote products >+ >+ * derived from this software without prior written permission. For >+ >+ * written permission, please contact apache@apache.org. >+ >+ * >+ >+ * 5. Products derived from this software may not be called "Apache", >+ >+ * "Apache POI", nor may "Apache" appear in their name, without >+ >+ * prior written permission of the Apache Software Foundation. >+ >+ * >+ >+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED >+ >+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES >+ >+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE >+ >+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR >+ >+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, >+ >+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT >+ >+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF >+ >+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND >+ >+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, >+ >+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT >+ >+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF >+ >+ * SUCH DAMAGE. >+ >+ * ==================================================================== >+ >+ * >+ >+ * This software consists of voluntary contributions made by many >+ >+ * individuals on behalf of the Apache Software Foundation. For more >+ >+ * information on the Apache Software Foundation, please see >+ >+ * <http://www.apache.org/>. >+ >+ */ >+ >+ >+ >+package org.apache.poi.hssf.record.formula; >+ >+ >+ >+import org.apache.poi.util.LittleEndian; >+ >+import org.apache.poi.hssf.util.RangeAddress; >+ >+ >+ >+/** >+ >+ * Title: Area 3D Ptg - 3D referecnce (Sheet + Area)<P> >+ >+ * Description: Defined a area in Extern Sheet. <P> >+ >+ * REFERENCE: <P> >+ >+ * @author Libin Roman (Vista Portal LDT. Developer) >+ >+ * @version 1.0-pre >+ >+ */ >+ >+ >+ >+public class Area3DPtg extends Ptg >+ >+{ >+ >+ public final static short sid = 0x3b; >+ >+ private final static int SIZE = 11; // 10 + 1 for Ptg >+ >+ private short field_1_index_extern_sheet; >+ >+ private short field_2_first_row; >+ >+ private short field_3_last_row; >+ >+ private short field_4_first_column; >+ >+ private short field_5_last_column; >+ >+ >+ >+ /** Creates new AreaPtg */ >+ >+ public Area3DPtg() { >+ >+ } >+ >+ >+ >+ >+ >+ public Area3DPtg(byte[] data, int offset) >+ >+ { >+ >+ offset++; >+ >+ field_1_index_extern_sheet = LittleEndian.getShort(data, 0 + offset); >+ >+ field_2_first_row = LittleEndian.getShort(data, 2 + offset); >+ >+ field_3_last_row = LittleEndian.getShort(data, 4 + offset); >+ >+ field_4_first_column = LittleEndian.getShort(data, 6 + offset); >+ >+ field_5_last_column = LittleEndian.getShort(data, 8 + offset); >+ >+ } >+ >+ protected Area3DPtg(String areaRef) { >+ //TODO! >+ } >+ >+ public String toString() >+ >+ { >+ >+ StringBuffer buffer = new StringBuffer(); >+ >+ >+ >+ buffer.append("AreaPtg\n"); >+ >+ buffer.append("Index to Extern Sheet = " + getExternSheetIndex()).append("\n"); >+ >+ buffer.append("firstRow = " + getFirstRow()).append("\n"); >+ >+ buffer.append("lastRow = " + getLastRow()).append("\n"); >+ >+ buffer.append("firstCol = " + getFirstColumn()).append("\n"); >+ >+ buffer.append("lastCol = " + getLastColumn()).append("\n"); >+ >+ buffer.append("firstColRowRel= " >+ >+ + isFirstColRowRelative()).append("\n"); >+ >+ buffer.append("lastColRowRel = " >+ >+ + isLastColRowRelative()).append("\n"); >+ >+ buffer.append("firstColRel = " + isFirstColRelative()).append("\n"); >+ >+ buffer.append("lastColRel = " + isLastColRelative()).append("\n"); >+ >+ return buffer.toString(); >+ >+ } >+ >+ >+ >+ public void writeBytes(byte [] array, int offset) >+ >+ { >+ >+ array[ 0 + offset ] = sid; >+ >+ LittleEndian.putShort(array, 1 + offset , getExternSheetIndex()); >+ >+ LittleEndian.putShort(array, 3 + offset , getFirstRow()); >+ >+ LittleEndian.putShort(array, 5 + offset , getLastRow()); >+ >+ LittleEndian.putShort(array, 7 + offset , getFirstColumnRaw()); >+ >+ LittleEndian.putShort(array, 9 + offset , getLastColumnRaw()); >+ >+ } >+ >+ >+ >+ public int getSize() >+ >+ { >+ >+ return SIZE; >+ >+ } >+ >+ >+ >+ public short getExternSheetIndex(){ >+ >+ return field_1_index_extern_sheet; >+ >+ } >+ >+ >+ >+ public void setExternSheetIndex(short index){ >+ >+ field_1_index_extern_sheet = index; >+ >+ } >+ >+ >+ >+ public short getFirstRow() >+ >+ { >+ >+ return field_2_first_row; >+ >+ } >+ >+ >+ >+ public void setFirstRow(short row) >+ >+ { >+ >+ field_2_first_row = row; >+ >+ } >+ >+ >+ >+ public short getLastRow() >+ >+ { >+ >+ return field_3_last_row; >+ >+ } >+ >+ >+ >+ public void setLastRow(short row) >+ >+ { >+ >+ field_3_last_row = row; >+ >+ } >+ >+ >+ >+ public short getFirstColumn() >+ >+ { >+ >+ return ( short ) (field_4_first_column & 0xFF); >+ >+ } >+ >+ >+ >+ public short getFirstColumnRaw() >+ >+ { >+ >+ return field_4_first_column; >+ >+ } >+ >+ >+ >+ public boolean isFirstColRowRelative() >+ >+ { >+ >+ return (((getFirstColumnRaw()) & 0x8000) == 0x8000); >+ >+ } >+ >+ >+ >+ public boolean isFirstColRelative() >+ >+ { >+ >+ return (((getFirstColumnRaw()) & 0x4000) == 0x4000); >+ >+ } >+ >+ >+ >+ public void setFirstColumn(short column) >+ >+ { >+ >+ field_4_first_column &= 0xFF00; >+ >+ field_4_first_column |= column & 0xFF; >+ >+ } >+ >+ >+ >+ public void setFirstColumnRaw(short column) >+ >+ { >+ >+ field_4_first_column = column; >+ >+ } >+ >+ >+ >+ public short getLastColumn() >+ >+ { >+ >+ return ( short ) (field_5_last_column & 0xFF); >+ >+ } >+ >+ >+ >+ public short getLastColumnRaw() >+ >+ { >+ >+ return field_5_last_column; >+ >+ } >+ >+ >+ >+ public boolean isLastColRowRelative() >+ >+ { >+ >+ return (((getLastColumnRaw()) & 0x8000) == 1); >+ >+ } >+ >+ >+ >+ public boolean isLastColRelative() >+ >+ { >+ >+ return (((getFirstColumnRaw()) & 0x4000) == 1); >+ >+ } >+ >+ >+ >+ public void setLastColumn(short column) >+ >+ { >+ >+ field_5_last_column &= 0xFF00; >+ >+ field_5_last_column |= column & 0xFF; >+ >+ } >+ >+ >+ >+ public void setLastColumnRaw(short column) >+ >+ { >+ >+ field_5_last_column = column; >+ >+ } >+ >+ >+ >+ public String getArea(){ >+ >+ RangeAddress ra = new RangeAddress( getFirstColumn(),getFirstRow() + 1, getLastColumn(), getLastRow() + 1); >+ >+ String result = ra.getAddress(); >+ >+ >+ >+ return result; >+ >+ } >+ >+ >+ >+ public void setArea(String ref){ >+ >+ RangeAddress ra = new RangeAddress(ref); >+ >+ >+ >+ String from = ra.getFromCell(); >+ >+ String to = ra.getToCell(); >+ >+ >+ >+ setFirstColumn((short) (ra.getXPosition(from) -1)); >+ >+ setFirstRow((short) (ra.getYPosition(from) -1)); >+ >+ setLastColumn((short) (ra.getXPosition(to) -1)); >+ >+ setLastRow((short) (ra.getYPosition(to) -1)); >+ >+ >+ >+ } >+ >+ >+ >+ public String toFormulaString() >+ >+ { >+ >+ String result = getArea(); >+ >+ >+ >+ return result; >+ >+ } >+ >+ >+ >+ >+ >+} >+ >Index: src/java/org/apache/poi/hssf/record/formula/AreaPtg.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/AreaPtg.java,v >retrieving revision 1.5 >diff -u -r1.5 AreaPtg.java >--- src/java/org/apache/poi/hssf/record/formula/AreaPtg.java 30 Apr 2002 04:43:17 -0000 1.5 >+++ src/java/org/apache/poi/hssf/record/formula/AreaPtg.java 30 Apr 2002 19:17:59 -0000 >@@ -85,13 +85,8 @@ > private BitField column = new BitField(0x3FFF); > > >- /** Creates new AreaPtg */ >- >- public AreaPtg() >- { >- } >- >- public AreaPtg(String arearef) { >+ >+ protected AreaPtg(String arearef) { > int[] xyxy = ReferenceUtil.getXYXYFromAreaRef(arearef); > setFirstRow((short)xyxy[0]); > setFirstColumn((short)xyxy[1]); >Index: src/java/org/apache/poi/hssf/record/formula/AttrPtg.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java,v >retrieving revision 1.4 >diff -u -r1.4 AttrPtg.java >--- src/java/org/apache/poi/hssf/record/formula/AttrPtg.java 30 Apr 2002 01:05:48 -0000 1.4 >+++ src/java/org/apache/poi/hssf/record/formula/AttrPtg.java 30 Apr 2002 19:18:00 -0000 >@@ -87,12 +87,9 @@ > private BitField baxcel = new BitField(0x20); > private BitField space = new BitField(0x40); > >- /** Creates new AttrPtg */ >- >- public AttrPtg() >- { >+ public AttrPtg() { > } >- >+ > public AttrPtg(byte [] data, int offset) > { > offset++; // adjust past id >@@ -199,11 +196,6 @@ > return "SUM()"; > } > >- public String toFormulaString(Ptg [] operands) >- { >- return "SUM(" + operands[ 0 ].toFormulaString() + ")"; >- } >- > public int getNumberOfOperands() > { > return 1; >@@ -218,8 +210,6 @@ > return "SUM(" + operands[ 0 ] + ")"; > } > >- public int getPrecedence() { >- return 1; >- } >+ > > } >Index: src/java/org/apache/poi/hssf/record/formula/ConcatPtg.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/ConcatPtg.java,v >retrieving revision 1.1 >diff -u -r1.1 ConcatPtg.java >--- src/java/org/apache/poi/hssf/record/formula/ConcatPtg.java 28 Apr 2002 16:42:21 -0000 1.1 >+++ src/java/org/apache/poi/hssf/record/formula/ConcatPtg.java 30 Apr 2002 19:18:01 -0000 >@@ -75,19 +75,13 @@ > > private final static String CONCAT = "&"; > >- /** Creates new ConcatPtg */ >- >- public ConcatPtg() >- { >- } >- > public ConcatPtg(byte [] data, int offset) > { > > // doesn't need anything > } > >- protected ConcatPtg(String formula, int offset) { >+ protected ConcatPtg() { > > } > >@@ -116,21 +110,7 @@ > return CONCAT; > } > >- public String toFormulaString(Ptg [] operands) >- { >- StringBuffer buffer = new StringBuffer(); >- >- buffer.append(operands[ 0 ].toFormulaString()); >- buffer.append(CONCAT); >- buffer.append(operands[ 1 ].toFormulaString()); >- return buffer.toString(); >- } >- >- public int getStringLength() { >- return 1; >- } >- >- >+ > public String toFormulaString(String[] operands) { > StringBuffer buffer = new StringBuffer(); > >Index: src/java/org/apache/poi/hssf/record/formula/DividePtg.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/DividePtg.java,v >retrieving revision 1.5 >diff -u -r1.5 DividePtg.java >--- src/java/org/apache/poi/hssf/record/formula/DividePtg.java 28 Apr 2002 15:55:37 -0000 1.5 >+++ src/java/org/apache/poi/hssf/record/formula/DividePtg.java 30 Apr 2002 19:18:02 -0000 >@@ -75,7 +75,7 @@ > > /** Creates new AddPtg */ > >- public DividePtg() >+ protected DividePtg() > { > } > >@@ -110,25 +110,11 @@ > return "/"; > } > >- public String toFormulaString(Ptg [] operands) >- { >- StringBuffer buffer = new StringBuffer(); >- >- buffer.append(operands[ 0 ].toFormulaString()); >- buffer.append("/"); >- buffer.append(operands[ 1 ].toFormulaString()); >- return buffer.toString(); >- } >- >- public int getStringLength() { >- return 1; >- } >- >- public String toFormulaString(String[] operands) { >+ public String toFormulaString(String[] operands) { > StringBuffer buffer = new StringBuffer(); > > buffer.append(operands[ 0 ]); >- buffer.append("/"); >+ buffer.append(toFormulaString()); > buffer.append(operands[ 1 ]); > return buffer.toString(); > } >Index: src/java/org/apache/poi/hssf/record/formula/ExpPtg.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/ExpPtg.java,v >retrieving revision 1.1.1.1 >diff -u -r1.1.1.1 ExpPtg.java >--- src/java/org/apache/poi/hssf/record/formula/ExpPtg.java 31 Jan 2002 02:23:44 -0000 1.1.1.1 >+++ src/java/org/apache/poi/hssf/record/formula/ExpPtg.java 30 Apr 2002 19:18:02 -0000 >@@ -73,7 +73,7 @@ > > /** Creates new ExpPtg */ > >- public ExpPtg() >+ protected ExpPtg() > { > } > >Index: src/java/org/apache/poi/hssf/record/formula/FormulaParser.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/FormulaParser.java,v >retrieving revision 1.13 >diff -u -r1.13 FormulaParser.java >--- src/java/org/apache/poi/hssf/record/formula/FormulaParser.java 30 Apr 2002 03:05:07 -0000 1.13 >+++ src/java/org/apache/poi/hssf/record/formula/FormulaParser.java 30 Apr 2002 19:18:23 -0000 >@@ -310,8 +310,6 @@ > if (IsDigit(Look)) number = number +"."+ GetNum(); //this also takes care of someone entering "1234." > tokens.add(new NumberPtg(number)); > } else { >- //IntPtg p = new IntPtg(GetNum()); // removing since a ptg should be able to create itself from parser results. >- //p.setValue(Short.parseShort(GetNum())); > tokens.add(new IntPtg(number)); //TODO:what if the number is too big to be a short? ..add factory to return Int or Number! > } > } >@@ -450,7 +448,6 @@ > > /** Static method to convert an array of Ptgs in RPN order > * to a human readable string format in infix mode >- * TODO - extra brackets might appear, but string will be semantically correct. > */ > public static String toFormulaString(Ptg[] ptgs) { > java.util.Stack stack = new java.util.Stack(); >@@ -468,7 +465,6 @@ > > } > String result = o.toFormulaString(operands); >- //if (! (o instanceof DummyFunctionPtg) ) result = "("+result+")" ; > stack.push(result); > } else { > stack.push(ptgs[i].toFormulaString()); >@@ -477,6 +473,9 @@ > return (String) stack.pop(); //TODO: catch stack underflow and throw parse exception. > } > >+ /** toString on the parser instance returns the RPN ordered list of tokens >+ * Useful for testing >+ */ > public String toString() { > StringBuffer buf = new StringBuffer(); > for (int i=0;i<tokens.size();i++) { >Index: src/java/org/apache/poi/hssf/record/formula/FunctionPtg.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/FunctionPtg.java,v >retrieving revision 1.5 >diff -u -r1.5 FunctionPtg.java >--- src/java/org/apache/poi/hssf/record/formula/FunctionPtg.java 30 Apr 2002 03:05:07 -0000 1.5 >+++ src/java/org/apache/poi/hssf/record/formula/FunctionPtg.java 30 Apr 2002 19:18:24 -0000 >@@ -16,12 +16,10 @@ > private byte field_1_num_args; > private short field_2_fnc_index; > >- //private String name; >- //private int numOperands; >- /** Creates new DummyFunctionPtg */ >- public FunctionPtg() { >- } >- >+ >+ /**Creates new function pointer from a byte array >+ * usually called while reading an excel file. >+ */ > public FunctionPtg(byte[] data, int offset) { > offset++; > field_1_num_args = data[ offset + 0 ]; >@@ -29,8 +27,10 @@ > > } > >- >- public FunctionPtg(String pName, byte pNumOperands) { >+ /** >+ * Create a function ptg from a string tokenised by the parser >+ */ >+ protected FunctionPtg(String pName, byte pNumOperands) { > field_1_num_args = pNumOperands; > field_2_fnc_index = lookupIndex(pName); > >@@ -64,20 +64,10 @@ > } > > public String toFormulaString() { >- return getName()+getNumberOfOperands(); >- } >- >- public String toFormulaString(Ptg[] operands) { >- StringBuffer buf = new StringBuffer(); >- buf.append(getName()+"("); >- for (int i=0;i<operands.length;i++) { >- buf.append(operands[i].toFormulaString()).append(','); >- } >- buf.append(")"); >- return buf.toString(); >+ return getName(); > } > >- public String toFormulaString(String[] operands) { >+ public String toFormulaString(String[] operands) { > StringBuffer buf = new StringBuffer(); > buf.append(getName()+"("); > if (operands.length >0) { >Index: src/java/org/apache/poi/hssf/record/formula/IntPtg.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/IntPtg.java,v >retrieving revision 1.5 >diff -u -r1.5 IntPtg.java >--- src/java/org/apache/poi/hssf/record/formula/IntPtg.java 30 Apr 2002 00:19:49 -0000 1.5 >+++ src/java/org/apache/poi/hssf/record/formula/IntPtg.java 30 Apr 2002 19:18:42 -0000 >@@ -77,23 +77,12 @@ > > private String val; > private int strlen = 0; >- /** Creates new IntPtg */ >- >- public IntPtg() >- { >- } >- >+ > public IntPtg(byte [] data, int offset) > { > setValue(LittleEndian.getShort(data, offset + 1)); > } > >- protected IntPtg(String formula, int offset) { >- val = parseString(formula, offset); >- if (val == null) throw new RuntimeException("WHOOAA there...thats got no int!"); >- strlen=val.length(); >- field_1_value = Short.parseShort(val); >- } > > // IntPtg should be able to create itself, shouldnt have to call setValue > protected IntPtg(String formulaToken) { >@@ -126,37 +115,4 @@ > return "" + getValue(); > } > >- private static String parseString(String formula, int pos) { >- String retval = null; >- while (pos < formula.length() && Character.isWhitespace(formula.charAt(pos))) { >- pos++; >- } >- >- if (pos < formula.length()) { >- if (Character.isDigit(formula.charAt(pos)) ) { >- int numpos = pos; >- >- while (numpos < formula.length() && Character.isDigit(formula.charAt(numpos))){ >- numpos++; >- } >- >- if (numpos == formula.length() || formula.charAt(numpos) != '.') { >- String numberstr = formula.substring(pos,numpos); >- try { >- int number = Short.parseShort(numberstr); >- retval = numberstr; >- } catch (NumberFormatException e) { >- retval = null; >- } >- } >- } >- } >- return retval; >- >- } >- >- >- public int getStringLength() { >- return strlen; >- } > } >Index: src/java/org/apache/poi/hssf/record/formula/MultiplyPtg.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/MultiplyPtg.java,v >retrieving revision 1.6 >diff -u -r1.6 MultiplyPtg.java >--- src/java/org/apache/poi/hssf/record/formula/MultiplyPtg.java 28 Apr 2002 16:33:57 -0000 1.6 >+++ src/java/org/apache/poi/hssf/record/formula/MultiplyPtg.java 30 Apr 2002 19:18:43 -0000 >@@ -77,7 +77,7 @@ > > /** Creates new AddPtg */ > >- public MultiplyPtg() >+ protected MultiplyPtg() > { > } > >@@ -87,11 +87,6 @@ > // doesn't need anything > } > >- protected MultiplyPtg(String formula, int offset) { >- >- } >- >- > public void writeBytes(byte [] array, int offset) > { > array[ offset + 0 ] = sid; >@@ -136,7 +131,7 @@ > StringBuffer buffer = new StringBuffer(); > > buffer.append(operands[ 0 ]); >- buffer.append("*"); >+ buffer.append(toFormulaString()); > buffer.append(operands[ 1 ]); > return buffer.toString(); > } >Index: src/java/org/apache/poi/hssf/record/formula/NamePtg.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/NamePtg.java,v >retrieving revision 1.1.1.1 >diff -u -r1.1.1.1 NamePtg.java >--- src/java/org/apache/poi/hssf/record/formula/NamePtg.java 31 Jan 2002 02:23:44 -0000 1.1.1.1 >+++ src/java/org/apache/poi/hssf/record/formula/NamePtg.java 30 Apr 2002 19:18:44 -0000 >@@ -78,8 +78,9 @@ > > /** Creates new NamePtg */ > >- public NamePtg() >+ protected NamePtg(String name) > { >+ //TODO > } > > /** Creates new NamePtg */ >Index: src/java/org/apache/poi/hssf/record/formula/NumberPtg.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java,v >retrieving revision 1.1 >diff -u -r1.1 NumberPtg.java >--- src/java/org/apache/poi/hssf/record/formula/NumberPtg.java 30 Apr 2002 00:18:29 -0000 1.1 >+++ src/java/org/apache/poi/hssf/record/formula/NumberPtg.java 30 Apr 2002 19:18:44 -0000 >@@ -57,8 +57,9 @@ > import org.apache.poi.util.LittleEndian; > > /** >- * Integer (short intger) >- * Stores a (java) short value in a formula >+ * Number >+ * Stores a floating point value in a formula >+ * value stored in a 8 byte field using IEEE notation > * @author Avik Sengupta > */ > >@@ -69,25 +70,29 @@ > public final static byte sid = 0x1f; > private double field_1_value; > >- /** Creates new NumberPtg */ >- >- public NumberPtg() >- { >- } >- >+ >+ /** Create a NumberPtg from a byte array read from disk */ > public NumberPtg(byte [] data, int offset) > { > setValue(LittleEndian.getDouble(data, offset + 1)); > } > >+ /** Create a NumberPtg from a string representation of the number >+ * Number format is not checked, it is expected to be validated in the parser >+ * that calls this method. >+ * @param value : String representation of a floating point number >+ */ > protected NumberPtg(String value) { > setValue(Double.parseDouble(value)); > } >+ >+ > public void setValue(double value) > { > field_1_value = value; > } >- >+ >+ > public double getValue() > { > return field_1_value; >@@ -108,11 +113,6 @@ > { > return "" + getValue(); > } >- >- >- //TODO: do we really need this method?? >- public int getStringLength() { >- return 1; >- } >+ > } > >Index: src/java/org/apache/poi/hssf/record/formula/OperationPtg.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/OperationPtg.java,v >retrieving revision 1.5 >diff -u -r1.5 OperationPtg.java >--- src/java/org/apache/poi/hssf/record/formula/OperationPtg.java 28 Apr 2002 15:55:37 -0000 1.5 >+++ src/java/org/apache/poi/hssf/record/formula/OperationPtg.java 30 Apr 2002 19:18:45 -0000 >@@ -75,11 +75,17 @@ > > public abstract int getType(); > >+ /** >+ * returns a string representation of the operations >+ * the length of the input array should equal the number returned by >+ * @see getNumberOfOperands >+ * >+ */ > public abstract String toFormulaString(String[] operands); > >+ /** >+ * The number of operands expected by the operations >+ */ > public abstract int getNumberOfOperands(); >- >- >- public abstract String toFormulaString(Ptg [] operands); > > } >Index: src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java,v >retrieving revision 1.5 >diff -u -r1.5 ParenthesisPtg.java >--- src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java 28 Apr 2002 16:40:37 -0000 1.5 >+++ src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java 30 Apr 2002 19:18:45 -0000 >@@ -72,7 +72,7 @@ > private final static int SIZE = 1; > public final static byte sid = 0x15; > >- public ParenthesisPtg() >+ protected ParenthesisPtg() > { > } > >@@ -82,10 +82,7 @@ > // doesn't need anything > } > >- protected ParenthesisPtg(String formula, int offset) { >- >- } >- >+ > > public void writeBytes(byte [] array, int offset) > { >@@ -112,11 +109,7 @@ > return "()"; > } > >- public String toFormulaString(Ptg [] operands) >- { >- return ""; >- } >- >+ > public String toFormulaString(String[] operands) { > return "("+operands[0]+")"; > } >Index: src/java/org/apache/poi/hssf/record/formula/PowerPtg.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/PowerPtg.java,v >retrieving revision 1.6 >diff -u -r1.6 PowerPtg.java >--- src/java/org/apache/poi/hssf/record/formula/PowerPtg.java 28 Apr 2002 15:55:37 -0000 1.6 >+++ src/java/org/apache/poi/hssf/record/formula/PowerPtg.java 30 Apr 2002 19:18:46 -0000 >@@ -75,7 +75,7 @@ > > /** Creates new AddPtg */ > >- public PowerPtg() >+ protected PowerPtg() > { > } > >@@ -110,24 +110,14 @@ > return "^"; > } > >- public String toFormulaString(Ptg [] operands) >- { >- StringBuffer buffer = new StringBuffer(); >- >- buffer.append(operands[ 0 ].toFormulaString()); >- buffer.append("^"); >- buffer.append(operands[ 1 ].toFormulaString()); >- >- return buffer.toString(); >- } >- >+ > > public String toFormulaString(String[] operands) { > StringBuffer buffer = new StringBuffer(); > > > buffer.append(operands[ 0 ]); >- buffer.append("^"); >+ buffer.append(toFormulaString()); > buffer.append(operands[ 1 ]); > return buffer.toString(); > } >Index: src/java/org/apache/poi/hssf/record/formula/Ptg.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/Ptg.java,v >retrieving revision 1.13 >diff -u -r1.13 Ptg.java >--- src/java/org/apache/poi/hssf/record/formula/Ptg.java 30 Apr 2002 03:05:07 -0000 1.13 >+++ src/java/org/apache/poi/hssf/record/formula/Ptg.java 30 Apr 2002 19:18:47 -0000 >@@ -77,7 +77,7 @@ > * @param infixPtgs List of ptgs in infix order > */ > >- /* DO NOI REMOVE >+ /* DO NOT REMOVE > *we keep this method in case we wish to change the way we parse > *It needs a getPrecedence in OperationsPtg > >@@ -287,15 +287,13 @@ > writeBytes(bytes, 0); > return bytes; > } >- >+ /** write this Ptg to a byte array*/ > public abstract void writeBytes(byte [] array, int offset); >- >- public abstract String toFormulaString(); >- >- public int getStringLength() { >- return 0; >- } > >+ /** >+ * return a string representation of this token alone >+ */ >+ public abstract String toFormulaString(); > /** > * dump a debug representation (hexdump) to a strnig > */ >Index: src/java/org/apache/poi/hssf/record/formula/ReferencePtg.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/ReferencePtg.java,v >retrieving revision 1.1 >diff -u -r1.1 ReferencePtg.java >--- src/java/org/apache/poi/hssf/record/formula/ReferencePtg.java 28 Apr 2002 22:22:47 -0000 1.1 >+++ src/java/org/apache/poi/hssf/record/formula/ReferencePtg.java 30 Apr 2002 19:18:48 -0000 >@@ -82,17 +82,13 @@ > private BitField rowRelative = new BitField(0x8000); > private BitField colRelative = new BitField(0x4000); > >- /** Creates new ValueReferencePtg */ >- >- public ReferencePtg() >- { >- } >+ > > /** > * Takes in a String represnetation of a cell reference and fills out the > * numeric fields. > */ >- public ReferencePtg(String cellref) { >+ protected ReferencePtg(String cellref) { > int[] xy = ReferenceUtil.getXYFromReference(cellref); > setRow((short)xy[0]); > setColumn((short)xy[1]); >Index: src/java/org/apache/poi/hssf/record/formula/SubtractPtg.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/SubtractPtg.java,v >retrieving revision 1.5 >diff -u -r1.5 SubtractPtg.java >--- src/java/org/apache/poi/hssf/record/formula/SubtractPtg.java 28 Apr 2002 15:55:37 -0000 1.5 >+++ src/java/org/apache/poi/hssf/record/formula/SubtractPtg.java 30 Apr 2002 19:18:48 -0000 >@@ -73,9 +73,7 @@ > public final static int SIZE = 1; > public final static byte sid = 0x04; > >- /** Creates new AddPtg */ >- >- public SubtractPtg() >+ protected SubtractPtg() > { > } > >@@ -110,21 +108,7 @@ > return "-"; > } > >- public String toFormulaString(Ptg [] operands) >- { >- StringBuffer buffer = new StringBuffer(); >- >- buffer.append(operands[ 0 ].toFormulaString()); >- buffer.append("-"); >- buffer.append(operands[ 1 ].toFormulaString()); >- return buffer.toString(); >- } >- >- >- public int getStringLength() { >- return 1; >- } >- >+ > public String toFormulaString(String[] operands) { > StringBuffer buffer = new StringBuffer(); > >Index: src/java/org/apache/poi/hssf/record/formula/ValueVariableFunctionPtg.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/ValueVariableFunctionPtg.java,v >retrieving revision 1.3 >diff -u -r1.3 ValueVariableFunctionPtg.java >--- src/java/org/apache/poi/hssf/record/formula/ValueVariableFunctionPtg.java 27 Apr 2002 14:07:53 -0000 1.3 >+++ src/java/org/apache/poi/hssf/record/formula/ValueVariableFunctionPtg.java 30 Apr 2002 19:18:49 -0000 >@@ -124,24 +124,13 @@ > return "NO IDEA YET VALUE VARIABLE"; > } > >- public String toFormulaString(Ptg [] operands) >- { >- return toFormulaString(); >- } >- >- >+ > public String toFormulaString(String[] operands) { > return toFormulaString(); > } > > >- public void manipulate(List source, List results, int pos) { >- } >- >- public int getPrecedence() { >- return 1; >- } >- >+ > > > } >Index: src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java,v >retrieving revision 1.9 >diff -u -r1.9 TestFormulas.java >--- src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java 30 Apr 2002 02:12:25 -0000 1.9 >+++ src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java 30 Apr 2002 19:18:53 -0000 >@@ -206,35 +206,80 @@ > * > */ > public void testFloat() >- throws Exception { >- String operator = "+"; >- short rownum = 0; >- File file = File.createTempFile("testFormulaFloat",".xls"); >- FileOutputStream out = new FileOutputStream(file); >- HSSFWorkbook wb = new HSSFWorkbook(); >- HSSFSheet s = wb.createSheet(); >- HSSFRow r = null; >- HSSFCell c = null; >- >- for (short x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2)) { >- r = s.createRow((short) x); >- >- for (short y = 1; y < 256 && y > 0; y++) { >- >- c = r.createCell((short) y); >- c.setCellFormula("" + (100*x)+"."+y + operator + (10000*y) + >- "."+x); >+ throws Exception { >+ floatTest("*"); >+ floatTest("/"); >+ } > >- >- } >+ private void floatTest(String operator) >+ throws Exception { >+ short rownum = 0; >+ File file = File.createTempFile("testFormulaFloat",".xls"); >+ FileOutputStream out = new FileOutputStream(file); >+ HSSFWorkbook wb = new HSSFWorkbook(); >+ HSSFSheet s = wb.createSheet(); >+ HSSFRow r = null; >+ HSSFCell c = null; >+ >+ //get our minimum values >+ >+ r = s.createRow((short)0); >+ c = r.createCell((short)1); >+ c.setCellFormula(""+Float.MIN_VALUE + operator + Float.MIN_VALUE); >+ >+ for (short x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2) ) { >+ r = s.createRow((short) x); >+ >+ for (short y = 1; y < 256 && y > 0; y= (short) (y +2)) { >+ >+ c = r.createCell((short) y); >+ c.setCellFormula("" + x+"."+y + operator + y +"."+x); >+ >+ >+ } >+ } >+ if (s.getLastRowNum() < Short.MAX_VALUE) { >+ r = s.createRow((short)0); >+ c = r.createCell((short)0); >+ c.setCellFormula("" + Float.MAX_VALUE + operator + Float.MAX_VALUE); >+ } >+ wb.write(out); >+ out.close(); >+ assertTrue("file exists",file.exists()); >+ out=null;wb=null; //otherwise we get out of memory error! >+ floatVerify(operator,file); >+ >+ } >+ >+ private void floatVerify(String operator, File file) >+ throws Exception { >+ short rownum = 0; >+ >+ FileInputStream in = new FileInputStream(file); >+ HSSFWorkbook wb = new HSSFWorkbook(in); >+ HSSFSheet s = wb.getSheetAt(0); >+ HSSFRow r = null; >+ HSSFCell c = null; >+ >+ // dont know how to check correct result .. for the moment, we just verify that the file can be read. >+ >+ for (short x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2)) { >+ r = s.getRow((short) x); >+ >+ for (short y = 1; y < 256 && y > 0; y=(short)(y+2)) { >+ >+ c = r.getCell((short) y); >+ assertTrue("got a formula",c.getCellFormula()!=null); >+ >+ assertTrue("loop Formula is as expected "+x+"."+y+operator+y+"."+x+"!="+c.getCellFormula(),( >+ (""+x+"."+y+operator+y+"."+x).equals(c.getCellFormula()) )); >+ > } >- >- wb.write(out); >- out.close(); >- assertTrue("file exists",file.exists()); >- >- > } >+ >+ in.close(); >+ assertTrue("file exists",file.exists()); >+ } > > public void testAreaSum() > throws Exception {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 8665
: 1745