poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r690461 - in /poi/trunk/src: java/org/apache/poi/hssf/record/formula/Ptg.java testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java
Date Sat, 30 Aug 2008 04:34:02 GMT
Author: josh
Date: Fri Aug 29 21:34:01 2008
New Revision: 690461

URL: http://svn.apache.org/viewvc?rev=690461&view=rev
Log:
Fixed decoding of operand class for ArrayPtg

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ptg.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ptg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ptg.java?rev=690461&r1=690460&r2=690461&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ptg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ptg.java Fri Aug 29 21:34:01 2008
@@ -43,58 +43,6 @@
 public abstract class Ptg implements Cloneable {
 	public static final Ptg[] EMPTY_PTG_ARRAY = { }; 
 
-	/* 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.
@@ -145,15 +93,15 @@
 		
 		Ptg  retval = createClassifiedPtg(id, in);
 
-		if (id > 0x60) {
+		if (id >= 0x60) { 
 			retval.setClass(CLASS_ARRAY);
-		} else if (id > 0x40) {
+		} else if (id >= 0x40) {
 			retval.setClass(CLASS_VALUE);
 		} else {
 			retval.setClass(CLASS_REF);
 		}
 
-	   return retval;
+		return retval;
 	}
 
 	private static Ptg createClassifiedPtg(byte id, RecordInputStream in) {
@@ -396,6 +344,22 @@
 	public final byte getPtgClass() {
 		return ptgClass;
 	}
+	
+	/**
+	 * Debug / diagnostic method to get this token's 'operand class' type.
+	 * @return 'R' for 'reference', 'V' for 'value', 'A' for 'array' and '.' for base tokens
+	 */
+	public final char getRVAType() {
+		if (isBaseToken()) {
+			return '.';
+		}
+		switch (ptgClass) {
+			case Ptg.CLASS_REF:   return 'R';
+			case Ptg.CLASS_VALUE: return 'V';
+			case Ptg.CLASS_ARRAY: return 'A';
+		}
+		throw new RuntimeException("Unknown operand class (" + ptgClass + ")");
+	}
 
 	public abstract byte getDefaultOperandClass();
 

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java?rev=690461&r1=690460&r2=690461&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java Fri Aug 29
21:34:01 2008
@@ -20,6 +20,7 @@
 import java.util.Arrays;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.record.TestcaseRecordInputStream;
 import org.apache.poi.hssf.record.UnicodeString;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -128,4 +129,28 @@
 		}
 		assertEquals("{TRUE,\"ABCD\";\"E\",0.0;FALSE,\"FG\"}", actualFormula);
 	}
+	
+	/**
+	 * worth checking since AttrPtg.sid=0x20 and Ptg.CLASS_* = (0x00, 0x20, and 0x40)
+	 */
+	public void testOperandClassDecoding() {
+		confirmOperandClassDecoding(Ptg.CLASS_REF);
+		confirmOperandClassDecoding(Ptg.CLASS_VALUE);
+		confirmOperandClassDecoding(Ptg.CLASS_ARRAY);
+	}
+
+	private static void confirmOperandClassDecoding(byte operandClass) {
+		byte[] fullData = new byte[ENCODED_PTG_DATA.length + ENCODED_CONSTANT_DATA.length];
+		System.arraycopy(ENCODED_PTG_DATA, 0, fullData, 0, ENCODED_PTG_DATA.length);
+		System.arraycopy(ENCODED_CONSTANT_DATA, 0, fullData, ENCODED_PTG_DATA.length, ENCODED_CONSTANT_DATA.length);
+
+		// Force encoded operand class for tArray 
+		fullData[0] = (byte) (ArrayPtg.sid + operandClass);
+		
+		RecordInputStream in = new TestcaseRecordInputStream(ArrayPtg.sid, fullData);
+		
+		Ptg[] ptgs = Ptg.readTokens(ENCODED_PTG_DATA.length, in);
+		ArrayPtg aPtg = (ArrayPtg) ptgs[0];
+		assertEquals(operandClass, aPtg.getPtgClass());
+	}
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message