You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2008/04/05 15:07:25 UTC

svn commit: r645088 [2/3] - in /poi/branches/ooxml: ./ src/documentation/content/xdocs/ src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/record/ src/java/org/apache/poi/hssf/record/aggregates/ src/java/org/apache/poi/hssf/record/cf/ src...

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/function/FunctionMetadata.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/function/FunctionMetadata.java?rev=645088&r1=645087&r2=645088&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/function/FunctionMetadata.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/function/FunctionMetadata.java Sat Apr  5 06:07:22 2008
@@ -17,6 +17,7 @@
 
 package org.apache.poi.hssf.record.formula.function;
 /**
+ * Holds information about Excel built-in functions.
  * 
  * @author Josh Micich
  */
@@ -46,7 +47,7 @@
 		return _maxParams;
 	}
 	public boolean hasFixedArgsLength() {
-	    return _minParams == _maxParams;
+		return _minParams == _maxParams;
 	}
 	public String toString() {
 		StringBuffer sb = new StringBuffer(64);

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/function/FunctionMetadataReader.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/function/FunctionMetadataReader.java?rev=645088&r1=645087&r2=645088&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/function/FunctionMetadataReader.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/function/FunctionMetadataReader.java Sat Apr  5 06:07:22 2008
@@ -46,7 +46,7 @@
 
 	public static FunctionMetadataRegistry createRegistry() {
 		InputStream is = FunctionMetadataReader.class.getResourceAsStream(METADATA_FILE_NAME);
-		if(is == null) {
+		if (is == null) {
 			throw new RuntimeException("resource '" + METADATA_FILE_NAME + "' not found");
 		}
 

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/function/FunctionMetadataRegistry.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/function/FunctionMetadataRegistry.java?rev=645088&r1=645087&r2=645088&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/function/FunctionMetadataRegistry.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/function/FunctionMetadataRegistry.java Sat Apr  5 06:07:22 2008
@@ -19,7 +19,11 @@
 
 import java.util.Map;
 import java.util.Set;
-
+/**
+ * Allows clients to get <tt>FunctionMetadata</tt> instances for any built-in function of Excel.
+ * 
+ * @author Josh Micich
+ */
 public final class FunctionMetadataRegistry {
 	/**
 	 * The name of the IF function (i.e. "IF").  Extracted as a constant for clarity.
@@ -35,7 +39,6 @@
 	private static FunctionMetadataRegistry getInstance() {
 		if (_instance == null) {
 			_instance = FunctionMetadataReader.createRegistry();
-//			_instance = POIFunctionMetadataCreator.createInstance();
 		}
 		return _instance;
 	}

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/functions/Pmt.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/functions/Pmt.java?rev=645088&r1=645087&r2=645088&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/functions/Pmt.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/functions/Pmt.java Sat Apr  5 06:07:22 2008
@@ -46,15 +46,15 @@
 		if(args.length < 3 || args.length > 5) {
 			return ErrorEval.VALUE_INVALID;
 		}
-		
- 		try {
- 			// evaluate first three (always present) args
+
+		try {
+			// evaluate first three (always present) args
 			double rate = evalArg(args[0], srcRow, srcCol);
 			double nper = evalArg(args[1], srcRow, srcCol);
-			double pv  = evalArg(args[2], srcRow, srcCol); 
+			double pv  = evalArg(args[2], srcRow, srcCol);
 			double fv = 0;
 			boolean arePaymentsAtPeriodBeginning = false;
-			
+
 			switch (args.length) {
 				case 5:
 					ValueEval ve = singleOperandNumericAsBoolean(args[4], srcRow, srcCol);
@@ -67,10 +67,10 @@
 			}
 			double d = FinanceLib.pmt(rate, nper, pv, fv, arePaymentsAtPeriodBeginning);
 			if (Double.isNaN(d)) {
-				return (ValueEval) ErrorEval.VALUE_INVALID;
+				return ErrorEval.VALUE_INVALID;
 			}
 			if (Double.isInfinite(d)) {
-				return (ValueEval) ErrorEval.NUM_ERROR;
+				return ErrorEval.NUM_ERROR;
 			}
 			return new NumberEval(d);
 		} catch (EvaluationException e) {

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java?rev=645088&r1=645087&r2=645088&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java Sat Apr  5 06:07:22 2008
@@ -26,103 +26,167 @@
  * @author Dmitriy Kumshayev
  *
  */
-public class HSSFBorderFormatting
+public final class HSSFBorderFormatting
 {
-    /**
-     * No border
-     */
+	/** No border */
+	public final static short BORDER_NONE =  BorderFormatting.BORDER_NONE;
+	/** Thin border */
+	public final static short BORDER_THIN =  BorderFormatting.BORDER_THIN;
+	/** Medium border */
+	public final static short BORDER_MEDIUM =  BorderFormatting.BORDER_MEDIUM;
+	/** dash border */
+	public final static short BORDER_DASHED =  BorderFormatting.BORDER_DASHED;
+	/** dot border */
+	public final static short BORDER_HAIR =  BorderFormatting.BORDER_HAIR;
+	/** Thick border */
+	public final static short BORDER_THICK =  BorderFormatting.BORDER_THICK;
+	/** double-line border */
+	public final static short BORDER_DOUBLE =  BorderFormatting.BORDER_DOUBLE;
+	/** hair-line border */
+	public final static short BORDER_DOTTED =  BorderFormatting.BORDER_DOTTED;
+	/** Medium dashed border */
+	public final static short BORDER_MEDIUM_DASHED =  BorderFormatting.BORDER_MEDIUM_DASHED;
+	/** dash-dot border */
+	public final static short BORDER_DASH_DOT =  BorderFormatting.BORDER_DASH_DOT;
+	/** medium dash-dot border */
+	public final static short BORDER_MEDIUM_DASH_DOT =  BorderFormatting.BORDER_MEDIUM_DASH_DOT;
+	/** dash-dot-dot border */
+	public final static short BORDER_DASH_DOT_DOT =  BorderFormatting.BORDER_DASH_DOT_DOT;
+	/** medium dash-dot-dot border */
+	public final static short BORDER_MEDIUM_DASH_DOT_DOT =  BorderFormatting.BORDER_MEDIUM_DASH_DOT_DOT;
+	/** slanted dash-dot border */
+	public final static short BORDER_SLANTED_DASH_DOT =  BorderFormatting.BORDER_SLANTED_DASH_DOT;
 
-    public final static short BORDER_NONE =  BorderFormatting.BORDER_NONE;
-
-    /**
-     * Thin border
-     */
-
-    public final static short BORDER_THIN =  BorderFormatting.BORDER_THIN;
-
-    /**
-     * Medium border
-     */
+	
+	private final BorderFormatting borderFormatting;
+	
+	public HSSFBorderFormatting()
+	{
+		borderFormatting = new BorderFormatting();
+	}
 
-    public final static short BORDER_MEDIUM =  BorderFormatting.BORDER_MEDIUM;
+	protected BorderFormatting getBorderFormattingBlock()
+	{
+		return borderFormatting;
+	}
 
-    /**
-     * dash border
-     */
+	public short getBorderBottom()
+	{
+		return borderFormatting.getBorderBottom();
+	}
 
-    public final static short BORDER_DASHED =  BorderFormatting.BORDER_DASHED;
+	public short getBorderDiagonal()
+	{
+		return borderFormatting.getBorderDiagonal();
+	}
 
-    /**
-     * dot border
-     */
+	public short getBorderLeft()
+	{
+		return borderFormatting.getBorderLeft();
+	}
 
-    public final static short BORDER_HAIR =  BorderFormatting.BORDER_HAIR;
+	public short getBorderRight()
+	{
+		return borderFormatting.getBorderRight();
+	}
 
-    /**
-     * Thick border
-     */
+	public short getBorderTop()
+	{
+		return borderFormatting.getBorderTop();
+	}
 
-    public final static short BORDER_THICK =  BorderFormatting.BORDER_THICK;
+	public short getBottomBorderColor()
+	{
+		return borderFormatting.getBottomBorderColor();
+	}
 
-    /**
-     * double-line border
-     */
+	public short getDiagonalBorderColor()
+	{
+		return borderFormatting.getDiagonalBorderColor();
+	}
 
-    public final static short BORDER_DOUBLE =  BorderFormatting.BORDER_DOUBLE;
+	public short getLeftBorderColor()
+	{
+		return borderFormatting.getLeftBorderColor();
+	}
 
-    /**
-     * hair-line border
-     */
+	public short getRightBorderColor()
+	{
+		return borderFormatting.getRightBorderColor();
+	}
 
-    public final static short BORDER_DOTTED =  BorderFormatting.BORDER_DOTTED;
+	public short getTopBorderColor()
+	{
+		return borderFormatting.getTopBorderColor();
+	}
 
-    /**
-     * Medium dashed border
-     */
+	public boolean isBackwardDiagonalOn()
+	{
+		return borderFormatting.isBackwardDiagonalOn();
+	}
 
-    public final static short BORDER_MEDIUM_DASHED =  BorderFormatting.BORDER_MEDIUM_DASHED;
+	public boolean isForwardDiagonalOn()
+	{
+		return borderFormatting.isForwardDiagonalOn();
+	}
 
-    /**
-     * dash-dot border
-     */
+	public void setBackwardDiagonalOn(boolean on)
+	{
+		borderFormatting.setBackwardDiagonalOn(on);
+	}
 
-    public final static short BORDER_DASH_DOT =  BorderFormatting.BORDER_DASH_DOT;
+	public void setBorderBottom(short border)
+	{
+		borderFormatting.setBorderBottom(border);
+	}
 
-    /**
-     * medium dash-dot border
-     */
+	public void setBorderDiagonal(short border)
+	{
+		borderFormatting.setBorderDiagonal(border);
+	}
 
-    public final static short BORDER_MEDIUM_DASH_DOT =  BorderFormatting.BORDER_MEDIUM_DASH_DOT;
+	public void setBorderLeft(short border)
+	{
+		borderFormatting.setBorderLeft(border);
+	}
 
-    /**
-     * dash-dot-dot border
-     */
+	public void setBorderRight(short border)
+	{
+		borderFormatting.setBorderRight(border);
+	}
 
-    public final static short BORDER_DASH_DOT_DOT =  BorderFormatting.BORDER_DASH_DOT_DOT;
+	public void setBorderTop(short border)
+	{
+		borderFormatting.setBorderTop(border);
+	}
 
-    /**
-     * medium dash-dot-dot border
-     */
+	public void setBottomBorderColor(short color)
+	{
+		borderFormatting.setBottomBorderColor(color);
+	}
 
-    public final static short BORDER_MEDIUM_DASH_DOT_DOT =  BorderFormatting.BORDER_MEDIUM_DASH_DOT_DOT;
+	public void setDiagonalBorderColor(short color)
+	{
+		borderFormatting.setDiagonalBorderColor(color);
+	}
 
-    /**
-     * slanted dash-dot border
-     */
+	public void setForwardDiagonalOn(boolean on)
+	{
+		borderFormatting.setForwardDiagonalOn(on);
+	}
 
-    public final static short BORDER_SLANTED_DASH_DOT =  BorderFormatting.BORDER_SLANTED_DASH_DOT;
+	public void setLeftBorderColor(short color)
+	{
+		borderFormatting.setLeftBorderColor(color);
+	}
 
-    
-	private BorderFormatting borderFormatting;
-	
-	public HSSFBorderFormatting()
+	public void setRightBorderColor(short color)
 	{
-		borderFormatting = new BorderFormatting();
+		borderFormatting.setRightBorderColor(color);
 	}
 
-	protected BorderFormatting getBorderFormattingBlock()
+	public void setTopBorderColor(short color)
 	{
-		return borderFormatting;
+		borderFormatting.setTopBorderColor(color);
 	}
-    
 }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java?rev=645088&r1=645087&r2=645088&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java Sat Apr  5 06:07:22 2008
@@ -16,9 +16,7 @@
 ==================================================================== */
 package org.apache.poi.hssf.usermodel;
 
-import java.util.ArrayList;
-import java.util.List;
-
+import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.CFHeaderRecord;
 import org.apache.poi.hssf.record.CFRuleRecord;
 import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate;
@@ -86,13 +84,9 @@
  */
 public final class HSSFConditionalFormatting
 {
-	private final HSSFSheet sheet;
+	private final Workbook workbook;
 	private final CFRecordsAggregate cfAggregate;
 
-	HSSFConditionalFormatting(HSSFSheet sheet) {
-		this(sheet, new CFRecordsAggregate());
-	}
-
 	HSSFConditionalFormatting(HSSFSheet sheet, CFRecordsAggregate cfAggregate)
 	{
 		if(sheet == null) {
@@ -101,36 +95,25 @@
 		if(cfAggregate == null) {
 			throw new IllegalArgumentException("cfAggregate must not be null");
 		}
-		this.sheet = sheet;
+		workbook = sheet.workbook.getWorkbook();
 		this.cfAggregate = cfAggregate;
 	}
 	CFRecordsAggregate getCFRecordsAggregate() {
 		return cfAggregate;
 	}
 
-	public void setFormattingRegions(Region[] regions)
-	{
-		if( regions != null)
-		{
-			CFHeaderRecord header = cfAggregate.getHeader();
-			header.setCellRanges(mergeCellRanges(toCellRangeList(regions)));
-		}
-	}
-
 	/**
-	 * @return array of <tt>Region</tt>s. never <code>null</code>
+	 * @return array of <tt>Region</tt>s. never <code>null</code> 
 	 */
 	public Region[] getFormattingRegions()
 	{
 		CFHeaderRecord cfh = cfAggregate.getHeader();
-
-		List cellRanges = cfh.getCellRanges();
-
-		return toRegionArray(cellRanges);
+		CellRange[] cellRanges = cfh.getCellRanges();
+		return CellRange.convertCellRangesToRegions(cellRanges);
 	}
 
 	/**
-	 * set a Conditional Formatting rule at position idx. 
+	 * Replaces an existing Conditional Formatting rule at position idx. 
 	 * Excel allows to create up to 3 Conditional Formatting rules.
 	 * This method can be useful to modify existing  Conditional Formatting rules.
 	 * 
@@ -139,11 +122,7 @@
 	 */
 	public void setRule(int idx, HSSFConditionalFormattingRule cfRule)
 	{
-	    if (idx < 0 || idx > 2) {
-	        throw new IllegalArgumentException("idx must be between 0 and 2 but was (" 
-	                + idx + ")");
-	    }
-		cfAggregate.getRules().set(idx, cfRule);
+		cfAggregate.setRule(idx, cfRule.getCfRuleRecord());
 	}
 
 	/**
@@ -153,136 +132,24 @@
 	 */
 	public void addRule(HSSFConditionalFormattingRule cfRule)
 	{
-		cfAggregate.getRules().add(cfRule);
+		cfAggregate.addRule(cfRule.getCfRuleRecord());
 	}
 
 	/**
-	 * get a Conditional Formatting rule at position idx. 
-	 * @param idx
-	 * @return a Conditional Formatting rule at position idx.
+	 * @return the Conditional Formatting rule at position idx.
 	 */
 	public HSSFConditionalFormattingRule getRule(int idx)
 	{
-		CFRuleRecord ruleRecord = (CFRuleRecord)cfAggregate.getRules().get(idx);
-		return new HSSFConditionalFormattingRule(sheet.workbook, ruleRecord);
+		CFRuleRecord ruleRecord = cfAggregate.getRule(idx);
+		return new HSSFConditionalFormattingRule(workbook, ruleRecord);
 	}
 
 	/**
 	 * @return number of Conditional Formatting rules.
 	 */
-	public int getNumbOfRules()
+	public int getNumberOfRules()
 	{
-		return cfAggregate.getRules().size();
-	}
-
-
-	/**
-	 * Do all possible cell merges between cells of the list so that:<br>
-	 * 	<li>if a cell range is completely inside of another cell range, it gets removed from the list 
-	 * 	<li>if two cells have a shared border, merge them into one bigger cell range
-	 * @param cellRangeList
-	 * @return updated List of cell ranges
-	 */
-	private static List mergeCellRanges(List cellRangeList)
-	{
-		boolean merged = false;
-
-		do
-		{
-			merged = false;
-
-			if( cellRangeList.size()>1 )
-			{
-				for( int i=0; i<cellRangeList.size(); i++)
-				{
-					CellRange range1 = (CellRange)cellRangeList.get(i);
-					for( int j=i+1; j<cellRangeList.size(); j++)
-					{
-						CellRange range2 = (CellRange)cellRangeList.get(j);
-
-						switch(range1.intersect(range2))
-						{
-							case CellRange.NO_INTERSECTION: 
-							{
-								if( range1.hasSharedBorder(range2))
-								{
-									cellRangeList.set(i, range1.createEnclosingCellRange(range2));
-									cellRangeList.remove(j--);
-									merged = true;
-								}
-								else
-								{
-									// No intersection and no shared border: do nothing 
-								}
-								break;
-							}
-							case CellRange.OVERLAP:
-							{
-								// TODO split and re-merge the intersected area
-								break;
-							}
-							case CellRange.INSIDE:
-							{
-								// Remove range2, since it is completely inside of range1
-								cellRangeList.remove(j--);
-								merged = true;
-								break;
-							}
-							case CellRange.ENCLOSES:
-							{
-								// range2 encloses range1, so replace it with the enclosing one
-								cellRangeList.set(i, range2);
-								cellRangeList.remove(j--);
-								merged = true;
-								break;
-							}
-						}
-					}
-				}
-			}
-		}
-		while( merged );
-
-		return cellRangeList;
-	}
-
-	/**
-	 * Convert a List of CellRange objects to an array of regions 
-	 *  
-	 * @param List of CellRange objects
-	 * @return regions
-	 */
-	private static Region[] toRegionArray(List cellRanges)
-	{
-		int size = cellRanges.size();
-		Region[] regions = new Region[size];
-
-		for (int i = 0; i != size; i++)
-		{
-			CellRange cr = (CellRange) cellRanges.get(i);
-			regions[i] = new Region(cr.getFirstRow(), cr.getFirstColumn(), 
-					cr.getLastRow(), cr.getLastColumn());
-		}
-		return regions;
-	}
-
-	/**
-	 * Convert array of regions to a List of CellRange objects
-	 *  
-	 * @param regions
-	 * @return List of CellRange objects
-	 */
-	private static List toCellRangeList(Region[] regions)
-	{
-		List cellRangeList = new ArrayList();
-		for( int i=0; i<regions.length; i++)
-		{
-			Region r = regions[i];
-			CellRange cr = new CellRange(r.getRowFrom(), r.getRowTo(), r.getColumnFrom(), r
-					.getColumnTo());
-			cellRangeList.add(cr);
-		}
-		return cellRangeList;
+		return cfAggregate.getNumberOfRules();
 	}
 
 	public String toString()

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java?rev=645088&r1=645087&r2=645088&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java Sat Apr  5 06:07:22 2008
@@ -18,231 +18,105 @@
 package org.apache.poi.hssf.usermodel;
 
 import java.util.List;
-import java.util.Stack;
 
 import org.apache.poi.hssf.model.FormulaParser;
+import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.CFRuleRecord;
+import org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator;
+import org.apache.poi.hssf.record.cf.BorderFormatting;
+import org.apache.poi.hssf.record.cf.FontFormatting;
+import org.apache.poi.hssf.record.cf.PatternFormatting;
 import org.apache.poi.hssf.record.formula.Ptg;
 
 /**
  * 
- * High level representation of Conditional Format  
+ * High level representation of Conditional Formatting Rule.
+ * It allows to specify formula based conditions for the Conditional Formatting
+ * and the formatting settings such as font, border and pattern.
  * 
  * @author Dmitriy Kumshayev
  */
 
-public class HSSFConditionalFormattingRule
+public final class HSSFConditionalFormattingRule
 {
-    public static final byte CELL_COMPARISON = CFRuleRecord.CONDITION_TYPE_CELL_VALUE_IS;
-    public static final byte FORMULA = CFRuleRecord.CONDITION_TYPE_FORMULA;
+    private static final byte CELL_COMPARISON = CFRuleRecord.CONDITION_TYPE_CELL_VALUE_IS;
+ 
 
-    public static final byte COMPARISON_OPERATOR_NO_COMPARISON = CFRuleRecord.COMPARISON_OPERATOR_NO_COMPARISON;
-    public static final byte COMPARISON_OPERATOR_BETWEEN 	   = CFRuleRecord.COMPARISON_OPERATOR_BETWEEN;
-    public static final byte COMPARISON_OPERATOR_NOT_BETWEEN   = CFRuleRecord.COMPARISON_OPERATOR_NOT_BETWEEN;
-    public static final byte COMPARISON_OPERATOR_EQUAL         = CFRuleRecord.COMPARISON_OPERATOR_EQUAL;
-    public static final byte COMPARISON_OPERATOR_NOT_EQUAL     = CFRuleRecord.COMPARISON_OPERATOR_NOT_EQUAL;
-    public static final byte COMPARISON_OPERATOR_GT            = CFRuleRecord.COMPARISON_OPERATOR_GT;
-    public static final byte COMPARISON_OPERATOR_LT            = CFRuleRecord.COMPARISON_OPERATOR_LT;
-    public static final byte COMPARISON_OPERATOR_GE            = CFRuleRecord.COMPARISON_OPERATOR_GE;
-    public static final byte COMPARISON_OPERATOR_LE            = CFRuleRecord.COMPARISON_OPERATOR_LE;
-    
-    
 
-	private CFRuleRecord cfRuleRecord;
-	private HSSFWorkbook workbook;
-	
-	protected HSSFConditionalFormattingRule(HSSFWorkbook workbook)
-	{
-		this.workbook = workbook;
-		this.cfRuleRecord = new CFRuleRecord();
-	}
 
-	protected HSSFConditionalFormattingRule(HSSFWorkbook workbook, CFRuleRecord cfRuleRecord)
-	{
-		this.workbook = workbook;
-		this.cfRuleRecord = cfRuleRecord;
-	}
+	private final CFRuleRecord cfRuleRecord;
+	private final Workbook workbook;
 
-	/** 
-	 *  Keep Font Formatting unchanged for this Conditional Formatting Rule 
-	 */
-	public void setFontFormattingUnchanged()
-	{
-		cfRuleRecord.setFontFormattingUnchanged();
+	HSSFConditionalFormattingRule(Workbook pWorkbook, CFRuleRecord pRuleRecord) {
+		workbook = pWorkbook;
+		cfRuleRecord = pRuleRecord;
 	}
-	/** 
-	 *  Keep Border Formatting unchanged for this Conditional Formatting Rule 
-	 */
-	public void setBorderFormattingUnchanged()
-	{
-		cfRuleRecord.setBorderFormattingUnchanged();
+	HSSFConditionalFormattingRule(Workbook pWorkbook, CFRuleRecord pRuleRecord, 
+			HSSFFontFormatting fontFmt, HSSFBorderFormatting bordFmt, HSSFPatternFormatting patternFmt) {
+		this(pWorkbook, pRuleRecord);
+		setFontFormatting(fontFmt);
+		setBorderFormatting(bordFmt);
+		setPatternFormatting(patternFmt);
 	}
-	/** 
-	 *  Keep Pattern Formatting unchanged for this Conditional Formatting Rule 
-	 */
-	public void setPatternFormattingUnchanged()
+
+	CFRuleRecord getCfRuleRecord()
 	{
-		cfRuleRecord.setPatternFormattingUnchanged();
+		return cfRuleRecord;
 	}
 	
-	public void setFontFormatting(HSSFFontFormatting fontFormatting)
-	{
-		if( fontFormatting!=null )
-		{
-			cfRuleRecord.setFontFormatting(fontFormatting.getFontFormattingBlock());
-		}
-		else
-		{
-			setFontFormattingUnchanged();
-		}
-	}
-	public void setBorderFormatting(HSSFBorderFormatting borderFormatting)
-	{
-		if( borderFormatting != null )
-		{
-			cfRuleRecord.setBorderFormatting(borderFormatting.getBorderFormattingBlock());
-		}
-		else
-		{
-			setBorderFormattingUnchanged();
-		}
-	}
-	public void setPatternFormatting(HSSFPatternFormatting patternFormatting)
-	{
-		if( patternFormatting != null)
-		{
-			cfRuleRecord.setPatternFormatting(patternFormatting.getPatternFormattingBlock());
-		}
-		else
-		{
-			setPatternFormattingUnchanged();
-		}
-	}
 	
-	public void setCellComparisonCondition(byte comparisonOperation, String formula1, String formula2)
+	/**
+	 * @param fontFmt pass <code>null</code> to signify 'font unchanged'
+	 */
+	public void setFontFormatting(HSSFFontFormatting fontFmt)
 	{
-		cfRuleRecord.setConditionType(CELL_COMPARISON);
-		cfRuleRecord.setComparisonOperation(comparisonOperation);
-		
-		// Formula 1
-		setFormula1(formula1);
-		
-		// Formula 2
-		setFormula1(formula2);
+		FontFormatting block = fontFmt==null ? null : fontFmt.getFontFormattingBlock();
+		cfRuleRecord.setFontFormatting(block);
 	}
-	
-	public void setFormulaCondition(String formula)
+	/**
+	 * @param borderFmt pass <code>null</code> to signify 'border unchanged'
+	 */
+	public void setBorderFormatting(HSSFBorderFormatting borderFmt)
 	{
-		cfRuleRecord.setConditionType(FORMULA);
-		// Formula 1
-		setFormula1(formula);
+		BorderFormatting block = borderFmt==null ? null : borderFmt.getBorderFormattingBlock();
+		cfRuleRecord.setBorderFormatting(block);
 	}
-	
-	public void setFormula1(String formula)
-	{
-		// Formula 1
-		if( formula != null)
-		{
-		    Stack parsedExpression = parseFormula(formula);
-			if( parsedExpression != null )
-			{
-				cfRuleRecord.setParsedExpression1(parsedExpression);
-			}
-			else
-			{
-				cfRuleRecord.setParsedExpression1(null);
-			}
-		}
-		else
-		{
-			cfRuleRecord.setParsedExpression1(null);
-		}
-	}
-	
-	public void setFormula2(String formula)
+	/**
+	 * @param patternFmt pass <code>null</code> to signify 'pattern unchanged'
+	 */
+	public void setPatternFormatting(HSSFPatternFormatting patternFmt)
 	{
-		// Formula 2
-		if( formula != null)
-		{
-		    Stack parsedExpression = parseFormula(formula);
-			if( parsedExpression != null )
-			{
-				cfRuleRecord.setParsedExpression2(parsedExpression);
-			}
-			else
-			{
-				cfRuleRecord.setParsedExpression2(null);
-			}
-		}
-		else
-		{
-			cfRuleRecord.setParsedExpression2(null);
-		}
+		PatternFormatting block = patternFmt==null ? null : patternFmt.getPatternFormattingBlock();
+		cfRuleRecord.setPatternFormatting(block);
 	}
 	
 	public String getFormula1()
 	{
-        return toFormulaString(cfRuleRecord.getParsedExpression1());
+		return toFormulaString(cfRuleRecord.getParsedExpression1());
 	}
 
 	public String getFormula2()
 	{
 		byte conditionType = cfRuleRecord.getConditionType();
-		switch(conditionType)
-		{
-			case CELL_COMPARISON:
-			{
-				byte comparisonOperation = cfRuleRecord.getComparisonOperation();
-				switch(comparisonOperation)
-				{
-					case COMPARISON_OPERATOR_BETWEEN:
-					case COMPARISON_OPERATOR_NOT_BETWEEN:
-						return toFormulaString(cfRuleRecord.getParsedExpression2());
-				}
+		if (conditionType == CELL_COMPARISON) {
+			byte comparisonOperation = cfRuleRecord.getComparisonOperation();
+			switch(comparisonOperation)
+			{
+				case ComparisonOperator.BETWEEN:
+				case ComparisonOperator.NOT_BETWEEN:
+					return toFormulaString(cfRuleRecord.getParsedExpression2());
 			}
 		}
 		return null;
 	}
 
-	private String toFormulaString(List parsedExpression)
+	private String toFormulaString(Ptg[] parsedExpression)
 	{
 		String formula = null;
 		if(parsedExpression!=null)
 		{
-	        formula = FormulaParser.toFormulaString(workbook.getWorkbook(),parsedExpression);
+		formula = FormulaParser.toFormulaString(workbook, parsedExpression);
 		}
 		return formula;
 	}
-	
-
-	private Stack parseFormula(String formula2)
-	{
-		FormulaParser parser = 
-			new FormulaParser(formula2, workbook.getWorkbook());
-		parser.parse();
-
-		Stack parsedExpression = convertToTokenStack(parser.getRPNPtg());
-	    parsedExpression = convertToTokenStack(parser.getRPNPtg());
-		return parsedExpression;
-	}
-
-	private static Stack convertToTokenStack(Ptg[] ptgs)
-	{
-		if( ptgs != null)
-		{
-			Stack parsedExpression = new Stack();
-			// fill the Ptg Stack with Ptgs of new formula
-			for (int k = 0; k < ptgs.length; k++) 
-			{
-			    parsedExpression.push(ptgs[ k ]);
-			}
-			return parsedExpression;
-		}
-		else
-		{
-			return null;
-		}
-	}
-	
-	
 }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java?rev=645088&r1=645087&r2=645088&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java Sat Apr  5 06:07:22 2008
@@ -58,7 +58,7 @@
      */
     HSSFPatriarch(HSSFSheet sheet, EscherAggregate boundAggregate)
     {
-    	this.boundAggregate = boundAggregate;
+        this.boundAggregate = boundAggregate;
         this.sheet = sheet;
     }
 
@@ -197,29 +197,29 @@
      *  to work on some charts so far)
      */
     public boolean containsChart() {
-    	// TODO - support charts properly in usermodel
-    	
-    	// We're looking for a EscherOptRecord
-    	EscherOptRecord optRecord = (EscherOptRecord)
-    		boundAggregate.findFirstWithId(EscherOptRecord.RECORD_ID);
-    	if(optRecord == null) {
-    		// No opt record, can't have chart
-    		return false;
-    	}
-    	
-    	for(Iterator it = optRecord.getEscherProperties().iterator(); it.hasNext();) {
-    		EscherProperty prop = (EscherProperty)it.next();
-    		if(prop.getPropertyNumber() == 896 && prop.isComplex()) {
-    			EscherComplexProperty cp = (EscherComplexProperty)prop;
-    			String str = StringUtil.getFromUnicodeLE(cp.getComplexData());
-    			System.err.println(str);
-    			if(str.equals("Chart 1\0")) {
-    				return true;
-    			}
-    		}
-    	}
+        // TODO - support charts properly in usermodel
+        
+        // We're looking for a EscherOptRecord
+        EscherOptRecord optRecord = (EscherOptRecord)
+            boundAggregate.findFirstWithId(EscherOptRecord.RECORD_ID);
+        if(optRecord == null) {
+            // No opt record, can't have chart
+            return false;
+        }
+        
+        for(Iterator it = optRecord.getEscherProperties().iterator(); it.hasNext();) {
+            EscherProperty prop = (EscherProperty)it.next();
+            if(prop.getPropertyNumber() == 896 && prop.isComplex()) {
+                EscherComplexProperty cp = (EscherComplexProperty)prop;
+                String str = StringUtil.getFromUnicodeLE(cp.getComplexData());
+                //System.err.println(str);
+                if(str.equals("Chart 1\0")) {
+                    return true;
+                }
+            }
+        }
 
-    	return false;
+        return false;
     }
 
     /**
@@ -258,6 +258,6 @@
      * Returns the aggregate escher record we're bound to 
      */
     protected EscherAggregate _getBoundAggregate() {
-    	return boundAggregate;
+        return boundAggregate;
     }
 }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java?rev=645088&r1=645087&r2=645088&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java Sat Apr  5 06:07:22 2008
@@ -36,6 +36,7 @@
 import org.apache.poi.hssf.model.Sheet;
 import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.CellValueRecordInterface;
+import org.apache.poi.hssf.record.CFRuleRecord;
 import org.apache.poi.hssf.record.DVALRecord;
 import org.apache.poi.hssf.record.DVRecord;
 import org.apache.poi.hssf.record.EOFRecord;
@@ -1106,8 +1107,8 @@
      * @param leftcol the left column to show in desktop window pane
      */
     public void showInPane(short toprow, short leftcol){
-        this.sheet.setTopRow((short)toprow);
-        this.sheet.setLeftCol((short)leftcol);
+        this.sheet.setTopRow(toprow);
+        this.sheet.setLeftCol(leftcol);
         }
 
     /**
@@ -1454,7 +1455,7 @@
           int i = 0;
           while (iterator.hasNext()) {
             PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
-            returnValue[i++] = (int)breakItem.main;
+            returnValue[i++] = breakItem.main;
           }
           return returnValue;
         }
@@ -1822,7 +1823,7 @@
      *
      * @return cell comment or <code>null</code> if not found
      */
-     public HSSFComment getCellComment(int row, int column){
+     public HSSFComment getCellComment(int row, int column) {
         // Don't call findCellComment directly, otherwise
         //  two calls to this method will result in two
         //  new HSSFComment instances, which is bad
@@ -1846,25 +1847,26 @@
       * with a cell comparison operator and
       * formatting rules such as font format, border format and pattern format
       *
-      * @param comparisonOperation - one of the following values: <p>
-      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}</li>
-      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN}</li>
-      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_EQUAL}</li>
-      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_EQUAL}</li>
-      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GT}</li>
-      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LT}</li>
-      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GE}</li>
-      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LE}</li>
+      * @param comparisonOperation - a constant value from
+      *         <tt>{@link HSSFConditionalFormattingRule.ComparisonOperator}</tt>: <p>
+      * <ul>
+      *         <li>BETWEEN</li>
+      *         <li>NOT_BETWEEN</li>
+      *         <li>EQUAL</li>
+      *         <li>NOT_EQUAL</li>
+      *         <li>GT</li>
+      *         <li>LT</li>
+      *         <li>GE</li>
+      *         <li>LE</li>
+      * </ul>
       * </p>
       * @param formula1 - formula for the valued, compared with the cell
       * @param formula2 - second formula (only used with
       * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}) and
       * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN} operations)
-      * @param fontFmt - font formatting rules
-      * @param bordFmt - border formatting rules
-      * @param patternFmt - pattern formatting rules
-      * @return
-      *
+      * @param fontFmt - font formatting rules (may be <code>null</code>)
+      * @param bordFmt - border formatting rules (may be <code>null</code>)
+      * @param patternFmt - pattern formatting rules (may be <code>null</code>)
       */
      public HSSFConditionalFormattingRule createConditionalFormattingRule(
              byte comparisonOperation,
@@ -1872,14 +1874,11 @@
              String formula2,
              HSSFFontFormatting fontFmt,
              HSSFBorderFormatting bordFmt,
-             HSSFPatternFormatting patternFmt)
-     {
-         HSSFConditionalFormattingRule cf = new HSSFConditionalFormattingRule(workbook);
-         cf.setFontFormatting(fontFmt);
-         cf.setBorderFormatting(bordFmt);
-         cf.setPatternFormatting(patternFmt);
-         cf.setCellComparisonCondition(comparisonOperation, formula1, formula2);
-         return cf;
+             HSSFPatternFormatting patternFmt) {
+    	 
+        Workbook wb = workbook.getWorkbook();
+        CFRuleRecord rr = CFRuleRecord.create(wb, comparisonOperation, formula1, formula2);
+        return new HSSFConditionalFormattingRule(wb, rr, fontFmt, bordFmt, patternFmt);
      }
 
      /**
@@ -1888,38 +1887,19 @@
       *
       * The formatting rules are applied by Excel when the value of the formula not equal to 0.
       *
-      * @param comparisonOperation - one of the following values: <p>
-      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}</li>
-      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN}</li>
-      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_EQUAL}</li>
-      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_EQUAL}</li>
-      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GT}</li>
-      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LT}</li>
-      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GE}</li>
-      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LE}</li>
-      * </p>
-      * @param formula1 - formula for the valued, compared with the cell
-      * @param formula2 - second formula (only used with
-      * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}) and
-      * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN} operations)
-      * @param fontFmt - font formatting rules
-      * @param bordFmt - border formatting rules
-      * @param patternFmt - pattern formatting rules
-      * @return
-      *
+      * @param formula - formula for the valued, compared with the cell
+      * @param fontFmt - font formatting rules (may be <code>null</code>)
+      * @param bordFmt - border formatting rules (may be <code>null</code>)
+      * @param patternFmt - pattern formatting rules (may be <code>null</code>)
       */
      public HSSFConditionalFormattingRule createConditionalFormattingRule(
              String formula,
              HSSFFontFormatting fontFmt,
              HSSFBorderFormatting bordFmt,
-             HSSFPatternFormatting patternFmt)
-     {
-         HSSFConditionalFormattingRule cf = new HSSFConditionalFormattingRule(workbook);
-         cf.setFontFormatting(fontFmt);
-         cf.setBorderFormatting(bordFmt);
-         cf.setPatternFormatting(patternFmt);
-         cf.setFormulaCondition(formula);
-         return cf;
+             HSSFPatternFormatting patternFmt) {
+         Workbook wb = workbook.getWorkbook();
+         CFRuleRecord rr = CFRuleRecord.create(wb, formula);
+         return new HSSFConditionalFormattingRule(wb, rr, fontFmt, bordFmt, patternFmt);
      }
 
      /**
@@ -1934,8 +1914,7 @@
       * @param cf HSSFConditionalFormatting object
       * @return index of the new Conditional Formatting object
       */
-     public int addConditionalFormatting( HSSFConditionalFormatting cf )
-     {
+     public int addConditionalFormatting( HSSFConditionalFormatting cf ) {
          CFRecordsAggregate cfraClone = cf.getCFRecordsAggregate().cloneCFAggregate();
 
          return sheet.addConditionalFormatting(cfraClone);
@@ -1945,46 +1924,46 @@
       * Allows to add a new Conditional Formatting set to the sheet.
       *
       * @param regions - list of rectangular regions to apply conditional formatting rules
-      * @param cfRules - set of up to three conditional formatting rules
+      * @param hcfRules - set of up to three conditional formatting rules
       *
       * @return index of the newly created Conditional Formatting object
       */
 
-     public int addConditionalFormatting( Region [] regions, HSSFConditionalFormattingRule [] cfRules )
-     {
-         HSSFConditionalFormatting cf = new HSSFConditionalFormatting(this);
-         cf.setFormattingRegions(regions);
-         if( cfRules != null )
-         {
-             for( int i=0; i!= cfRules.length; i++ )
-             {
-                 cf.addRule(cfRules[i]);
-             }
-         }
-         return sheet.addConditionalFormatting(cf.getCFRecordsAggregate());
+    public int addConditionalFormatting(Region [] regions, HSSFConditionalFormattingRule [] hcfRules) {
+        if (regions == null) {
+            throw new IllegalArgumentException("regions must not be null");
+        }
+        if (hcfRules == null) {
+            throw new IllegalArgumentException("hcfRules must not be null");
+        }
+
+        CFRuleRecord[] rules = new CFRuleRecord[hcfRules.length];
+        for (int i = 0; i != hcfRules.length; i++) {
+            rules[i] = hcfRules[i].getCfRuleRecord();
+        }
+        CFRecordsAggregate cfra = new CFRecordsAggregate(regions, rules);
+        return sheet.addConditionalFormatting(cfra);
      }
 
     /**
      * gets Conditional Formatting object at a particular index
-     * @param index of the Conditional Formatting object to fetch
+     * 
+     * @param index
+     *            of the Conditional Formatting object to fetch
      * @return Conditional Formatting object
      */
-
-    public HSSFConditionalFormatting getConditionalFormattingAt(int index)
-    {
+    public HSSFConditionalFormatting getConditionalFormattingAt(int index) {
         CFRecordsAggregate cf = sheet.getCFRecordsAggregateAt(index);
-        if( cf != null )
-        {
-            return new HSSFConditionalFormatting(this,cf);
+        if (cf == null) {
+            return null;
         }
-        return null;
+        return new HSSFConditionalFormatting(this,cf);
     }
 
     /**
      * @return number of Conditional Formatting objects of the sheet
      */
-    public int getNumConditionalFormattings()
-    {
+    public int getNumConditionalFormattings() {
         return sheet.getNumConditionalFormattings();
     }
 
@@ -1992,8 +1971,7 @@
      * removes a Conditional Formatting object by index
      * @param index of a Conditional Formatting object to remove
      */
-    public void removeConditionalFormatting(int index)
-    {
+    public void removeConditionalFormatting(int index) {
         sheet.removeConditionalFormatting(index);
     }
 }

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java?rev=645088&r1=645087&r2=645088&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java Sat Apr  5 06:07:22 2008
@@ -266,6 +266,31 @@
     }
 
     /**
+     * Removes the specified shape from this sheet.
+     *
+     * @param shape shape to be removed from this sheet, if present.
+     * @return <tt>true</tt> if the shape was deleted.
+     */
+    public boolean removeShape(Shape shape) {
+        PPDrawing ppdrawing = getPPDrawing();
+
+        EscherContainerRecord dg = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
+        EscherContainerRecord spgr = null;
+
+        for (Iterator it = dg.getChildRecords().iterator(); it.hasNext();) {
+            EscherRecord rec = (EscherRecord) it.next();
+            if (rec.getRecordId() == EscherContainerRecord.SPGR_CONTAINER) {
+                spgr = (EscherContainerRecord) rec;
+                break;
+            }
+        }
+        if(spgr == null) return false;
+
+        List lst = spgr.getChildRecords();
+        return lst.remove(shape.getSpContainer());
+    }
+
+    /**
      * Return the master sheet .
      */
     public abstract MasterSheet getMasterSheet();

Modified: poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java?rev=645088&r1=645087&r2=645088&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java (original)
+++ poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java Sat Apr  5 06:07:22 2008
@@ -26,6 +26,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.ByteArrayInputStream;
 import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 
 /**
@@ -278,5 +279,32 @@
 
         line = (Line)grshape[1];
         assertEquals(new Rectangle(300, 300, 500, 0), line.getAnchor());
+    }
+
+    /**
+     * Test functionality of Sheet.removeShape(Shape shape)
+     */
+    public void testRemoveShapes() throws IOException {
+        String file = System.getProperty("HSLF.testdata.path")+ "/with_textbox.ppt";
+        SlideShow ppt = new SlideShow(new HSLFSlideShow(file));
+        Slide sl = ppt.getSlides()[0];
+        Shape[] sh = sl.getShapes();
+        assertEquals("expected four shaped in " + file, 4, sh.length);
+        //remove all
+        for (int i = 0; i < sh.length; i++) {
+            boolean ok = sl.removeShape(sh[i]);
+            assertTrue("Failed to delete shape #" + i, ok);
+        }
+        //now Slide.getShapes() should return an empty array
+        assertEquals("expected 0 shaped in " + file, 0, sl.getShapes().length);
+
+        //serialize and read again. The file should be readable and contain no shapes
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        ppt.write(out);
+        out.close();
+
+        ppt = new SlideShow(new ByteArrayInputStream(out.toByteArray()));
+        sl = ppt.getSlides()[0];
+        assertEquals("expected 0 shaped in " + file, 0, sl.getShapes().length);
     }
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java?rev=645088&r1=645087&r2=645088&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java Sat Apr  5 06:07:22 2008
@@ -14,7 +14,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
+
 package org.apache.poi.hssf.model;
 
 import junit.framework.AssertionFailedError;
@@ -54,7 +54,7 @@
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 
 /**
- * Test the low level formula parser functionality. High level tests are to 
+ * Test the low level formula parser functionality. High level tests are to
  *  be done via usermodel/HSSFCell.setFormulaValue() .
  * Some tests are also done in scratchpad, if they need
  *  HSSFFormulaEvaluator, which is there
@@ -71,7 +71,7 @@
         assertNotNull("Ptg array should not be null", result);
         return result;
     }
-    
+
     public void testSimpleFormula() {
         FormulaParser fp = new FormulaParser("2+2",null);
         fp.parse();
@@ -86,9 +86,9 @@
         assertTrue("",(ptgs[0] instanceof IntPtg));
         assertTrue("",(ptgs[1] instanceof IntPtg));
         assertTrue("",(ptgs[2] instanceof AddPtg));
-        
+
     }
-    
+
     public void testFormulaWithSpace2() {
         Ptg[] ptgs;
         FormulaParser fp;
@@ -97,7 +97,7 @@
         ptgs = fp.getRPNPtg();
         assertTrue("five tokens expected, got "+ptgs.length,ptgs.length == 5);
     }
-    
+
      public void testFormulaWithSpaceNRef() {
         Ptg[] ptgs;
         FormulaParser fp;
@@ -106,7 +106,7 @@
         ptgs = fp.getRPNPtg();
         assertTrue("two tokens expected, got "+ptgs.length,ptgs.length == 2);
     }
-    
+
     public void testFormulaWithString() {
         Ptg[] ptgs;
         FormulaParser fp;
@@ -172,7 +172,7 @@
 		
 		
 	}
-    
+
 	/**
 	 * Make sure the ptgs are generated properly with two functions embedded
 	 *
@@ -225,7 +225,7 @@
 		assertEquals("4 Ptgs expected", 4, asts.length);
 		
 	}
-	 
+	
 	/**
 	 * Bug Reported by xt-jens.riis@nokia.com (Jens Riis)
 	 * Refers to Bug <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=17582">#17582</a>
@@ -247,7 +247,7 @@
 		
 					
 	}
-        
+
 	public void testSimpleLogical() {
 		FormulaParser fp=new FormulaParser("IF(A1<A2,B1,B2)",null);
 		fp.parse();
@@ -255,10 +255,10 @@
       assertTrue("Ptg array should not be null", ptgs !=null);
       assertEquals("Ptg array length", 9, ptgs.length);
       assertEquals("3rd Ptg is less than",LessThanPtg.class,ptgs[2].getClass());
-            
-           
+
+
 	}
-	 
+	
 	public void testParenIf() {
 		FormulaParser fp=new FormulaParser("IF((A1+A2)<=3,\"yes\",\"no\")",null);
 		fp.parse();
@@ -281,7 +281,7 @@
 		assertEquals("15th Ptg is not the inner IF variable function ptg",FuncVarPtg.class,ptgs[14].getClass());
 		
 	}
-	    
+	
     public void testMacroFunction() {
         Workbook w = Workbook.createWorkbook();
         FormulaParser fp = new FormulaParser("FOO()", w);
@@ -291,7 +291,7 @@
         // the name gets encoded as the first arg
         NamePtg tname = (NamePtg) ptg[0];
         assertEquals("FOO", tname.toFormulaString(w));
-        
+
         AbstractFunctionPtg tfunc = (AbstractFunctionPtg) ptg[1];
         assertTrue(tfunc.isExternalFunction());
     }
@@ -302,9 +302,9 @@
         Ptg[] ptg = fp.getRPNPtg();
         assertTrue("first ptg is string",ptg[0] instanceof StringPtg);
         assertTrue("second ptg is string",ptg[1] instanceof StringPtg);
-        
+
     }
-    
+
     public void testConcatenate(){
          FormulaParser fp = new FormulaParser("CONCATENATE(\"first\",\"second\")",null);
          fp.parse();
@@ -312,7 +312,7 @@
         assertTrue("first ptg is string",ptg[0] instanceof StringPtg);
         assertTrue("second ptg is string",ptg[1] instanceof StringPtg);
     }
-    
+
     public void testWorksheetReferences()
     {
     	HSSFWorkbook wb = new HSSFWorkbook();
@@ -330,7 +330,7 @@
     	cell = row.createCell((short)1);
     	cell.setCellFormula("'Quotes Needed Here &#$@'!A1");
     }
-    
+
     public void testUnaryMinus()
     {
 		FormulaParser fp = new FormulaParser("-A1", null);
@@ -340,7 +340,7 @@
 		assertTrue("first ptg is reference",ptg[0] instanceof ReferencePtg);
 		assertTrue("second ptg is Minus",ptg[1] instanceof UnaryMinusPtg);
      }
-    
+
     public void testUnaryPlus()
     {
 		FormulaParser fp = new FormulaParser("+A1", null);
@@ -350,14 +350,14 @@
 		assertTrue("first ptg is reference",ptg[0] instanceof ReferencePtg);
 		assertTrue("second ptg is Plus",ptg[1] instanceof UnaryPlusPtg);
      }
-    
+
 	public void testLeadingSpaceInString()
 	{
 		String value = "  hi  ";
 		FormulaParser fp = new FormulaParser("\"" + value + "\"", null);
 		fp.parse();
 		Ptg[] ptg = fp.getRPNPtg();
-    
+
 		assertTrue("got 1 ptg", ptg.length == 1);
 		assertTrue("ptg0 is a StringPtg", ptg[0] instanceof StringPtg);
 		assertTrue("ptg0 contains exact value", ((StringPtg)ptg[0]).getValue().equals(value));
@@ -368,14 +368,14 @@
 		FormulaParser fp = new FormulaParser("lookup(A1, A3:A52, B3:B52)", null);
 		fp.parse();
 		Ptg[] ptg = fp.getRPNPtg();
-    
+
 		assertTrue("got 4 ptg", ptg.length == 4);
 		assertTrue("ptg0 has Value class", ptg[0].getPtgClass() == Ptg.CLASS_VALUE);
 		
 		fp = new FormulaParser("match(A1, A3:A52)", null);
 		fp.parse();
 		ptg = fp.getRPNPtg();
-    
+
 		assertTrue("got 3 ptg", ptg.length == 3);
 		assertTrue("ptg0 has Value class", ptg[0].getPtgClass() == Ptg.CLASS_VALUE);
 	}
@@ -521,77 +521,77 @@
         System.out.println("Testing org.apache.poi.hssf.record.formula.FormulaParser");
         junit.textui.TestRunner.run(TestFormulaParser.class);
     }
-    
+
     public void testNumbers() {
         HSSFWorkbook wb = new HSSFWorkbook();
-        
+
         wb.createSheet("Cash_Flow");
-        
+
         HSSFSheet sheet = wb.createSheet("Test");
         HSSFRow row = sheet.createRow(0);
         HSSFCell cell = row.createCell((short)0);
         String formula = null;
-        
+
         // starts from decimal point
-        
+
         cell.setCellFormula(".1");
         formula = cell.getCellFormula();
         assertEquals("0.1", formula);
-        
+
         cell.setCellFormula("+.1");
         formula = cell.getCellFormula();
         assertEquals("+0.1", formula);
-        
+
         cell.setCellFormula("-.1");
         formula = cell.getCellFormula();
         assertEquals("-0.1", formula);
-        
+
         // has exponent
-        
+
         cell.setCellFormula("10E1");
         formula = cell.getCellFormula();
         assertEquals("100.0", formula);
-        
+
         cell.setCellFormula("10E+1");
         formula = cell.getCellFormula();
         assertEquals("100.0", formula);
-        
+
         cell.setCellFormula("10E-1");
         formula = cell.getCellFormula();
         assertEquals("1.0", formula);
     }
-    
+
     public void testRanges() {
         HSSFWorkbook wb = new HSSFWorkbook();
-        
+
         wb.createSheet("Cash_Flow");
-        
+
         HSSFSheet sheet = wb.createSheet("Test");
         HSSFRow row = sheet.createRow(0);
         HSSFCell cell = row.createCell((short)0);
         String formula = null;
-        
+
         cell.setCellFormula("A1.A2");
         formula = cell.getCellFormula();
         assertEquals("A1:A2", formula);
-        
+
         cell.setCellFormula("A1..A2");
         formula = cell.getCellFormula();
         assertEquals("A1:A2", formula);
-        
+
         cell.setCellFormula("A1...A2");
         formula = cell.getCellFormula();
         assertEquals("A1:A2", formula);
     }
-    
+
     /**
      * Test for bug observable at svn revision 618865 (5-Feb-2008)<br/>
      * a formula consisting of a single no-arg function got rendered without the function braces
      */
     public void testToFormulaStringZeroArgFunction() {
-        
+
         Workbook book = Workbook.createWorkbook(); // not really used in this test
-        
+
         Ptg[] ptgs = {
                 new FuncPtg(10, 0),
         };
@@ -610,21 +610,21 @@
         assertEquals(2, ptgs.length);
         assertEquals(ptgs[0].getClass(), IntPtg.class);
         assertEquals(ptgs[1].getClass(), PercentPtg.class);
-        
-        
-        // double percent OK 
+
+
+        // double percent OK
         ptgs = parseFormula("12345.678%%");
         assertEquals(3, ptgs.length);
         assertEquals(ptgs[0].getClass(), NumberPtg.class);
         assertEquals(ptgs[1].getClass(), PercentPtg.class);
         assertEquals(ptgs[2].getClass(), PercentPtg.class);
-        
+
         // percent of a bracketed expression
         ptgs = parseFormula("(A1+35)%*B1%");
         assertEquals(8, ptgs.length);
         assertEquals(ptgs[4].getClass(), PercentPtg.class);
         assertEquals(ptgs[6].getClass(), PercentPtg.class);
-        
+
         // percent of a text quantity
         ptgs = parseFormula("\"8.75\"%");
         assertEquals(2, ptgs.length);
@@ -641,64 +641,64 @@
 
         //
         // things that parse OK but would *evaluate* to an error
-        
+
         ptgs = parseFormula("\"abc\"%");
         assertEquals(2, ptgs.length);
         assertEquals(ptgs[0].getClass(), StringPtg.class);
         assertEquals(ptgs[1].getClass(), PercentPtg.class);
-        
+
         ptgs = parseFormula("#N/A%");
         assertEquals(2, ptgs.length);
         assertEquals(ptgs[0].getClass(), ErrPtg.class);
         assertEquals(ptgs[1].getClass(), PercentPtg.class);
     }
-    
+
     /**
      * Tests combinations of various operators in the absence of brackets
      */
     public void testPrecedenceAndAssociativity() {
 
         Class[] expClss;
-        
+
         // TRUE=TRUE=2=2  evaluates to FALSE
-        expClss = new Class[] { BoolPtg.class, BoolPtg.class, EqualPtg.class, 
+        expClss = new Class[] { BoolPtg.class, BoolPtg.class, EqualPtg.class,
                 IntPtg.class, EqualPtg.class, IntPtg.class, EqualPtg.class,  };
         confirmTokenClasses("TRUE=TRUE=2=2", expClss);
-       
+
 
         //  2^3^2    evaluates to 64 not 512
-        expClss = new Class[] { IntPtg.class, IntPtg.class, PowerPtg.class, 
+        expClss = new Class[] { IntPtg.class, IntPtg.class, PowerPtg.class,
                 IntPtg.class, PowerPtg.class, };
         confirmTokenClasses("2^3^2", expClss);
-        
+
         // "abc" & 2 + 3 & "def"   evaluates to "abc5def"
-        expClss = new Class[] { StringPtg.class, IntPtg.class, IntPtg.class, 
+        expClss = new Class[] { StringPtg.class, IntPtg.class, IntPtg.class,
                 AddPtg.class, ConcatPtg.class, StringPtg.class, ConcatPtg.class, };
         confirmTokenClasses("\"abc\"&2+3&\"def\"", expClss);
-        
-        
+
+
         //  (1 / 2) - (3 * 4)
-        expClss = new Class[] { IntPtg.class, IntPtg.class, DividePtg.class, 
+        expClss = new Class[] { IntPtg.class, IntPtg.class, DividePtg.class,
                 IntPtg.class, IntPtg.class, MultiplyPtg.class, SubtractPtg.class, };
         confirmTokenClasses("1/2-3*4", expClss);
-        
+
         // 2 * (2^2)
         expClss = new Class[] { IntPtg.class, IntPtg.class, IntPtg.class, PowerPtg.class, MultiplyPtg.class, };
         // NOT: (2 *2) ^ 2 -> int int multiply int power
         confirmTokenClasses("2*2^2", expClss);
-        
+
         //  2^200% -> 2 not 1.6E58
         expClss = new Class[] { IntPtg.class, IntPtg.class, PercentPtg.class, PowerPtg.class, };
         confirmTokenClasses("2^200%", expClss);
     }
-    
+
     private static void confirmTokenClasses(String formula, Class[] expectedClasses) {
         Ptg[] ptgs = parseFormula(formula);
         assertEquals(expectedClasses.length, ptgs.length);
         for (int i = 0; i < expectedClasses.length; i++) {
             if(expectedClasses[i] != ptgs[i].getClass()) {
                 fail("difference at token[" + i + "]: expected ("
-                    + expectedClasses[i].getName() + ") but got (" 
+                    + expectedClasses[i].getName() + ") but got ("
                     + ptgs[i].getClass().getName() + ")");
             }
         }
@@ -718,38 +718,38 @@
 
     public void testParseNumber() {
         IntPtg ip;
-        
+
         // bug 33160
         ip = (IntPtg) parseSingleToken("40", IntPtg.class);
         assertEquals(40, ip.getValue());
         ip = (IntPtg) parseSingleToken("40000", IntPtg.class);
         assertEquals(40000, ip.getValue());
-        
+
         // check the upper edge of the IntPtg range:
         ip = (IntPtg) parseSingleToken("65535", IntPtg.class);
         assertEquals(65535, ip.getValue());
         NumberPtg np = (NumberPtg) parseSingleToken("65536", NumberPtg.class);
         assertEquals(65536, np.getValue(), 0);
-        
+
         np = (NumberPtg) parseSingleToken("65534.6", NumberPtg.class);
         assertEquals(65534.6, np.getValue(), 0);
     }
-    
+
     public void testMissingArgs() {
-        
+
         Class[] expClss;
-        
-        expClss = new Class[] { ReferencePtg.class, MissingArgPtg.class, ReferencePtg.class, 
+
+        expClss = new Class[] { ReferencePtg.class, MissingArgPtg.class, ReferencePtg.class,
                 FuncVarPtg.class, };
         confirmTokenClasses("if(A1, ,C1)", expClss);
-        
+
         expClss = new Class[] { MissingArgPtg.class, AreaPtg.class, MissingArgPtg.class,
                 FuncVarPtg.class, };
         confirmTokenClasses("counta( , A1:B2, )", expClss);
     }
 
     public void testParseErrorLiterals() {
-        
+
         confirmParseErrorLiteral(ErrPtg.NULL_INTERSECTION, "#NULL!");
         confirmParseErrorLiteral(ErrPtg.DIV_ZERO, "#DIV/0!");
         confirmParseErrorLiteral(ErrPtg.VALUE_INVALID, "#VALUE!");
@@ -762,7 +762,7 @@
     private static void confirmParseErrorLiteral(ErrPtg expectedToken, String formula) {
         assertEquals(expectedToken, parseSingleToken(formula, ErrPtg.class));
     }
-    
+
     /**
      * To aid readability the parameters have been encoded with single quotes instead of double
      * quotes.  This method converts single quotes to double quotes before performing the parse
@@ -772,23 +772,23 @@
         // formula: internal quotes become double double, surround with double quotes
         String formula = '"' + singleQuotedValue.replaceAll("'", "\"\"") + '"';
         String expectedValue = singleQuotedValue.replace('\'', '"');
-        
+
         StringPtg sp = (StringPtg) parseSingleToken(formula, StringPtg.class);
         assertEquals(expectedValue, sp.getValue());
     }
-    
+
     public void testPaseStringLiterals() {
         confirmStringParse("goto considered harmful");
-        
+
         confirmStringParse("goto 'considered' harmful");
-        
+
         confirmStringParse("");
         confirmStringParse("'");
         confirmStringParse("''");
         confirmStringParse("' '");
         confirmStringParse(" ' ");
     }
-    
+
     public void testParseSumIfSum() {
         String formulaString;
         Ptg[] ptgs;
@@ -809,14 +809,14 @@
         parseExpectedException("1 + #N / A * 2");
         parseExpectedException("#value?");
         parseExpectedException("#DIV/ 0+2");
-        
-        
+
+
         if (false) { // TODO - add functionality to detect func arg count mismatch
             parseExpectedException("IF(TRUE)");
             parseExpectedException("countif(A1:B5, C1, D1)");
         }
     }
-    
+
     private static void parseExpectedException(String formula) {
         try {
             parseFormula(formula);
@@ -831,11 +831,11 @@
     }
 
     public void testSetFormulaWithRowBeyond32768_Bug44539() {
-        
+
         HSSFWorkbook wb = new HSSFWorkbook();
         HSSFSheet sheet = wb.createSheet();
         wb.setSheetName(0, "Sheet1");
-        
+
         HSSFRow row = sheet.createRow(0);
         HSSFCell cell = row.createCell((short)0);
         cell.setCellFormula("SUM(A32769:A32770)");
@@ -862,11 +862,11 @@
             throw e;
         }
         // FormulaParser strips spaces anyway
-        assertEquals("4", formulaString); 
+        assertEquals("4", formulaString);
 
         ptgs = new Ptg[] { new IntPtg(3), spacePtg, new IntPtg(4), spacePtg, new AddPtg()};
         formulaString = FormulaParser.toFormulaString(null, ptgs);
-        assertEquals("3+4", formulaString); 
+        assertEquals("3+4", formulaString);
     }
 
     /**
@@ -875,7 +875,7 @@
     public void testTooFewOperandArgs() {
         // Simulating badly encoded cell formula of "=/1"
         // Not sure if Excel could ever produce this
-        Ptg[] ptgs = { 
+        Ptg[] ptgs = {
                 // Excel would probably have put tMissArg here
                 new IntPtg(1),
                 new DividePtg(),

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java?rev=645088&r1=645087&r2=645088&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java Sat Apr  5 06:07:22 2008
@@ -17,7 +17,9 @@
 
 package org.apache.poi.hssf.record;
 
+import org.apache.poi.hssf.record.aggregates.AllRecordAggregateTests;
 import org.apache.poi.hssf.record.formula.AllFormulaTests;
+import org.apache.poi.hssf.record.formula.functions.AllIndividualFunctionEvaluationTests;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -33,7 +35,8 @@
 		TestSuite result = new TestSuite(AllRecordTests.class.getName());
 
 		result.addTest(AllFormulaTests.suite());
-		
+		result.addTest(AllRecordAggregateTests.suite());
+
 		result.addTestSuite(TestAreaFormatRecord.class);
 		result.addTestSuite(TestAreaRecord.class);
 		result.addTestSuite(TestAxisLineFormatRecord.class);
@@ -45,6 +48,8 @@
 		result.addTestSuite(TestBarRecord.class);
 		result.addTestSuite(TestBoundSheetRecord.class);
 		result.addTestSuite(TestCategorySeriesAxisRecord.class);
+		result.addTestSuite(TestCFHeaderRecord.class);
+		result.addTestSuite(TestCFRuleRecord.class);
 		result.addTestSuite(TestChartRecord.class);
 		result.addTestSuite(TestChartTitleFormatRecord.class);
 		result.addTestSuite(TestCommonObjectDataSubRecord.class);

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java?rev=645088&r1=645087&r2=645088&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java Sat Apr  5 06:07:22 2008
@@ -17,9 +17,6 @@
 
 package org.apache.poi.hssf.record;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.record.cf.CellRange;
@@ -30,116 +27,114 @@
  *
  * @author Dmitriy Kumshayev 
  */
-public class TestCFHeaderRecord
-        extends TestCase
+public final class TestCFHeaderRecord extends TestCase
 {
 
-    public TestCFHeaderRecord(String name)
-    {
-        super(name);
-    }
-
-    public void testCreateCFHeaderRecord () 
-    {
-        CFHeaderRecord record = new CFHeaderRecord();
-        List ranges = new ArrayList();
-        ranges.add(new CellRange(0,-1,(short)5,(short)5));
-        ranges.add(new CellRange(0,-1,(short)6,(short)6));
-        ranges.add(new CellRange(0,1,(short)0,(short)1));
-        ranges.add(new CellRange(0,1,(short)2,(short)3));
-        ranges.add(new CellRange(2,3,(short)0,(short)1));
-        ranges.add(new CellRange(2,3,(short)2,(short)3));
-        record.setCellRanges(ranges);
-        ranges = record.getCellRanges();
-        assertEquals(6,ranges.size());
-        CellRange enclosingCellRange = record.getEnclosingCellRange();
-        assertEquals(0, enclosingCellRange.getFirstRow());
-        assertEquals(-1, enclosingCellRange.getLastRow());
-        assertEquals(0, enclosingCellRange.getFirstColumn());
-        assertEquals(6, enclosingCellRange.getLastColumn());
-        record.setNeedRecalculation(true);
-        assertTrue(record.getNeedRecalculation());
-        record.setNeedRecalculation(false);
-        assertFalse(record.getNeedRecalculation());
-    }
-    
-    public void testSerialization() {
-    	byte[] recordData = new byte[]
-    	{
-       		(byte)0x03, (byte)0x00,
-       		(byte)0x01,	(byte)0x00,
-       		
-       		(byte)0x00,	(byte)0x00,
-       		(byte)0x03,	(byte)0x00,
-       		(byte)0x00,	(byte)0x00,
-       		(byte)0x03,	(byte)0x00,
-       		
-       		(byte)0x04,	(byte)0x00,
-       		
-       		(byte)0x00,	(byte)0x00,
-       		(byte)0x01,	(byte)0x00,
-       		(byte)0x00,	(byte)0x00,
-       		(byte)0x01,	(byte)0x00,
-       		
-       		(byte)0x00,	(byte)0x00,
-       		(byte)0x01,	(byte)0x00,
-       		(byte)0x02,	(byte)0x00,
-       		(byte)0x03,	(byte)0x00,
-       		
-       		(byte)0x02,	(byte)0x00,
-       		(byte)0x03,	(byte)0x00,
-       		(byte)0x00,	(byte)0x00,
-       		(byte)0x01,	(byte)0x00,
-       		
-       		(byte)0x02,	(byte)0x00,
-       		(byte)0x03,	(byte)0x00,
-       		(byte)0x02,	(byte)0x00,
-       		(byte)0x03,	(byte)0x00,
-    	};
-    	
-    	CFHeaderRecord record = new CFHeaderRecord(new TestcaseRecordInputStream(CFHeaderRecord.sid, (short)recordData.length, recordData));
-		
-    	assertEquals("#CFRULES", 3, record.getNumberOfConditionalFormats());
-    	assertTrue(record.getNeedRecalculation());
-        CellRange enclosingCellRange = record.getEnclosingCellRange();
-        assertEquals(0, enclosingCellRange.getFirstRow());
-        assertEquals(3, enclosingCellRange.getLastRow());
-        assertEquals(0, enclosingCellRange.getFirstColumn());
-        assertEquals(3, enclosingCellRange.getLastColumn());
-        List ranges = record.getCellRanges();
-        assertEquals(0, ((CellRange)ranges.get(0)).getFirstRow());
-        assertEquals(1, ((CellRange)ranges.get(0)).getLastRow());
-        assertEquals(0, ((CellRange)ranges.get(0)).getFirstColumn());
-        assertEquals(1, ((CellRange)ranges.get(0)).getLastColumn());
-        assertEquals(0, ((CellRange)ranges.get(1)).getFirstRow());
-        assertEquals(1, ((CellRange)ranges.get(1)).getLastRow());
-        assertEquals(2, ((CellRange)ranges.get(1)).getFirstColumn());
-        assertEquals(3, ((CellRange)ranges.get(1)).getLastColumn());
-        assertEquals(2, ((CellRange)ranges.get(2)).getFirstRow());
-        assertEquals(3, ((CellRange)ranges.get(2)).getLastRow());
-        assertEquals(0, ((CellRange)ranges.get(2)).getFirstColumn());
-        assertEquals(1, ((CellRange)ranges.get(2)).getLastColumn());
-        assertEquals(2, ((CellRange)ranges.get(3)).getFirstRow());
-        assertEquals(3, ((CellRange)ranges.get(3)).getLastRow());
-        assertEquals(2, ((CellRange)ranges.get(3)).getFirstColumn());
-        assertEquals(3, ((CellRange)ranges.get(3)).getLastColumn());
-        assertEquals(recordData.length+4, record.getRecordSize());
-    	
+	public void testCreateCFHeaderRecord () 
+	{
+		CFHeaderRecord record = new CFHeaderRecord();
+		CellRange[] ranges = {
+			new CellRange(0,-1,5,5),
+			new CellRange(0,-1,6,6),
+			new CellRange(0,1,0,1),
+			new CellRange(0,1,2,3),
+			new CellRange(2,3,0,1),
+			new CellRange(2,3,2,3),
+		};
+		record.setCellRanges(ranges);
+		ranges = record.getCellRanges();
+		assertEquals(6,ranges.length);
+		CellRange enclosingCellRange = record.getEnclosingCellRange();
+		assertEquals(0, enclosingCellRange.getFirstRow());
+		assertEquals(-1, enclosingCellRange.getLastRow());
+		assertEquals(0, enclosingCellRange.getFirstColumn());
+		assertEquals(6, enclosingCellRange.getLastColumn());
+		record.setNeedRecalculation(true);
+		assertTrue(record.getNeedRecalculation());
+		record.setNeedRecalculation(false);
+		assertFalse(record.getNeedRecalculation());
+	}
+	
+	public void testSerialization() {
+		byte[] recordData = new byte[]
+		{
+			(byte)0x03, (byte)0x00,
+			(byte)0x01,	(byte)0x00,
+			
+			(byte)0x00,	(byte)0x00,
+			(byte)0x03,	(byte)0x00,
+			(byte)0x00,	(byte)0x00,
+			(byte)0x03,	(byte)0x00,
+			
+			(byte)0x04,	(byte)0x00,
+			
+			(byte)0x00,	(byte)0x00,
+			(byte)0x01,	(byte)0x00,
+			(byte)0x00,	(byte)0x00,
+			(byte)0x01,	(byte)0x00,
+			
+			(byte)0x00,	(byte)0x00,
+			(byte)0x01,	(byte)0x00,
+			(byte)0x02,	(byte)0x00,
+			(byte)0x03,	(byte)0x00,
+			
+			(byte)0x02,	(byte)0x00,
+			(byte)0x03,	(byte)0x00,
+			(byte)0x00,	(byte)0x00,
+			(byte)0x01,	(byte)0x00,
+			
+			(byte)0x02,	(byte)0x00,
+			(byte)0x03,	(byte)0x00,
+			(byte)0x02,	(byte)0x00,
+			(byte)0x03,	(byte)0x00,
+		};
+
+		CFHeaderRecord record = new CFHeaderRecord(new TestcaseRecordInputStream(CFHeaderRecord.sid, (short)recordData.length, recordData));
+
+		assertEquals("#CFRULES", 3, record.getNumberOfConditionalFormats());
+		assertTrue(record.getNeedRecalculation());
+		CellRange enclosingCellRange = record.getEnclosingCellRange();
+		assertEquals(0, enclosingCellRange.getFirstRow());
+		assertEquals(3, enclosingCellRange.getLastRow());
+		assertEquals(0, enclosingCellRange.getFirstColumn());
+		assertEquals(3, enclosingCellRange.getLastColumn());
+		CellRange[] ranges = record.getCellRanges();
+		CellRange range0 = ranges[0];
+		assertEquals(0, range0.getFirstRow());
+		assertEquals(1, range0.getLastRow());
+		assertEquals(0, range0.getFirstColumn());
+		assertEquals(1, range0.getLastColumn());
+		CellRange range1 = ranges[1];
+		assertEquals(0, range1.getFirstRow());
+		assertEquals(1, range1.getLastRow());
+		assertEquals(2, range1.getFirstColumn());
+		assertEquals(3, range1.getLastColumn());
+		CellRange range2 = ranges[2];
+		assertEquals(2, range2.getFirstRow());
+		assertEquals(3, range2.getLastRow());
+		assertEquals(0, range2.getFirstColumn());
+		assertEquals(1, range2.getLastColumn());
+		CellRange range3 = ranges[3];
+		assertEquals(2, range3.getFirstRow());
+		assertEquals(3, range3.getLastRow());
+		assertEquals(2, range3.getFirstColumn());
+		assertEquals(3, range3.getLastColumn());
+		assertEquals(recordData.length+4, record.getRecordSize());
+
 		byte[] output = record.serialize();
-		
+
 		assertEquals("Output size", recordData.length+4, output.length); //includes sid+recordlength
-		
+
 		for (int i = 0; i < recordData.length;i++) 
 		{
 			assertEquals("CFHeaderRecord doesn't match", recordData[i], output[i+4]);
 		}
-    }
-    
-    
-    public static void main(String[] ignored_args)
+	}
+	
+
+	public static void main(String[] ignored_args)
 	{
 		System.out.println("Testing org.apache.poi.hssf.record.CFHeaderRecord");
 		junit.textui.TestRunner.run(TestCFHeaderRecord.class);
 	}
-    
 }



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