You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2008/06/21 14:03:49 UTC
svn commit: r670186 [3/7] - in /poi/tags/REL_3_1_FINAL: ./ legal/
src/documentation/content/xdocs/ src/examples/src/org/apache/poi/hslf/
src/examples/src/org/apache/poi/hslf/usermodel/
src/examples/src/org/apache/poi/hslf/usermodel/examples/ src/java/o...
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/GreaterThanPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/GreaterThanPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/GreaterThanPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/GreaterThanPtg.java Sat Jun 21 05:03:44 2008
@@ -15,94 +15,36 @@
limitations under the License.
==================================================================== */
-
-/*
- * GreaterThanPtg.java
- *
- * Created on January 23, 2003, 9:47 AM
- */
package org.apache.poi.hssf.record.formula;
-import java.util.List;
-
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.record.RecordInputStream;
/**
* Greater than operator PTG ">"
* @author Cameron Riley (criley at ekmail.com)
*/
-public class GreaterThanPtg
- extends OperationPtg
-{
- public final static int SIZE = 1;
+public final class GreaterThanPtg extends ValueOperatorPtg {
public final static byte sid = 0x0D;
private final static String GREATERTHAN = ">";
- /**
- * Constructor. Creates new GreaterThanPtg
- */
- public GreaterThanPtg()
- {
- //deliberately empty
- }
+ public static final ValueOperatorPtg instance = new GreaterThanPtg();
- /**
- * Constructor. Create a new GreaterThanPtg.
- * @param in the RecordInputstream to read the record from
- */
- public GreaterThanPtg(RecordInputStream in)
- {
- //deliberately empty
+ private GreaterThanPtg() {
+ // enforce singleton
}
- /**
- * Write the sid to an array
- * @param array the array of bytes to write the sid to
- * @param offset the offset to add the sid to
- */
- public void writeBytes(byte [] array, int offset)
- {
- array[ offset + 0 ] = sid;
- }
-
- /**
- * Get the size of the sid
- * @return int the size of the sid in terms of byte additions to an array
- */
- public int getSize()
- {
- return SIZE;
- }
-
- /**
- * Get the type of PTG for Greater Than
- * @return int the identifier for the type
- */
- public int getType()
- {
- return TYPE_BINARY;
+ protected byte getSid() {
+ return sid;
}
/**
* Get the number of operands for the Less than operator
* @return int the number of operands
*/
- public int getNumberOfOperands()
- {
+ public int getNumberOfOperands() {
return 2;
}
/**
- * Implementation of method from Ptg
- * @param book the Sheet References
- */
- public String toFormulaString(HSSFWorkbook book)
- {
- return this.GREATERTHAN;
- }
-
- /**
* Implementation of method from OperationsPtg
* @param operands a String array of operands
* @return String the Formula as a String
@@ -112,26 +54,8 @@
StringBuffer buffer = new StringBuffer();
buffer.append(operands[ 0 ]);
- buffer.append(this.GREATERTHAN);
+ buffer.append(GREATERTHAN);
buffer.append(operands[ 1 ]);
return buffer.toString();
}
-
- /**
- * Get the default operands class value
- * @return byte the Ptg Class Value as a byte from the Ptg Parent object
- */
- public byte getDefaultOperandClass()
- {
- return Ptg.CLASS_VALUE;
- }
-
- /**
- * Implementation of clone method from Object
- * @return Object a clone of this class as an Object
- */
- public Object clone()
- {
- return new GreaterThanPtg();
- }
}
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/IntPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/IntPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/IntPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/IntPtg.java Sat Jun 21 05:03:44 2008
@@ -27,7 +27,7 @@
* @author Andrew C. Oliver (acoliver at apache dot org)
* @author Jason Height (jheight at chariot dot net dot au)
*/
-public final class IntPtg extends Ptg {
+public final class IntPtg extends ScalarConstantPtg {
// 16 bit unsigned integer
private static final int MIN_VALUE = 0x0000;
private static final int MAX_VALUE = 0xFFFF;
@@ -43,13 +43,12 @@
public final static int SIZE = 3;
public final static byte sid = 0x1e;
- private int field_1_value;
+ private final int field_1_value;
public IntPtg(RecordInputStream in) {
this(in.readUShort());
}
-
public IntPtg(int value) {
if(!isInRange(value)) {
throw new IllegalArgumentException("value is out of range: " + value);
@@ -61,7 +60,6 @@
return field_1_value;
}
-
public void writeBytes(byte [] array, int offset)
{
array[ offset + 0 ] = sid;
@@ -75,13 +73,7 @@
public String toFormulaString(HSSFWorkbook book) {
return String.valueOf(getValue());
}
- public byte getDefaultOperandClass() {
- return Ptg.CLASS_VALUE;
- }
- public Object clone() {
- return new IntPtg(field_1_value);
- }
public String toString() {
StringBuffer sb = new StringBuffer(64);
sb.append(getClass().getName()).append(" [");
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/IntersectionPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/IntersectionPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/IntersectionPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/IntersectionPtg.java Sat Jun 21 05:03:44 2008
@@ -18,26 +18,23 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.record.RecordInputStream;
/**
* @author Daniel Noll (daniel at nuix dot com dot au)
*/
-public class IntersectionPtg extends OperationPtg
-{
+public final class IntersectionPtg extends OperationPtg {
public final static byte sid = 0x0f;
+ public static final OperationPtg instance = new IntersectionPtg();
- public IntersectionPtg()
- {
+ private IntersectionPtg() {
+ // enforce singleton
}
- public IntersectionPtg(RecordInputStream in)
- {
- // doesn't need anything
+ public final boolean isBaseToken() {
+ return true;
}
-
public int getSize()
{
return 1;
@@ -48,16 +45,6 @@
array[ offset + 0 ] = sid;
}
- public Object clone()
- {
- return new IntersectionPtg();
- }
-
- public int getType()
- {
- return TYPE_BINARY;
- }
-
/** Implementation of method from Ptg */
public String toFormulaString(HSSFWorkbook book)
{
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/LessEqualPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/LessEqualPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/LessEqualPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/LessEqualPtg.java Sat Jun 21 05:03:44 2008
@@ -16,12 +16,9 @@
limitations under the License.
==================================================================== */
-
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.record.RecordInputStream;
/**
@@ -29,61 +26,28 @@
*
* @author fred at stsci dot edu
*/
-public class LessEqualPtg
- extends OperationPtg
-{
- public final static int SIZE = 1;
+public final class LessEqualPtg extends ValueOperatorPtg {
public final static byte sid = 0x0a;
- /**
- * Creates new LessEqualPtg
- */
- public LessEqualPtg()
- {
-
- }
-
- public LessEqualPtg( RecordInputStream in )
- {
- // doesn't need anything
- }
-
- public void writeBytes( byte[] array, int offset )
- {
- array[offset + 0] = sid;
- }
+ public static final ValueOperatorPtg instance = new LessEqualPtg();
- public int getSize()
- {
- return SIZE;
+ private LessEqualPtg() {
+ // enforce singleton
}
-
- public int getType()
- {
- return TYPE_BINARY;
+
+ protected byte getSid() {
+ return sid;
}
- public int getNumberOfOperands()
- {
+ public int getNumberOfOperands() {
return 2;
}
- public String toFormulaString( HSSFWorkbook book )
- {
- return "<=";
- }
-
- public String toFormulaString( String[] operands )
- {
+ public String toFormulaString(String[] operands) {
StringBuffer buffer = new StringBuffer();
buffer.append( operands[0] );
- buffer.append( toFormulaString( (HSSFWorkbook) null ) );
+ buffer.append("<=");
buffer.append( operands[1] );
return buffer.toString();
}
-
- public Object clone()
- {
- return new LessEqualPtg();
- }
}
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/LessThanPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/LessThanPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/LessThanPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/LessThanPtg.java Sat Jun 21 05:03:44 2008
@@ -15,103 +15,40 @@
limitations under the License.
==================================================================== */
-
-/*
- * LessThanPtg.java
- *
- * Created on January 23, 2003, 9:47 AM
- */
package org.apache.poi.hssf.record.formula;
-//JDK
-import java.util.List;
-
-//POI
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.record.RecordInputStream;
-
/**
* Less than operator PTG "<". The SID is taken from the
* Openoffice.orgs Documentation of the Excel File Format,
* Table 3.5.7
* @author Cameron Riley (criley at ekmail.com)
*/
-public class LessThanPtg
- extends OperationPtg
-{
- /** the size of the Ptg */
- public final static int SIZE = 1;
-
+public final class LessThanPtg extends ValueOperatorPtg {
/** the sid for the less than operator as hex */
public final static byte sid = 0x09;
/** identifier for LESS THAN char */
private final static String LESSTHAN = "<";
- /**
- * Constructor. Creates new LessThanPtg
- */
- public LessThanPtg()
- {
- //deliberately empty
- }
+ public static final ValueOperatorPtg instance = new LessThanPtg();
- /**
- * Constructor. Create a new LessThanPtg.
- * @param in the RecordInputstream to read the record from
- */
- public LessThanPtg(RecordInputStream in)
- {
- //deliberately empty
+ private LessThanPtg() {
+ // enforce singleton
}
- /**
- * Write the sid to an array
- * @param array the array of bytes to write the sid to
- * @param offset the offset to add the sid to
- */
- public void writeBytes(byte[] array, int offset)
- {
- array[ offset + 0 ] = sid;
- }
-
- /**
- * Get the size of the sid
- * @return int the size of the sid in terms of byte additions to an array
- */
- public int getSize()
- {
- return SIZE;
- }
-
- /**
- * Get the type of PTG for Less Than
- * @return int the identifier for the type
- */
- public int getType()
- {
- return TYPE_BINARY;
+ protected byte getSid() {
+ return sid;
}
/**
* Get the number of operands for the Less than operator
* @return int the number of operands
*/
- public int getNumberOfOperands()
- {
+ public int getNumberOfOperands() {
return 2;
}
- /**
- * Implementation of method from Ptg
- * @param book the Sheet References
- */
- public String toFormulaString(HSSFWorkbook book)
- {
- return this.LESSTHAN;
- }
-
- /**
+ /**
* Implementation of method from OperationsPtg
* @param operands a String array of operands
* @return String the Formula as a String
@@ -120,27 +57,8 @@
{
StringBuffer buffer = new StringBuffer();
buffer.append(operands[ 0 ]);
- buffer.append(this.LESSTHAN);
+ buffer.append(LESSTHAN);
buffer.append(operands[ 1 ]);
return buffer.toString();
}
-
- /**
- * Get the default operands class value
- * @return byte the Ptg Class Value as a byte from the Ptg Parent object
- */
- public byte getDefaultOperandClass()
- {
- return Ptg.CLASS_VALUE;
- }
-
- /**
- * Implementation of clone method from Object
- * @return Object a clone of this class as an Object
- */
- public Object clone()
- {
- return new LessThanPtg();
- }
-
}
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/MemAreaPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/MemAreaPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/MemAreaPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/MemAreaPtg.java Sat Jun 21 05:03:44 2008
@@ -1,4 +1,3 @@
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -16,12 +15,6 @@
limitations under the License.
==================================================================== */
-
-/*
- * MemAreaPtg.java
- *
- * Created on November 21, 2001, 8:46 AM
- */
package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
@@ -31,9 +24,7 @@
/**
* @author Daniel Noll (daniel at nuix dot com dot au)
*/
-public class MemAreaPtg
- extends Ptg
-{
+public class MemAreaPtg extends OperandPtg {
public final static short sid = 0x26;
private final static int SIZE = 7;
private int field_1_reserved;
@@ -73,7 +64,7 @@
public void writeBytes(byte [] array, int offset)
{
- array[offset] = (byte) (sid + ptgClass);
+ array[offset] = (byte) (sid + getPtgClass());
LittleEndian.putInt(array, offset + 1, field_1_reserved);
LittleEndian.putShort(array, offset + 5, field_2_subex_len);
}
@@ -88,12 +79,7 @@
return ""; // TODO: Not sure how to format this. -- DN
}
- public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
-
- public Object clone() {
- MemAreaPtg ptg = new MemAreaPtg();
- ptg.field_1_reserved = field_1_reserved;
- ptg.field_2_subex_len = field_2_subex_len;
- return ptg;
+ public byte getDefaultOperandClass() {
+ return Ptg.CLASS_VALUE;
}
}
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/MemErrPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/MemErrPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/MemErrPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/MemErrPtg.java Sat Jun 21 05:03:44 2008
@@ -1,4 +1,3 @@
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -16,17 +15,10 @@
limitations under the License.
==================================================================== */
-
-/*
- * MemErrPtg.java
- *
- * Created on November 21, 2001, 8:46 AM
- */
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.util.LittleEndian;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
*
@@ -35,9 +27,7 @@
* @author Daniel Noll (daniel at nuix dot com dot au)
*/
-public class MemErrPtg
- extends MemAreaPtg
-{
+public final class MemErrPtg extends MemAreaPtg {
public final static short sid = 0x27;
/** Creates new MemErrPtg */
@@ -46,26 +36,17 @@
{
}
- public MemErrPtg(RecordInputStream in)
- {
+ public MemErrPtg(RecordInputStream in) {
super(in);
}
- public void writeBytes(byte [] array, int offset)
- {
+ public void writeBytes(byte [] array, int offset) {
super.writeBytes(array, offset);
- array[offset] = (byte) (sid + ptgClass);
+ array[offset] = (byte) (sid + getPtgClass());
}
public String toFormulaString(HSSFWorkbook book)
{
return "ERR#";
}
-
- public Object clone() {
- MemErrPtg ptg = new MemErrPtg();
- ptg.setReserved(getReserved());
- ptg.setSubexpressionLength(getSubexpressionLength());
- return ptg;
- }
}
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/MemFuncPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/MemFuncPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/MemFuncPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/MemFuncPtg.java Sat Jun 21 05:03:44 2008
@@ -15,12 +15,6 @@
limitations under the License.
==================================================================== */
-
-/*
- * Ptg.java
- *
- * Created on October 28, 2001, 6:30 PM
- */
package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
@@ -30,26 +24,23 @@
/**
* @author Glen Stampoultzis (glens at apache.org)
*/
-public class MemFuncPtg extends ControlPtg
-{
+public final class MemFuncPtg extends OperandPtg {
public final static byte sid = 0x29;
- private short field_1_len_ref_subexpression = 0;
-
- public MemFuncPtg()
- {
- //Required for clone methods
- }
+ private final int field_1_len_ref_subexpression;
/**Creates new function pointer from a byte array
* usually called while reading an excel file.
*/
- public MemFuncPtg( RecordInputStream in )
- {
- field_1_len_ref_subexpression = in.readShort();
+ public MemFuncPtg(RecordInputStream in) {
+ this(in.readUShort());
}
- public int getSize()
+ public MemFuncPtg(int subExprLen) {
+ field_1_len_ref_subexpression = subExprLen;
+ }
+
+ public int getSize()
{
return 3;
}
@@ -57,7 +48,7 @@
public void writeBytes( byte[] array, int offset )
{
array[offset + 0] = sid ;
- LittleEndian.putShort( array, offset + 1, (short)field_1_len_ref_subexpression );
+ LittleEndian.putUShort( array, offset + 1, field_1_len_ref_subexpression );
}
public String toFormulaString(HSSFWorkbook book)
@@ -67,7 +58,7 @@
public byte getDefaultOperandClass()
{
- return 0;
+ return Ptg.CLASS_REF;
}
public int getNumberOfOperands()
@@ -75,21 +66,8 @@
return field_1_len_ref_subexpression;
}
- public Object clone()
- {
- MemFuncPtg ptg = new MemFuncPtg();
- ptg.field_1_len_ref_subexpression = this.field_1_len_ref_subexpression;
- return ptg;
- }
-
public int getLenRefSubexpression()
{
return field_1_len_ref_subexpression;
}
-
- public void setLenRefSubexpression(int len)
- {
- field_1_len_ref_subexpression = (short)len;
- }
-
}
\ No newline at end of file
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/MissingArgPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/MissingArgPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/MissingArgPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/MissingArgPtg.java Sat Jun 21 05:03:44 2008
@@ -18,7 +18,6 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.record.RecordInputStream;
/**
* Missing Function Arguments
@@ -26,23 +25,15 @@
* Avik Sengupta <avik at apache.org>
* @author Jason Height (jheight at chariot dot net dot au)
*/
-public class MissingArgPtg
- extends Ptg
-{
+public final class MissingArgPtg extends ScalarConstantPtg {
private final static int SIZE = 1;
public final static byte sid = 0x16;
- public MissingArgPtg()
+ public static final Ptg instance = new MissingArgPtg();
+ private MissingArgPtg()
{
}
-
- public MissingArgPtg(RecordInputStream in)
- {
- // doesn't need anything
- }
-
-
public void writeBytes(byte [] array, int offset)
{
@@ -53,17 +44,9 @@
{
return SIZE;
}
-
public String toFormulaString(HSSFWorkbook book)
{
return " ";
}
-
- public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
-
- public Object clone() {
- return new MissingArgPtg();
- }
-
}
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/MultiplyPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/MultiplyPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/MultiplyPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/MultiplyPtg.java Sat Jun 21 05:03:44 2008
@@ -14,85 +14,37 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.record.RecordInputStream;
+package org.apache.poi.hssf.record.formula;
/**
* Implements the standard mathmatical multiplication - *
* @author Andrew C. Oliver (acoliver at apache dot org)
* @author Jason Height (jheight at chariot dot net dot au)
*/
-
-public class MultiplyPtg
- extends OperationPtg
-{
- public final static int SIZE = 1;
+public final class MultiplyPtg extends ValueOperatorPtg {
public final static byte sid = 0x05;
- /** Creates new AddPtg */
-
- public MultiplyPtg()
- {
- }
-
- public MultiplyPtg(RecordInputStream in)
- {
+ public static final ValueOperatorPtg instance = new MultiplyPtg();
- // doesn't need anything
+ private MultiplyPtg() {
+ // enforce singleton
}
- public void writeBytes(byte [] array, int offset)
- {
- array[ offset + 0 ] = sid;
+ protected byte getSid() {
+ return sid;
}
- public int getSize()
- {
- return SIZE;
- }
-
- public int getType()
- {
- return TYPE_BINARY;
- }
-
- public int getNumberOfOperands()
- {
+ public int getNumberOfOperands() {
return 2;
}
-
- public int getStringLength() {
- return 1;
- }
-
-
- public String toFormulaString(HSSFWorkbook book)
- {
- return "*";
- }
-
- public String toFormulaString(Ptg [] operands)
- {
- StringBuffer buffer = new StringBuffer();
-
- buffer.append(operands[ 0 ].toFormulaString((HSSFWorkbook)null));
- buffer.append("*");
- buffer.append(operands[ 1 ].toFormulaString((HSSFWorkbook)null));
- return buffer.toString();
- }
public String toFormulaString(String[] operands) {
StringBuffer buffer = new StringBuffer();
buffer.append(operands[ 0 ]);
- buffer.append(toFormulaString((HSSFWorkbook)null));
+ buffer.append("*");
buffer.append(operands[ 1 ]);
return buffer.toString();
}
-
- public Object clone() {
- return new MultiplyPtg();
- }
}
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/NamePtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/NamePtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/NamePtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/NamePtg.java Sat Jun 21 05:03:44 2008
@@ -17,32 +17,22 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.usermodel.HSSFName;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.record.NameRecord;
-import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.util.LittleEndian;
/**
*
* @author andy
* @author Jason Height (jheight at chariot dot net dot au)
*/
-
-public class NamePtg
- extends Ptg
-{
+public final class NamePtg extends OperandPtg {
public final static short sid = 0x23;
private final static int SIZE = 5;
/** one-based index to defined name record */
private short field_1_label_index;
private short field_2_zero; // reserved must be 0
- boolean xtra=false;
-
-
- private NamePtg() {
- //Required for clone methods
- }
/**
* Creates new NamePtg and sets its name index to that of the corresponding defined name record
@@ -72,12 +62,9 @@
/** Creates new NamePtg */
- public NamePtg(RecordInputStream in)
- {
- //field_1_ixti = LittleEndian.getShort(data, offset);
+ public NamePtg(RecordInputStream in) {
field_1_label_index = in.readShort();
field_2_zero = in.readShort();
- //if (data[offset+6]==0) xtra=true;
}
/**
@@ -87,15 +74,13 @@
return field_1_label_index-1; // convert to zero based
}
- public void writeBytes(byte [] array, int offset)
- {
- array[offset+0]= (byte) (sid + ptgClass);
+ public void writeBytes(byte [] array, int offset) {
+ array[offset+0]= (byte) (sid + getPtgClass());
LittleEndian.putShort(array,offset+1,field_1_label_index);
LittleEndian.putShort(array,offset+3, field_2_zero);
}
- public int getSize()
- {
+ public int getSize() {
return SIZE;
}
@@ -104,12 +89,7 @@
return book.getNameName(field_1_label_index - 1);
}
- public byte getDefaultOperandClass() {return Ptg.CLASS_REF;}
-
- public Object clone() {
- NamePtg ptg = new NamePtg();
- ptg.field_1_label_index = field_1_label_index;
- ptg.field_2_zero = field_2_zero;
- return ptg;
- }
+ public byte getDefaultOperandClass() {
+ return Ptg.CLASS_REF;
+ }
}
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/NameXPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/NameXPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/NameXPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/NameXPtg.java Sat Jun 21 05:03:44 2008
@@ -25,7 +25,7 @@
*
* @author aviks
*/
-public final class NameXPtg extends Ptg {
+public final class NameXPtg extends OperandPtg {
public final static short sid = 0x39;
private final static int SIZE = 7;
private short field_1_ixals; // index to REF entry in externsheet record
@@ -33,31 +33,20 @@
private short field_3_reserved; // reserved must be 0
- private NameXPtg() {
- //Required for clone methods
- }
-
- /** Creates new NamePtg */
-
- public NameXPtg(RecordInputStream in)
- {
+ public NameXPtg(RecordInputStream in) {
field_1_ixals = in.readShort();
field_2_ilbl = in.readShort();
field_3_reserved = in.readShort();
-
- //field_2_reserved = LittleEndian.getByteArray(data, offset + 12,12);
}
- public void writeBytes(byte [] array, int offset)
- {
- array[ offset + 0 ] = (byte)(sid + ptgClass);
+ public void writeBytes(byte [] array, int offset) {
+ array[ offset + 0 ] = (byte)(sid + getPtgClass());
LittleEndian.putShort(array, offset + 1, field_1_ixals);
LittleEndian.putShort(array,offset+3, field_2_ilbl);
LittleEndian.putShort(array, offset + 5, field_3_reserved);
}
- public int getSize()
- {
+ public int getSize() {
return SIZE;
}
@@ -67,14 +56,7 @@
return book.resolveNameXText(field_1_ixals, field_2_ilbl-1);
}
- public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
-
- public Object clone() {
- NameXPtg ptg = new NameXPtg();
- ptg.field_1_ixals = field_1_ixals;
- ptg.field_3_reserved = field_3_reserved;
- ptg.field_2_ilbl = field_2_ilbl;
- ptg.setClass(ptgClass);
- return ptg;
- }
+ public byte getDefaultOperandClass() {
+ return Ptg.CLASS_VALUE;
+ }
}
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/NotEqualPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/NotEqualPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/NotEqualPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/NotEqualPtg.java Sat Jun 21 05:03:44 2008
@@ -1,4 +1,3 @@
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -18,72 +17,36 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.record.RecordInputStream;
-
/**
* Ptg class to implement not equal
*
* @author fred at stsci dot edu
*/
-public class NotEqualPtg
- extends OperationPtg
-{
- public final static int SIZE = 1;
+public final class NotEqualPtg extends ValueOperatorPtg {
public final static byte sid = 0x0e;
- /**
- * Creates new NotEqualPtg
- */
- public NotEqualPtg()
- {
- }
-
- public NotEqualPtg( RecordInputStream in )
- {
- // doesn't need anything
- }
-
- public void writeBytes( byte[] array, int offset )
- {
- array[offset + 0] = sid;
- }
+ public static final ValueOperatorPtg instance = new NotEqualPtg();
- public int getSize()
- {
- return SIZE;
+ private NotEqualPtg() {
+ // enforce singleton
}
-
- public int getType()
- {
- return TYPE_BINARY;
+
+ protected byte getSid() {
+ return sid;
}
- public int getNumberOfOperands()
- {
+ public int getNumberOfOperands() {
return 2;
}
- public String toFormulaString( HSSFWorkbook book )
- {
- return "<>";
- }
-
- public String toFormulaString( String[] operands )
- {
+ public String toFormulaString(String[] operands) {
StringBuffer buffer = new StringBuffer();
buffer.append( operands[0] );
- buffer.append( toFormulaString( (HSSFWorkbook) null ) );
+ buffer.append("<>");
buffer.append( operands[1] );
return buffer.toString();
}
-
- public Object clone()
- {
- return new NotEqualPtg();
- }
-
}
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java Sat Jun 21 05:03:44 2008
@@ -28,22 +28,15 @@
* @author Avik Sengupta
* @author Jason Height (jheight at chariot dot net dot au)
*/
-
-public class NumberPtg
- extends Ptg
-{
+public final class NumberPtg extends ScalarConstantPtg {
public final static int SIZE = 9;
public final static byte sid = 0x1f;
- private double field_1_value;
-
- private NumberPtg() {
- //Required for clone methods
- }
+ private final double field_1_value;
/** Create a NumberPtg from a byte array read from disk */
public NumberPtg(RecordInputStream in)
{
- setValue(in.readDouble());
+ field_1_value = in.readDouble();
}
/** Create a NumberPtg from a string representation of the number
@@ -52,13 +45,7 @@
* @param value : String representation of a floating point number
*/
public NumberPtg(String value) {
- setValue(Double.parseDouble(value));
- }
-
-
- public void setValue(double value)
- {
- field_1_value = value;
+ field_1_value = Double.parseDouble(value);
}
@@ -82,11 +69,4 @@
{
return "" + getValue();
}
- public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
-
- public Object clone() {
- NumberPtg ptg = new NumberPtg();
- ptg.field_1_value = field_1_value;
- return ptg;
- }
}
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/OperationPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/OperationPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/OperationPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/OperationPtg.java Sat Jun 21 05:03:44 2008
@@ -17,21 +17,15 @@
package org.apache.poi.hssf.record.formula;
-
-
/**
* defines a Ptg that is an operation instead of an operand
* @author andy
*/
-
-public abstract class OperationPtg extends Ptg
-{
+public abstract class OperationPtg extends Ptg {
public final static int TYPE_UNARY = 0;
public final static int TYPE_BINARY = 1;
public final static int TYPE_FUNCTION = 2;
- public abstract int getType();
-
/**
* returns a string representation of the operations
* the length of the input array should equal the number returned by
@@ -45,6 +39,12 @@
*/
public abstract int getNumberOfOperands();
- public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
+ public byte getDefaultOperandClass() {
+ return Ptg.CLASS_VALUE;
+ }
+ public final int getType() {
+ // TODO remove "int getType();" from Eval hierarchy
+ throw new RuntimeException("remove this method");
+ }
}
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java Sat Jun 21 05:03:44 2008
@@ -32,25 +32,16 @@
* Andrew C. Oliver (acoliver at apache dot org)
* @author Jason Height (jheight at chariot dot net dot au)
*/
-public class ParenthesisPtg
- extends OperationPtg
-{
+public final class ParenthesisPtg extends ControlPtg {
private final static int SIZE = 1;
public final static byte sid = 0x15;
- public ParenthesisPtg()
- {
- }
-
- public ParenthesisPtg(RecordInputStream in)
- {
-
- // doesn't need anything
+ public static final ControlPtg instance = new ParenthesisPtg();
+ private ParenthesisPtg() {
+ // enforce singleton
}
-
-
public void writeBytes(byte [] array, int offset)
{
array[ offset + 0 ] = sid;
@@ -61,16 +52,6 @@
return SIZE;
}
- public int getType()
- {
- return TYPE_BINARY;
- }
-
- public int getNumberOfOperands()
- {
- return 1;
- }
-
public String toFormulaString(HSSFWorkbook book)
{
return "()";
@@ -80,11 +61,4 @@
public String toFormulaString(String[] operands) {
return "("+operands[0]+")";
}
-
- public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
-
- public Object clone() {
- return new ParenthesisPtg();
- }
-
}
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/PercentPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/PercentPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/PercentPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/PercentPtg.java Sat Jun 21 05:03:44 2008
@@ -1,4 +1,3 @@
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -16,70 +15,33 @@
limitations under the License.
==================================================================== */
-/*
- * PercentPtg.java
- *
- * Created on March 29, 2006, 9:23 PM
- */
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.record.RecordInputStream;
-
/**
* Percent PTG.
*
* @author Daniel Noll (daniel at nuix.com.au)
*/
-
-public class PercentPtg
- extends OperationPtg
-{
+public final class PercentPtg extends ValueOperatorPtg {
public final static int SIZE = 1;
public final static byte sid = 0x14;
private final static String PERCENT = "%";
- /** Creates new PercentPtg */
+ public static final ValueOperatorPtg instance = new PercentPtg();
- public PercentPtg()
- {
- }
-
- public PercentPtg(RecordInputStream in)
- {
-
- // doesn't need anything
+ private PercentPtg() {
+ // enforce singleton
}
-
- public void writeBytes(byte [] array, int offset)
- {
- array[ offset + 0 ] = sid;
+ protected byte getSid() {
+ return sid;
}
- public int getSize()
- {
- return SIZE;
- }
-
- public int getType()
- {
- return TYPE_UNARY;
- }
-
- public int getNumberOfOperands()
- {
+ public int getNumberOfOperands() {
return 1;
}
-
- /** Implementation of method from Ptg */
- public String toFormulaString(HSSFWorkbook book)
- {
- return "%";
- }
- /** implementation of method from OperationsPtg*/
public String toFormulaString(String[] operands) {
StringBuffer buffer = new StringBuffer();
@@ -87,11 +49,4 @@
buffer.append(PERCENT);
return buffer.toString();
}
-
- public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
-
- public Object clone() {
- return new PercentPtg();
- }
-
}
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/PowerPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/PowerPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/PowerPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/PowerPtg.java Sat Jun 21 05:03:44 2008
@@ -17,58 +17,26 @@
package org.apache.poi.hssf.record.formula;
-import java.util.List;
-
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.record.RecordInputStream;
-
/**
*
* @author andy
* @author Jason Height (jheight at chariot dot net dot au)
*/
-
-public class PowerPtg
- extends OperationPtg
-{
- public final static int SIZE = 1;
+public final class PowerPtg extends ValueOperatorPtg {
public final static byte sid = 0x07;
- /** Creates new AddPtg */
-
- public PowerPtg()
- {
- }
-
- public PowerPtg(RecordInputStream in)
- {
-
- // doesn't need anything
- }
-
- public void writeBytes(byte [] array, int offset)
- {
- array[ offset + 0 ] = sid;
- }
-
- public int getSize()
- {
- return SIZE;
- }
+ public static final ValueOperatorPtg instance = new PowerPtg();
- public int getType()
- {
- return TYPE_BINARY;
+ private PowerPtg() {
+ // enforce singleton
}
-
- public int getNumberOfOperands()
- {
- return 2;
+
+ protected byte getSid() {
+ return sid;
}
- public String toFormulaString(HSSFWorkbook book)
- {
- return "^";
+ public int getNumberOfOperands() {
+ return 2; // TODO - 2 seems wrong (Jun 2008). Maybe this method is not relevant
}
public String toFormulaString(String[] operands) {
@@ -76,13 +44,8 @@
buffer.append(operands[ 0 ]);
- buffer.append(toFormulaString((HSSFWorkbook)null));
+ buffer.append("^");
buffer.append(operands[ 1 ]);
return buffer.toString();
}
-
- public Object clone() {
- return new PowerPtg();
- }
-
}
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/Ptg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/Ptg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/Ptg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/Ptg.java Sat Jun 21 05:03:44 2008
@@ -17,456 +17,371 @@
package org.apache.poi.hssf.record.formula;
-import java.util.List;
import java.util.ArrayList;
+import java.util.List;
import java.util.Stack;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
+ * <tt>Ptg</tt> represents a syntactic token in a formula. 'PTG' is an acronym for
+ * '<b>p</b>arse <b>t</b>hin<b>g</b>'. Originally, the name referred to the single
+ * byte identifier at the start of the token, but in POI, <tt>Ptg</tt> encapsulates
+ * the whole formula token (initial byte + value data).
+ * <p/>
+ *
+ * <tt>Ptg</tt>s are logically arranged in a tree representing the structure of the
+ * parsed formula. However, in BIFF files <tt>Ptg</tt>s are written/read in
+ * <em>Reverse-Polish Notation</em> order. The RPN ordering also simplifies formula
+ * evaluation logic, so POI mostly accesses <tt>Ptg</tt>s in the same way.
*
* @author andy
* @author avik
* @author Jason Height (jheight at chariot dot net dot au)
*/
-public abstract class Ptg
-{
-
-
- /* convert infix order ptg list to rpn order ptg list
- * @return List ptgs in RPN order
- * @param infixPtgs List of ptgs in infix order
- */
-
- /* DO NOT REMOVE
- *we keep this method in case we wish to change the way we parse
- *It needs a getPrecedence in OperationsPtg
-
- public static List ptgsToRpn(List infixPtgs) {
- java.util.Stack operands = new java.util.Stack();
- java.util.List retval = new java.util.Stack();
-
- java.util.ListIterator i = infixPtgs.listIterator();
- Object p;
- OperationPtg o ;
- boolean weHaveABracket = false;
- while (i.hasNext()) {
- p=i.next();
- if (p instanceof OperationPtg) {
- if (p instanceof ParenthesisPtg) {
- if (!weHaveABracket) {
- operands.push(p);
- weHaveABracket = true;
- } else {
- o = (OperationPtg) operands.pop();
- while (!(o instanceof ParenthesisPtg)) {
- retval.add(o);
- }
- weHaveABracket = false;
- }
- } else {
-
- while (!operands.isEmpty() && ((OperationPtg) operands.peek()).getPrecedence() >= ((OperationPtg) p).getPrecedence() ) { //TODO handle ^ since it is right associative
- retval.add(operands.pop());
- }
- operands.push(p);
- }
- } else {
- retval.add(p);
- }
- }
- while (!operands.isEmpty()) {
- if (operands.peek() instanceof ParenthesisPtg ){
- //throw some error
- } else {
- retval.add(operands.pop());
- }
- }
- return retval;
- }
- */
-
- /**
- * Reads <tt>size</tt> bytes of the input stream, to create an array of <tt>Ptg</tt>s.
- * Extra data (beyond <tt>size</tt>) may be read if and <tt>ArrayPtg</tt>s are present.
- */
- public static Stack createParsedExpressionTokens(short size, RecordInputStream in )
- {
- Stack stack = new Stack();
- int pos = 0;
- List arrayPtgs = null;
- while ( pos < size )
- {
- Ptg ptg = Ptg.createPtg( in );
- if (ptg instanceof ArrayPtg) {
- if (arrayPtgs == null)
- arrayPtgs = new ArrayList(5);
- arrayPtgs.add(ptg);
- pos += 8;
- } else pos += ptg.getSize();
- stack.push( ptg );
- }
- if(pos != size) {
- throw new RuntimeException("Ptg array size mismatch");
- }
- if (arrayPtgs != null) {
- for (int i=0;i<arrayPtgs.size();i++) {
- ArrayPtg p = (ArrayPtg)arrayPtgs.get(i);
- p.readTokenValues(in);
- }
- }
- return stack;
- }
-
- public static Ptg createPtg(RecordInputStream in)
- {
- byte id = in.readByte();
- Ptg retval = null;
-
- switch (id)
- {
- case ExpPtg.sid : // 0x01
- retval = new ExpPtg(in);
- break;
-
- case AddPtg.sid : // 0x03
- retval = new AddPtg(in);
- break;
-
- case SubtractPtg.sid : // 0x04
- retval = new SubtractPtg(in);
- break;
-
- case MultiplyPtg.sid : // 0x05
- retval = new MultiplyPtg(in);
- break;
-
- case DividePtg.sid : // 0x06
- retval = new DividePtg(in);
- break;
-
- case PowerPtg.sid : // 0x07
- retval = new PowerPtg(in);
- break;
-
- case ConcatPtg.sid : // 0x08
- retval = new ConcatPtg(in);
- break;
-
- case LessThanPtg.sid: // 0x09
- retval = new LessThanPtg(in);
- break;
-
- case LessEqualPtg.sid : // 0x0a
- retval = new LessEqualPtg(in);
- break;
-
- case EqualPtg.sid : // 0x0b
- retval = new EqualPtg(in);
- break;
-
- case GreaterEqualPtg.sid : // 0x0c
- retval = new GreaterEqualPtg(in);
- break;
-
- case GreaterThanPtg.sid : // 0x0d
- retval = new GreaterThanPtg(in);
- break;
-
- case NotEqualPtg.sid : // 0x0e
- retval = new NotEqualPtg(in);
- break;
-
- case IntersectionPtg.sid : // 0x0f
- retval = new IntersectionPtg(in);
- break;
- case UnionPtg.sid : // 0x10
- retval = new UnionPtg(in);
- break;
-
- case RangePtg.sid : // 0x11
- retval = new RangePtg(in);
- break;
-
- case UnaryPlusPtg.sid : // 0x12
- retval = new UnaryPlusPtg(in);
- break;
-
- case UnaryMinusPtg.sid : // 0x13
- retval = new UnaryMinusPtg(in);
- break;
-
- case PercentPtg.sid : // 0x14
- retval = new PercentPtg(in);
- break;
-
- case ParenthesisPtg.sid : // 0x15
- retval = new ParenthesisPtg(in);
- break;
-
- case MissingArgPtg.sid : // 0x16
- retval = new MissingArgPtg(in);
- break;
-
- case StringPtg.sid : // 0x17
- retval = new StringPtg(in);
- break;
-
- case AttrPtg.sid : // 0x19
- case 0x1a :
- retval = new AttrPtg(in);
- break;
-
- case ErrPtg.sid : // 0x1c
- retval = new ErrPtg(in);
- break;
-
- case BoolPtg.sid : // 0x1d
- retval = new BoolPtg(in);
- break;
-
- case IntPtg.sid : // 0x1e
- retval = new IntPtg(in);
- break;
-
- case NumberPtg.sid : // 0x1f
- retval = new NumberPtg(in);
- break;
-
- case ArrayPtg.sid : // 0x20
- retval = new ArrayPtg(in);
- break;
- case ArrayPtgV.sid : // 0x40
- retval = new ArrayPtgV(in);
- break;
- case ArrayPtgA.sid : // 0x60
- retval = new ArrayPtgA(in);
- break;
-
- case FuncPtg.sid : // 0x21
- case FuncPtg.sid + 0x20 : // 0x41
- case FuncPtg.sid + 0x40 : // 0x61
- retval = new FuncPtg(in);
- break;
-
- case FuncVarPtg.sid : // 0x22
- case FuncVarPtg.sid + 0x20 : // 0x42
- case FuncVarPtg.sid + 0x40 : // 0x62
- retval = new FuncVarPtg(in);
- break;
-
- case ReferencePtg.sid : // 0x24
- retval = new ReferencePtg(in);
- break;
- case RefAPtg.sid : // 0x64
- retval = new RefAPtg(in);
- break;
- case RefVPtg.sid : // 0x44
- retval = new RefVPtg(in);
- break;
- case RefNAPtg.sid : // 0x6C
- retval = new RefNAPtg(in);
- break;
- case RefNPtg.sid : // 0x2C
- retval = new RefNPtg(in);
- break;
- case RefNVPtg.sid : // 0x4C
- retval = new RefNVPtg(in);
- break;
-
- case AreaPtg.sid : // 0x25
- retval = new AreaPtg(in);
- break;
- case AreaVPtg.sid: // 0x45
- retval = new AreaVPtg(in);
- break;
- case AreaAPtg.sid: // 0x65
- retval = new AreaAPtg(in);
- break;
- case AreaNAPtg.sid : // 0x6D
- retval = new AreaNAPtg(in);
- break;
- case AreaNPtg.sid : // 0x2D
- retval = new AreaNPtg(in);
- break;
- case AreaNVPtg.sid : // 0x4D
- retval = new AreaNVPtg(in);
- break;
-
- case MemAreaPtg.sid : // 0x26
- case MemAreaPtg.sid + 0x40 : // 0x46
- case MemAreaPtg.sid + 0x20 : // 0x66
- retval = new MemAreaPtg(in);
- break;
-
- case MemErrPtg.sid : // 0x27
- case MemErrPtg.sid + 0x20 : // 0x47
- case MemErrPtg.sid + 0x40 : // 0x67
- retval = new MemErrPtg(in);
- break;
-
- case MemFuncPtg.sid : // 0x29
- retval = new MemFuncPtg(in);
- break;
-
- case RefErrorPtg.sid : // 0x2a
- case RefErrorPtg.sid + 0x20 : // 0x4a
- case RefErrorPtg.sid + 0x40 : // 0x6a
- retval = new RefErrorPtg(in);
- break;
-
- case AreaErrPtg.sid : // 0x2b
- case AreaErrPtg.sid + 0x20 : // 0x4b
- case AreaErrPtg.sid + 0x40 : // 0x6b
- retval = new AreaErrPtg(in);
- break;
-
- case NamePtg.sid : // 0x23
- case NamePtg.sid + 0x20 : // 0x43
- case NamePtg.sid + 0x40 : // 0x63
- retval = new NamePtg(in);
- break;
-
- case NameXPtg.sid : // 0x39
- case NameXPtg.sid + 0x20 : // 0x45
- case NameXPtg.sid + 0x40 : // 0x79
- retval = new NameXPtg(in);
- break;
-
- case Area3DPtg.sid : // 0x3b
- case Area3DPtg.sid + 0x20 : // 0x5b
- case Area3DPtg.sid + 0x40 : // 0x7b
- retval = new Area3DPtg(in);
- break;
-
- case Ref3DPtg.sid : // 0x3a
- case Ref3DPtg.sid + 0x20: // 0x5a
- case Ref3DPtg.sid + 0x40: // 0x7a
- retval = new Ref3DPtg(in);
- break;
-
- case DeletedRef3DPtg.sid: // 0x3c
- case DeletedRef3DPtg.sid + 0x20: // 0x5c
- case DeletedRef3DPtg.sid + 0x40: // 0x7c
- retval = new DeletedRef3DPtg(in);
- break;
-
- case DeletedArea3DPtg.sid : // 0x3d
- case DeletedArea3DPtg.sid + 0x20 : // 0x5d
- case DeletedArea3DPtg.sid + 0x40 : // 0x7d
- retval = new DeletedArea3DPtg(in);
- break;
-
- case 0x00:
- retval = new UnknownPtg();
- break;
-
- default :
- //retval = new UnknownPtg();
- throw new java.lang.UnsupportedOperationException(" Unknown Ptg in Formula: 0x"+
- Integer.toHexString(( int ) id) + " (" + ( int ) id + ")");
- }
-
- if (id > 0x60) {
- retval.setClass(CLASS_ARRAY);
- } else if (id > 0x40) {
- retval.setClass(CLASS_VALUE);
- } else {
- retval.setClass(CLASS_REF);
- }
-
- return retval;
-
- }
-
- public static int serializePtgStack(Stack expression, byte[] array, int offset) {
- int pos = 0;
- int size = 0;
- if (expression != null)
- size = expression.size();
-
- List arrayPtgs = null;
-
- for (int k = 0; k < size; k++) {
- Ptg ptg = ( Ptg ) expression.get(k);
-
- ptg.writeBytes(array, pos + offset);
- if (ptg instanceof ArrayPtg) {
- if (arrayPtgs == null)
- arrayPtgs = new ArrayList(5);
- arrayPtgs.add(ptg);
- pos += 8;
- } else pos += ptg.getSize();
- }
- if (arrayPtgs != null) {
- for (int i=0;i<arrayPtgs.size();i++) {
- ArrayPtg p = (ArrayPtg)arrayPtgs.get(i);
- pos += p.writeTokenValueBytes(array, pos + offset);
- }
- }
- return pos;
- }
-
- public abstract int getSize();
-
- public final byte [] getBytes()
- {
- int size = getSize();
- byte[] bytes = new byte[ size ];
-
- writeBytes(bytes, 0);
- return bytes;
- }
- /** write this Ptg to a byte array*/
- public abstract void writeBytes(byte [] array, int offset);
-
- /**
- * return a string representation of this token alone
- */
- public abstract String toFormulaString(HSSFWorkbook book);
- /**
- * dump a debug representation (hexdump) to a string
- */
- public String toDebugString() {
- byte[] ba = new byte[getSize()];
- String retval=null;
- writeBytes(ba,0);
- try {
- retval = org.apache.poi.util.HexDump.dump(ba,0,0);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return retval;
- }
-
- /** Overridden toString method to ensure object hash is not printed.
- * This helps get rid of gratuitous diffs when comparing two dumps
- * Subclasses may output more relevant information by overriding this method
- **/
- public String toString(){
- return this.getClass().toString();
- }
-
- public static final byte CLASS_REF = 0x00;
- public static final byte CLASS_VALUE = 0x20;
- public static final byte CLASS_ARRAY = 0x40;
-
- protected byte ptgClass = CLASS_REF; //base ptg
-
- public void setClass(byte thePtgClass) {
- ptgClass = thePtgClass;
- }
-
- /** returns the class (REF/VALUE/ARRAY) for this Ptg */
- public byte getPtgClass() {
- return ptgClass;
- }
-
- public abstract byte getDefaultOperandClass();
-
- public abstract Object clone();
-
-
+public abstract class Ptg implements Cloneable {
+ /* convert infix order ptg list to rpn order ptg list
+ * @return List ptgs in RPN order
+ * @param infixPtgs List of ptgs in infix order
+ */
+
+ /* DO NOT REMOVE
+ *we keep this method in case we wish to change the way we parse
+ *It needs a getPrecedence in OperationsPtg
+
+ public static List ptgsToRpn(List infixPtgs) {
+ java.util.Stack operands = new java.util.Stack();
+ java.util.List retval = new java.util.Stack();
+
+ java.util.ListIterator i = infixPtgs.listIterator();
+ Object p;
+ OperationPtg o ;
+ boolean weHaveABracket = false;
+ while (i.hasNext()) {
+ p=i.next();
+ if (p instanceof OperationPtg) {
+ if (p instanceof ParenthesisPtg) {
+ if (!weHaveABracket) {
+ operands.push(p);
+ weHaveABracket = true;
+ } else {
+ o = (OperationPtg) operands.pop();
+ while (!(o instanceof ParenthesisPtg)) {
+ retval.add(o);
+ }
+ weHaveABracket = false;
+ }
+ } else {
+
+ while (!operands.isEmpty() && ((OperationPtg) operands.peek()).getPrecedence() >= ((OperationPtg) p).getPrecedence() ) { //TODO handle ^ since it is right associative
+ retval.add(operands.pop());
+ }
+ operands.push(p);
+ }
+ } else {
+ retval.add(p);
+ }
+ }
+ while (!operands.isEmpty()) {
+ if (operands.peek() instanceof ParenthesisPtg ){
+ //throw some error
+ } else {
+ retval.add(operands.pop());
+ }
+ }
+ return retval;
+ }
+ */
+
+ /**
+ * Reads <tt>size</tt> bytes of the input stream, to create an array of <tt>Ptg</tt>s.
+ * Extra data (beyond <tt>size</tt>) may be read if and <tt>ArrayPtg</tt>s are present.
+ */
+ public static Ptg[] readTokens(int size, RecordInputStream in) {
+ Stack temp = createParsedExpressionTokens((short)size, in);
+ return toPtgArray(temp);
+ }
+
+ /**
+ * @deprecated - use readTokens()
+ */
+ public static Stack createParsedExpressionTokens(short size, RecordInputStream in)
+ {
+ Stack stack = new Stack();
+ int pos = 0;
+ List arrayPtgs = null;
+ while ( pos < size )
+ {
+ Ptg ptg = Ptg.createPtg( in );
+ if (ptg instanceof ArrayPtg) {
+ if (arrayPtgs == null)
+ arrayPtgs = new ArrayList(5);
+ arrayPtgs.add(ptg);
+ pos += 8;
+ } else pos += ptg.getSize();
+ stack.push( ptg );
+ }
+ if(pos != size) {
+ throw new RuntimeException("Ptg array size mismatch");
+ }
+ if (arrayPtgs != null) {
+ for (int i=0;i<arrayPtgs.size();i++) {
+ ArrayPtg p = (ArrayPtg)arrayPtgs.get(i);
+ p.readTokenValues(in);
+ }
+ }
+ return stack;
+ }
+
+ public static Ptg createPtg(RecordInputStream in) {
+ byte id = in.readByte();
+
+ if (id < 0x20) {
+ return createBasePtg(id, in);
+ }
+
+ Ptg retval = createClassifiedPtg(id, in);
+
+ if (id > 0x60) {
+ retval.setClass(CLASS_ARRAY);
+ } else if (id > 0x40) {
+ retval.setClass(CLASS_VALUE);
+ } else {
+ retval.setClass(CLASS_REF);
+ }
+
+ return retval;
+ }
+
+ private static Ptg createClassifiedPtg(byte id, RecordInputStream in) {
+
+ int baseId = id & 0x1F | 0x20;
+
+ switch (baseId) {
+ case ArrayPtg.sid: return new ArrayPtg(in); // 0x20, 0x40, 0x60
+ case FuncPtg.sid: return new FuncPtg(in); // 0x21, 0x41, 0x61
+ case FuncVarPtg.sid: return new FuncVarPtg(in); // 0x22, 0x42, 0x62
+ case NamePtg.sid: return new NamePtg(in); // 0x23, 0x43, 0x63
+ case RefPtg.sid: return new RefPtg(in); // 0x24, 0x44, 0x64
+ case AreaPtg.sid: return new AreaPtg(in); // 0x25, 0x45, 0x65
+ case MemAreaPtg.sid: return new MemAreaPtg(in); // 0x26, 0x46, 0x66
+ case MemErrPtg.sid: return new MemErrPtg(in); // 0x27, 0x47, 0x67
+ case MemFuncPtg.sid: return new MemFuncPtg(in); // 0x29, 0x49, 0x69
+ case RefErrorPtg.sid: return new RefErrorPtg(in);// 0x2a, 0x4a, 0x6a
+ case AreaErrPtg.sid: return new AreaErrPtg(in); // 0x2b, 0x4b, 0x6b
+ case RefNPtg.sid: return new RefNPtg(in); // 0x2c, 0x4c, 0x6c
+ case AreaNPtg.sid: return new AreaNPtg(in); // 0x2d, 0x4d, 0x6d
+
+ case NameXPtg.sid: return new NameXPtg(in); // 0x39, 0x49, 0x79
+ case Ref3DPtg.sid: return new Ref3DPtg(in); // 0x3a, 0x5a, 0x7a
+ case Area3DPtg.sid: return new Area3DPtg(in); // 0x3b, 0x5b, 0x7b
+ case DeletedRef3DPtg.sid: return new DeletedRef3DPtg(in); // 0x3c, 0x5c, 0x7c
+ case DeletedArea3DPtg.sid: return new DeletedArea3DPtg(in); // 0x3d, 0x5d, 0x7d
+ }
+ throw new UnsupportedOperationException(" Unknown Ptg in Formula: 0x"+
+ Integer.toHexString(id) + " (" + ( int ) id + ")");
+ }
+
+ private static Ptg createBasePtg(byte id, RecordInputStream in) {
+ switch(id) {
+ case 0x00: return new UnknownPtg(); // TODO - not a real Ptg
+ case ExpPtg.sid: return new ExpPtg(in); // 0x01
+ case AddPtg.sid: return AddPtg.instance; // 0x03
+ case SubtractPtg.sid: return SubtractPtg.instance; // 0x04
+ case MultiplyPtg.sid: return MultiplyPtg.instance; // 0x05
+ case DividePtg.sid: return DividePtg.instance; // 0x06
+ case PowerPtg.sid: return PowerPtg.instance; // 0x07
+ case ConcatPtg.sid: return ConcatPtg.instance; // 0x08
+ case LessThanPtg.sid: return LessThanPtg.instance; // 0x09
+ case LessEqualPtg.sid: return LessEqualPtg.instance; // 0x0a
+ case EqualPtg.sid: return EqualPtg.instance; // 0x0b
+ case GreaterEqualPtg.sid: return GreaterEqualPtg.instance;// 0x0c
+ case GreaterThanPtg.sid: return GreaterThanPtg.instance; // 0x0d
+ case NotEqualPtg.sid: return NotEqualPtg.instance; // 0x0e
+ case IntersectionPtg.sid: return IntersectionPtg.instance;// 0x0f
+ case UnionPtg.sid: return UnionPtg.instance; // 0x10
+ case RangePtg.sid: return RangePtg.instance; // 0x11
+ case UnaryPlusPtg.sid: return UnaryPlusPtg.instance; // 0x12
+ case UnaryMinusPtg.sid: return UnaryMinusPtg.instance; // 0x13
+ case PercentPtg.sid: return PercentPtg.instance; // 0x14
+ case ParenthesisPtg.sid: return ParenthesisPtg.instance; // 0x15
+ case MissingArgPtg.sid: return MissingArgPtg.instance; // 0x16
+
+ case StringPtg.sid: return new StringPtg(in); // 0x17
+ case AttrPtg.sid:
+ case 0x1a: return new AttrPtg(in); // 0x19
+ case ErrPtg.sid: return new ErrPtg(in); // 0x1c
+ case BoolPtg.sid: return new BoolPtg(in); // 0x1d
+ case IntPtg.sid: return new IntPtg(in); // 0x1e
+ case NumberPtg.sid: return new NumberPtg(in); // 0x1f
+ }
+ throw new RuntimeException("Unexpected base token id (" + id + ")");
+ }
+ /**
+ *
+ *
+ */
+ public static int getEncodedSize(Stack ptgs) {
+ return getEncodedSize(toPtgArray(ptgs));
+ }
+ /**
+ * @return a distinct copy of this <tt>Ptg</tt> if the class is mutable, or the same instance
+ * if the class is immutable.
+ */
+ public final Ptg copy() {
+ // TODO - all base tokens are logically immutable, but AttrPtg needs some clean-up
+ if (this instanceof ValueOperatorPtg) {
+ return this;
+ }
+ if (this instanceof ScalarConstantPtg) {
+ return this;
+ }
+ return (Ptg) clone();
+ }
+
+ protected Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ private static Ptg[] toPtgArray(List l) {
+ Ptg[] result = new Ptg[l.size()];
+ l.toArray(result);
+ return result;
+ }
+ private static Stack createStack(Ptg[] formulaTokens) {
+ Stack result = new Stack();
+ for (int i = 0; i < formulaTokens.length; i++) {
+ result.add(formulaTokens[i]);
+ }
+ return result;
+ }
+ // TODO - several duplicates of this code should be refactored here
+ public static int getEncodedSize(Ptg[] ptgs) {
+ int result = 0;
+ for (int i = 0; i < ptgs.length; i++) {
+ result += ptgs[i].getSize();
+ }
+ return result;
+ }
+ /**
+ * Writes the ptgs to the data buffer, starting at the specified offset.
+ *
+ * <br/>
+ * The 2 byte encode length field is <b>not</b> written by this method.
+ * @return number of bytes written
+ */
+ public static int serializePtgs(Ptg[] ptgs, byte[] data, int offset) {
+ return serializePtgStack(createStack(ptgs), data, offset);
+ }
+
+ /**
+ * @deprecated use serializePtgs()
+ */
+ public static int serializePtgStack(Stack expression, byte[] array, int offset) {
+ int pos = 0;
+ int size = 0;
+ if (expression != null)
+ size = expression.size();
+
+ List arrayPtgs = null;
+
+ for (int k = 0; k < size; k++) {
+ Ptg ptg = ( Ptg ) expression.get(k);
+
+ ptg.writeBytes(array, pos + offset);
+ if (ptg instanceof ArrayPtg) {
+ if (arrayPtgs == null)
+ arrayPtgs = new ArrayList(5);
+ arrayPtgs.add(ptg);
+ pos += 8;
+ } else pos += ptg.getSize();
+ }
+ if (arrayPtgs != null) {
+ for (int i=0;i<arrayPtgs.size();i++) {
+ ArrayPtg p = (ArrayPtg)arrayPtgs.get(i);
+ pos += p.writeTokenValueBytes(array, pos + offset);
+ }
+ }
+ return pos;
+ }
+
+ /**
+ * @return the encoded length of this Ptg, including the initial Ptg type identifier byte.
+ */
+ public abstract int getSize();
+
+ /**
+ * @return the encoded length of this Ptg, not including the initial Ptg type identifier byte.
+ */
+// public abstract int getDataSize();
+
+ public final byte [] getBytes()
+ {
+ int size = getSize();
+ byte[] bytes = new byte[ size ];
+
+ writeBytes(bytes, 0);
+ return bytes;
+ }
+ /** write this Ptg to a byte array*/
+ public abstract void writeBytes(byte [] array, int offset);
+
+ /**
+ * return a string representation of this token alone
+ */
+ public abstract String toFormulaString(HSSFWorkbook book);
+ /**
+ * dump a debug representation (hexdump) to a string
+ */
+ public final String toDebugString() {
+ byte[] ba = new byte[getSize()];
+ String retval=null;
+ writeBytes(ba,0);
+ try {
+ retval = org.apache.poi.util.HexDump.dump(ba,0,0);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return retval;
+ }
+
+ /** Overridden toString method to ensure object hash is not printed.
+ * This helps get rid of gratuitous diffs when comparing two dumps
+ * Subclasses may output more relevant information by overriding this method
+ **/
+ public String toString(){
+ return this.getClass().toString();
+ }
+
+ public static final byte CLASS_REF = 0x00;
+ public static final byte CLASS_VALUE = 0x20;
+ public static final byte CLASS_ARRAY = 0x40;
+
+ private byte ptgClass = CLASS_REF; //base ptg
+
+ public final void setClass(byte thePtgClass) {
+ if (isBaseToken()) {
+ throw new RuntimeException("setClass should not be called on a base token");
+ }
+ ptgClass = thePtgClass;
+ }
+
+ /**
+ * @return the 'operand class' (REF/VALUE/ARRAY) for this Ptg
+ */
+ public final byte getPtgClass() {
+ return ptgClass;
+ }
+
+ public abstract byte getDefaultOperandClass();
+
+ /**
+ * @return <code>false</code> if this token is classified as 'reference', 'value', or 'array'
+ */
+ public abstract boolean isBaseToken();
}
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/RangePtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/RangePtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/RangePtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/RangePtg.java Sat Jun 21 05:03:44 2008
@@ -18,25 +18,23 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.record.RecordInputStream;
/**
* @author Daniel Noll (daniel at nuix dot com dot au)
*/
-public class RangePtg extends OperationPtg
-{
+public final class RangePtg extends OperationPtg {
public final static int SIZE = 1;
public final static byte sid = 0x11;
- public RangePtg()
- {
- }
+ public static final OperationPtg instance = new RangePtg();
- public RangePtg(RecordInputStream in)
- {
- // No contents
+ private RangePtg() {
+ // enforce singleton
}
+ public final boolean isBaseToken() {
+ return true;
+ }
public int getSize()
{
@@ -48,17 +46,6 @@
array[ offset + 0 ] = sid;
}
- public Object clone()
- {
- return new RangePtg();
- }
-
- public int getType()
- {
- return TYPE_BINARY;
- }
-
- /** Implementation of method from Ptg */
public String toFormulaString(HSSFWorkbook book)
{
return ":";
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java Sat Jun 21 05:03:44 2008
@@ -15,11 +15,10 @@
limitations under the License.
==================================================================== */
-
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.util.RangeAddress;
import org.apache.poi.hssf.util.SheetReferences;
@@ -35,8 +34,7 @@
* @author Jason Height (jheight at chariot dot net dot au)
* @version 1.0-pre
*/
-
-public class Ref3DPtg extends Ptg {
+public final class Ref3DPtg extends OperandPtg {
public final static byte sid = 0x3a;
private final static int SIZE = 7; // 6 + 1 for Ptg
private short field_1_index_extern_sheet;
@@ -70,20 +68,19 @@
}
public String toString() {
- StringBuffer buffer = new StringBuffer();
-
- buffer.append("Ref3dPtg\n");
- buffer.append("Index to Extern Sheet = " + getExternSheetIndex()).append("\n");
- buffer.append("Row = " + getRow()).append("\n");
- buffer.append("Col = " + getColumn()).append("\n");
- buffer.append("ColRowRel= "
- + isRowRelative()).append("\n");
- buffer.append("ColRel = " + isColRelative()).append("\n");
- return buffer.toString();
+ CellReference cr = new CellReference(getRow(), getColumn(), !isRowRelative(),!isColRelative());
+ StringBuffer sb = new StringBuffer();
+ sb.append(getClass().getName());
+ sb.append(" [");
+ sb.append("sheetIx=").append(getExternSheetIndex());
+ sb.append(" ! ");
+ sb.append(cr.formatAsString());
+ sb.append("]");
+ return sb.toString();
}
public void writeBytes(byte [] array, int offset) {
- array[ 0 + offset ] = (byte) (sid + ptgClass);
+ array[ 0 + offset ] = (byte) (sid + getPtgClass());
LittleEndian.putShort(array, 1 + offset , getExternSheetIndex());
LittleEndian.putShort(array, 3 + offset , (short)getRow());
LittleEndian.putShort(array, 5 + offset , (short)getColumnRaw());
@@ -191,14 +188,7 @@
return retval.toString();
}
- public byte getDefaultOperandClass() {return Ptg.CLASS_REF;}
-
- public Object clone() {
- Ref3DPtg ptg = new Ref3DPtg();
- ptg.field_1_index_extern_sheet = field_1_index_extern_sheet;
- ptg.field_2_row = field_2_row;
- ptg.field_3_column = field_3_column;
- ptg.setClass(ptgClass);
- return ptg;
- }
+ public byte getDefaultOperandClass() {
+ return Ptg.CLASS_REF;
+ }
}
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/RefErrorPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/RefErrorPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/RefErrorPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/RefErrorPtg.java Sat Jun 21 05:03:44 2008
@@ -17,28 +17,20 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.BitField;
-
-import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.util.LittleEndian;
/**
* RefError - handles deleted cell reference
* @author Jason Height (jheight at chariot dot net dot au)
*/
+public final class RefErrorPtg extends OperandPtg {
-public class RefErrorPtg extends Ptg
-{
private final static int SIZE = 5;
public final static byte sid = 0x2a;
private int field_1_reserved;
- private RefErrorPtg() {
- //Required for clone methods
- }
-
public RefErrorPtg(RecordInputStream in)
{
field_1_reserved = in.readInt();
@@ -55,7 +47,7 @@
public void writeBytes(byte [] array, int offset)
{
- array[offset] = (byte) (sid + ptgClass);
+ array[offset] = (byte) (sid + getPtgClass());
LittleEndian.putInt(array,offset+1,field_1_reserved);
}
@@ -83,11 +75,4 @@
public byte getDefaultOperandClass() {
return Ptg.CLASS_REF;
}
-
- public Object clone() {
- RefErrorPtg ptg = new RefErrorPtg();
- ptg.field_1_reserved = field_1_reserved;
- ptg.setClass(ptgClass);
- return ptg;
- }
}
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/RefNPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/RefNPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/RefNPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/RefNPtg.java Sat Jun 21 05:03:44 2008
@@ -18,37 +18,21 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
* RefNPtg
* @author Jason Height (jheight at apache dot com)
*/
-public final class RefNPtg extends ReferencePtg
-{
+public final class RefNPtg extends RefPtgBase {
public final static byte sid = 0x2C;
- protected RefNPtg() {
- //Required for clone methods
- }
-
/** Creates new ValueReferencePtg */
- public RefNPtg(RecordInputStream in)
- {
+ public RefNPtg(RecordInputStream in) {
super(in);
}
-
- public String getRefPtgName() {
- return "RefNPtg";
- }
-
- public String toFormulaString(HSSFWorkbook book)
- {
- throw notImplemented();
- }
-
- public Object clone() {
- throw notImplemented();
+
+ protected byte getSid() {
+ return sid;
}
}
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/StringPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/StringPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/StringPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/StringPtg.java Sat Jun 21 05:03:44 2008
@@ -31,7 +31,7 @@
* @author Jason Height (jheight at chariot dot net dot au)
* @author Bernard Chesnoy
*/
-public final class StringPtg extends Ptg {
+public final class StringPtg extends ScalarConstantPtg {
public final static int SIZE = 9;
public final static byte sid = 0x17;
private static final BitField fHighByte = BitFieldFactory.getInstance(0x01);
@@ -42,15 +42,11 @@
* NOTE: OO doc says 16bit length, but BiffViewer says 8 Book says something
* totally different, so don't look there!
*/
- private int field_1_length;
- private byte field_2_options;
- private String field_3_string;
+ private final int field_1_length;
+ private final byte field_2_options;
+ private final String field_3_string;
- private StringPtg() {
- // Required for clone methods
- }
-
- /** Create a StringPtg from a byte array read from disk */
+ /** Create a StringPtg from a stream */
public StringPtg(RecordInputStream in) {
field_1_length = in.readUByte();
field_2_options = in.readByte();
@@ -76,9 +72,7 @@
throw new IllegalArgumentException(
"String literals in formulas can't be bigger than 255 characters ASCII");
}
- field_2_options = 0;
- field_2_options = (byte) fHighByte.setBoolean(field_2_options, StringUtil
- .hasMultibyte(value));
+ field_2_options = (byte) fHighByte.setBoolean(0, StringUtil.hasMultibyte(value));
field_3_string = value;
field_1_length = value.length(); // for the moment, we support only ASCII strings in formulas we create
}
@@ -124,18 +118,6 @@
return sb.toString();
}
- public byte getDefaultOperandClass() {
- return Ptg.CLASS_VALUE;
- }
-
- public Object clone() {
- StringPtg ptg = new StringPtg();
- ptg.field_1_length = field_1_length;
- ptg.field_2_options = field_2_options;
- ptg.field_3_string = field_3_string;
- return ptg;
- }
-
public String toString() {
StringBuffer sb = new StringBuffer(64);
sb.append(getClass().getName()).append(" [");
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/SubtractPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/SubtractPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/SubtractPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/SubtractPtg.java Sat Jun 21 05:03:44 2008
@@ -17,57 +17,27 @@
package org.apache.poi.hssf.record.formula;
-import java.util.List;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.record.RecordInputStream;
-
/**
*
* @author andy
* @author Jason Height (jheight at chariot dot net dot au)
*/
-
-public class SubtractPtg
- extends OperationPtg
-{
- public final static int SIZE = 1;
+public final class SubtractPtg extends ValueOperatorPtg {
public final static byte sid = 0x04;
- public SubtractPtg()
- {
- }
-
- public SubtractPtg(RecordInputStream in)
- {
-
- // doesn't need anything
- }
-
- public void writeBytes(byte [] array, int offset)
- {
- array[ offset + 0 ] = sid;
- }
+ public static final ValueOperatorPtg instance = new SubtractPtg();
- public int getSize()
- {
- return SIZE;
+ private SubtractPtg() {
+ // enforce singleton
}
-
- public int getType()
- {
- return TYPE_BINARY;
+
+ protected byte getSid() {
+ return sid;
}
- public int getNumberOfOperands()
- {
+ public int getNumberOfOperands() {
return 2;
}
-
- public String toFormulaString(HSSFWorkbook book)
- {
- return "-";
- }
-
public String toFormulaString(String[] operands) {
StringBuffer buffer = new StringBuffer();
@@ -77,8 +47,4 @@
buffer.append(operands[ 1 ]);
return buffer.toString();
}
-
- public Object clone() {
- return new SubtractPtg();
- }
}
Modified: poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/UnaryMinusPtg.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/UnaryMinusPtg.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/UnaryMinusPtg.java (original)
+++ poi/tags/REL_3_1_FINAL/src/java/org/apache/poi/hssf/record/formula/UnaryMinusPtg.java Sat Jun 21 05:03:44 2008
@@ -17,63 +17,30 @@
package org.apache.poi.hssf.record.formula;
-import java.util.List;
-
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.record.RecordInputStream;
-
/**
* Unary Plus operator
* does not have any effect on the operand
* @author Avik Sengupta
*/
-
-public class UnaryMinusPtg extends OperationPtg
-{
- public final static int SIZE = 1;
+public final class UnaryMinusPtg extends ValueOperatorPtg {
public final static byte sid = 0x13;
private final static String MINUS = "-";
- /** Creates new AddPtg */
+ public static final ValueOperatorPtg instance = new UnaryMinusPtg();
- public UnaryMinusPtg()
- {
- }
-
- public UnaryMinusPtg(RecordInputStream in)
- {
-
- // doesn't need anything
+ private UnaryMinusPtg() {
+ // enforce singleton
}
-
- public void writeBytes(byte [] array, int offset)
- {
- array[ offset + 0 ] = sid;
- }
-
- public int getSize()
- {
- return SIZE;
- }
-
- public int getType()
- {
- return this.TYPE_UNARY;
+ protected byte getSid() {
+ return sid;
}
- public int getNumberOfOperands()
- {
+ public int getNumberOfOperands() {
return 1;
}
- /** Implementation of method from Ptg */
- public String toFormulaString(HSSFWorkbook book)
- {
- return "+";
- }
-
/** implementation of method from OperationsPtg*/
public String toFormulaString(String[] operands) {
StringBuffer buffer = new StringBuffer();
@@ -81,11 +48,4 @@
buffer.append(operands[ 0]);
return buffer.toString();
}
-
- public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
-
- public Object clone() {
- return new UnaryPlusPtg();
- }
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org