PR 13292, size of FuncPtg

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353087 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Avik Sengupta 2003-05-06 15:30:52 +00:00
parent e35ddf54f2
commit a1d25d01ea
4 changed files with 49 additions and 15 deletions

View File

@ -797,7 +797,9 @@ end;
} }
return (String) stack.pop(); //TODO: catch stack underflow and throw parse exception. return (String) stack.pop(); //TODO: catch stack underflow and throw parse exception.
} }
/** Create a tree representation of the RPN token array
*used to run the class(RVA) change algo
*/
private Node createTree() { private Node createTree() {
java.util.Stack stack = new java.util.Stack(); java.util.Stack stack = new java.util.Stack();
int numPtgs = tokens.size(); int numPtgs = tokens.size();
@ -837,7 +839,8 @@ end;
return buf.toString(); return buf.toString();
} }
} }
/** Private helper class, used to create a tree representation of the formula*/
class Node { class Node {
private Ptg value=null; private Ptg value=null;
private Node[] children=new Node[0]; private Node[] children=new Node[0];

View File

@ -69,7 +69,7 @@ public abstract class AbstractFunctionPtg extends OperationPtg {
//constant used allow a ptgAttr to be mapped properly for its functionPtg //constant used allow a ptgAttr to be mapped properly for its functionPtg
public static final String ATTR_NAME = "specialflag"; public static final String ATTR_NAME = "specialflag";
private final static int SIZE = 4;
private static BinaryTree map = produceHash(); private static BinaryTree map = produceHash();
protected static Object[][] functionData = produceFunctionData(); protected static Object[][] functionData = produceFunctionData();
@ -129,14 +129,13 @@ public abstract class AbstractFunctionPtg extends OperationPtg {
} }
public abstract void writeBytes(byte[] array, int offset); public abstract void writeBytes(byte[] array, int offset);
public abstract int getSize();
public int getSize() {
return SIZE;
}
private String lookupName(short index) { protected String lookupName(short index) {
return ((String)map.get(new Integer(index))); return ((String)map.get(new Integer(index)));
} }

View File

@ -2,13 +2,14 @@ package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
/** /**
* * @author aviks
* @author Jason Height (jheight at chariot dot net dot au) * @author Jason Height (jheight at chariot dot net dot au)
* @author Danny Mui (dmui at apache dot org) (Leftover handling) * @author Danny Mui (dmui at apache dot org) (Leftover handling)
*/ */
public class FuncPtg extends AbstractFunctionPtg{ public class FuncPtg extends AbstractFunctionPtg{
public final static byte sid = 0x21; public final static byte sid = 0x21;
public final static int SIZE = 3;
private int numParams=0; private int numParams=0;
/** /**
@ -17,8 +18,8 @@ public class FuncPtg extends AbstractFunctionPtg{
* <p> * <p>
* If the leftovers are removed, a prompt "Warning: Data may have been lost occurs in Excel" * If the leftovers are removed, a prompt "Warning: Data may have been lost occurs in Excel"
*/ */
protected byte[] leftOvers = null; //protected byte[] leftOvers = null;
private FuncPtg() { private FuncPtg() {
//Required for clone methods //Required for clone methods
} }
@ -31,12 +32,12 @@ public class FuncPtg extends AbstractFunctionPtg{
//field_1_num_args = data[ offset + 0 ]; //field_1_num_args = data[ offset + 0 ];
field_2_fnc_index = LittleEndian.getShort(data,offset + 0 ); field_2_fnc_index = LittleEndian.getShort(data,offset + 0 );
/*
if (data.length - offset > 2) { //save left overs if there are any if (data.length - offset > 2) { //save left overs if there are any
leftOvers = new byte[2]; leftOvers = new byte[2];
System.arraycopy(data, offset+1, leftOvers, 0, leftOvers.length); System.arraycopy(data, offset+1, leftOvers, 0, leftOvers.length);
} }
*/
try { try {
numParams = ( (Integer)functionData[field_2_fnc_index][2]).intValue(); numParams = ( (Integer)functionData[field_2_fnc_index][2]).intValue();
} catch (NullPointerException npe) { } catch (NullPointerException npe) {
@ -49,9 +50,9 @@ public class FuncPtg extends AbstractFunctionPtg{
array[offset+0]= (byte) (sid + ptgClass); array[offset+0]= (byte) (sid + ptgClass);
//array[offset+1]=field_1_num_args; //array[offset+1]=field_1_num_args;
LittleEndian.putShort(array,offset+1,field_2_fnc_index); LittleEndian.putShort(array,offset+1,field_2_fnc_index);
if (leftOvers != null) { /**if (leftOvers != null) {
System.arraycopy(leftOvers, 0, array, offset+2, leftOvers.length); System.arraycopy(leftOvers, 0, array, offset+2, leftOvers.length);
} }**/
} }
public int getNumberOfOperands() { public int getNumberOfOperands() {
@ -60,8 +61,23 @@ public class FuncPtg extends AbstractFunctionPtg{
public Object clone() { public Object clone() {
FuncPtg ptg = new FuncPtg(); FuncPtg ptg = new FuncPtg();
ptg.field_1_num_args = field_1_num_args; //ptg.field_1_num_args = field_1_num_args;
ptg.field_2_fnc_index = field_2_fnc_index; ptg.field_2_fnc_index = field_2_fnc_index;
return ptg; return ptg;
} }
public int getSize() {
return SIZE;
}
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer
.append("<FunctionPtg>").append("\n")
.append(" numArgs(internal)=").append(this.numParams).append("\n")
.append(" name =").append(lookupName(field_2_fnc_index)).append("\n")
.append(" field_2_fnc_index=").append(field_2_fnc_index).append("\n")
.append("</FunctionPtg>");
return buffer.toString();
}
} }

View File

@ -8,6 +8,7 @@ import org.apache.poi.util.LittleEndian;
public class FuncVarPtg extends AbstractFunctionPtg{ public class FuncVarPtg extends AbstractFunctionPtg{
public final static byte sid = 0x22; public final static byte sid = 0x22;
private final static int SIZE = 4;
private FuncVarPtg() { private FuncVarPtg() {
//Required for clone methods //Required for clone methods
@ -53,6 +54,21 @@ public class FuncVarPtg extends AbstractFunctionPtg{
ptg.field_2_fnc_index = field_2_fnc_index; ptg.field_2_fnc_index = field_2_fnc_index;
return ptg; return ptg;
} }
public int getSize() {
return SIZE;
}
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer
.append("<FunctionVarPtg>").append("\n")
.append(" field_1_num_args=").append(field_1_num_args).append("\n")
.append(" name =").append(lookupName(field_2_fnc_index)).append("\n")
.append(" field_2_fnc_index=").append(field_2_fnc_index).append("\n")
.append("</FunctionPtg>");
return buffer.toString();
}
} }