diff --git a/src/java/org/apache/poi/hssf/record/formula/AddPtg.java b/src/java/org/apache/poi/hssf/record/formula/AddPtg.java index a47cf6956..22af5b3b4 100644 --- a/src/java/org/apache/poi/hssf/record/formula/AddPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/AddPtg.java @@ -60,14 +60,15 @@ */ package org.apache.poi.hssf.record.formula; +import java.util.List; + /** * * @author andy */ public class AddPtg - extends Ptg - implements OperationPtg + extends OperationPtg { public final static int SIZE = 1; public final static byte sid = 0x03; @@ -147,4 +148,10 @@ public class AddPtg public int getStringLength() { return 1; } + + public void manipulate(List source, List results, int pos) { + standardBinaryManipulation(source,results,pos); + + } + } diff --git a/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java b/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java index 0a9fb5c48..a92712e9c 100644 --- a/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java @@ -63,6 +63,8 @@ package org.apache.poi.hssf.record.formula; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.BitField; +import java.util.List; + /** * "Special Attributes" * This seems to be a Misc Stuff and Junk record. One function it serves is @@ -71,8 +73,7 @@ import org.apache.poi.util.BitField; */ public class AttrPtg - extends Ptg - implements OperationPtg + extends OperationPtg { public final static short sid = 0x19; private final static int SIZE = 4; @@ -205,4 +206,9 @@ public class AttrPtg { return -1; } + + public void manipulate(List source, List results, int pos) { + } + + } diff --git a/src/java/org/apache/poi/hssf/record/formula/DividePtg.java b/src/java/org/apache/poi/hssf/record/formula/DividePtg.java index 241047f3b..a3d76fe94 100644 --- a/src/java/org/apache/poi/hssf/record/formula/DividePtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/DividePtg.java @@ -60,14 +60,15 @@ */ package org.apache.poi.hssf.record.formula; +import java.util.List; + /** * * @author andy */ public class DividePtg - extends Ptg - implements OperationPtg + extends OperationPtg { public final static int SIZE = 1; public final static byte sid = 0x06; @@ -118,4 +119,8 @@ public class DividePtg buffer.append(operands[ 1 ].toFormulaString()); return buffer.toString(); } + + public void manipulate(List source, List results, int pos) { + } + } diff --git a/src/java/org/apache/poi/hssf/record/formula/MultiplyPtg.java b/src/java/org/apache/poi/hssf/record/formula/MultiplyPtg.java index 8dc1395f2..e4a170379 100644 --- a/src/java/org/apache/poi/hssf/record/formula/MultiplyPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/MultiplyPtg.java @@ -60,17 +60,20 @@ */ package org.apache.poi.hssf.record.formula; +import java.util.List; + /** * * @author andy */ public class MultiplyPtg - extends Ptg - implements OperationPtg + extends OperationPtg { public final static int SIZE = 1; public final static byte sid = 0x05; + + private final static String MULTIPLY="*"; /** Creates new AddPtg */ @@ -83,6 +86,11 @@ public class MultiplyPtg // doesn't need anything } + + protected MultiplyPtg(String formula, int offset) { + + } + public void writeBytes(byte [] array, int offset) { @@ -104,6 +112,11 @@ public class MultiplyPtg return 2; } + public int getStringLength() { + return 1; + } + + public String toFormulaString() { return "*"; @@ -118,4 +131,28 @@ public class MultiplyPtg buffer.append(operands[ 1 ].toFormulaString()); return buffer.toString(); } + + public void manipulate(List source, List results, int pos) { + standardBinaryManipulation(source, results, pos); + } + + public int getPrecedence() { + return 3; + } + + public static boolean isNextStringToken(String formula, int pos) { + boolean retval = false; + while (pos < formula.length() && Character.isWhitespace(formula.charAt(pos))) { + pos++; + } + + if (pos < formula.length()) { + if (formula.charAt(pos) == MULTIPLY.toCharArray()[0]) { + retval = true; + } + } + return retval; + } + + } diff --git a/src/java/org/apache/poi/hssf/record/formula/OperationPtg.java b/src/java/org/apache/poi/hssf/record/formula/OperationPtg.java index c598cfcfd..6f56e2a1c 100644 --- a/src/java/org/apache/poi/hssf/record/formula/OperationPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/OperationPtg.java @@ -60,20 +60,31 @@ */ package org.apache.poi.hssf.record.formula; +import java.util.List; + /** * defines a Ptg that is an operation instead of an operand * @author andy */ -public interface OperationPtg +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 int getType(); + public abstract int getType(); - public int getNumberOfOperands(); + public abstract int getNumberOfOperands(); + + /** + * manipulate the list, moving the arguments for this function to the source list + * followed by the operator. + */ + public abstract void manipulate(List source, List results, int pos); - public String toFormulaString(Ptg [] operands); + public abstract String toFormulaString(Ptg [] operands); + + protected void standardBinaryManipulation(List source,List results, int pos) { + } } diff --git a/src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java b/src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java index 5bf163b07..afd6289f4 100644 --- a/src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java @@ -55,16 +55,18 @@ package org.apache.poi.hssf.record.formula; +import java.util.List; + /** * Dummy class, we want it only for for the parsing process * does not actually get into the file -- note by andy...there is a parenthesis PTG * that can be written and is sometimes! * * Avik Sengupta + * Andrew C. Oliver (acoliver at apache dot org) */ public class ParenthesisPtg - extends Ptg - implements OperationPtg + extends OperationPtg { @@ -99,5 +101,9 @@ public class ParenthesisPtg { return "("; } + + public void manipulate(List source, List results, int pos) { + } + } diff --git a/src/java/org/apache/poi/hssf/record/formula/PowerPtg.java b/src/java/org/apache/poi/hssf/record/formula/PowerPtg.java index e5e61be9e..b3680eb09 100644 --- a/src/java/org/apache/poi/hssf/record/formula/PowerPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/PowerPtg.java @@ -60,14 +60,15 @@ */ package org.apache.poi.hssf.record.formula; +import java.util.List; + /** * * @author andy */ public class PowerPtg - extends Ptg - implements OperationPtg + extends OperationPtg { public final static int SIZE = 1; public final static byte sid = 0x07; @@ -118,4 +119,8 @@ public class PowerPtg buffer.append(operands[ 0 ].toFormulaString()); return buffer.toString(); } + + public void manipulate(List source, List results, int pos) { + } + } diff --git a/src/java/org/apache/poi/hssf/record/formula/SubtractPtg.java b/src/java/org/apache/poi/hssf/record/formula/SubtractPtg.java index e9c70c834..d550df54d 100644 --- a/src/java/org/apache/poi/hssf/record/formula/SubtractPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/SubtractPtg.java @@ -60,14 +60,15 @@ */ package org.apache.poi.hssf.record.formula; +import java.util.List; + /** * * @author andy */ public class SubtractPtg - extends Ptg - implements OperationPtg + extends OperationPtg { public final static int SIZE = 1; public final static byte sid = 0x04; @@ -118,4 +119,9 @@ public class SubtractPtg buffer.append(operands[ 1 ].toFormulaString()); return buffer.toString(); } + + public void manipulate(List source, List results, int pos) { + } + + } diff --git a/src/java/org/apache/poi/hssf/record/formula/ValueVariableFunctionPtg.java b/src/java/org/apache/poi/hssf/record/formula/ValueVariableFunctionPtg.java index 84dcb51bd..df3972803 100644 --- a/src/java/org/apache/poi/hssf/record/formula/ValueVariableFunctionPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/ValueVariableFunctionPtg.java @@ -63,14 +63,15 @@ package org.apache.poi.hssf.record.formula; import org.apache.poi.util.BitField; import org.apache.poi.util.LittleEndian; +import java.util.List; + /** * An excel function with variable number of value arguments. * @author andy */ public class ValueVariableFunctionPtg - extends Ptg - implements OperationPtg + extends OperationPtg { public final static short sid = 0x42; private final static short SIZE = 4; @@ -127,4 +128,8 @@ public class ValueVariableFunctionPtg { return toFormulaString(); } + + public void manipulate(List source, List results, int pos) { + } + }