poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r683081 [2/2] - in /poi/trunk/src: java/org/apache/poi/hssf/model/ java/org/apache/poi/hssf/record/ java/org/apache/poi/hssf/record/aggregates/ java/org/apache/poi/hssf/usermodel/ java/org/apache/poi/hssf/util/ testcases/org/apache/poi/hssf...
Date Wed, 06 Aug 2008 01:39:45 GMT
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/VerticalPageBreakRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/VerticalPageBreakRecord.java?rev=683081&r1=683080&r2=683081&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/VerticalPageBreakRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/VerticalPageBreakRecord.java Tue Aug  5 18:39: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
@@ -15,46 +14,53 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
+
 package org.apache.poi.hssf.record;
 
+import java.util.Iterator;
+
 /**
- * VerticalPageBreak record that stores page breaks at columns
- * <p>
- * This class is just used so that SID compares work properly in the RecordFactory
+ * VerticalPageBreak (0x001A) record that stores page breaks at columns<p/>
+ * 
  * @see PageBreakRecord
- * @author Danny Mui (dmui at apache dot org) 
+ * @author Danny Mui (dmui at apache dot org)
  */
-public class VerticalPageBreakRecord extends PageBreakRecord {
-	
-    public static final short sid = PageBreakRecord.VERTICAL_SID;
-    
+public final class VerticalPageBreakRecord extends PageBreakRecord {
+
+	public static final short sid = 0x001A;
+
 	/**
-	 * 
+	 * Creates an empty vertical page break record
 	 */
 	public VerticalPageBreakRecord() {
-		super();
-	}
 
-	/**
-	 * @param sid
-	 */
-	public VerticalPageBreakRecord(short sid) {
-		super(sid);
 	}
 
 	/**
-     * @param in the RecordInputstream to read the record from
+	 * @param in the RecordInputstream to read the record from
 	 */
 	public VerticalPageBreakRecord(RecordInputStream in) {
 		super(in);
 	}
 
-	/* (non-Javadoc)
-	 * @see org.apache.poi.hssf.record.Record#getSid()
-	 */
+	protected void validateSid(short id) {
+		if (id != getSid()) {
+			throw new RecordFormatException(
+					"NOT A HorizontalPageBreak or VerticalPageBreak RECORD!! " + id);
+		}
+	}
+
 	public short getSid() {
 		return sid;
 	}
 
+	public Object clone() {
+		PageBreakRecord result = new VerticalPageBreakRecord();
+		Iterator iterator = getBreaksIterator();
+		while (iterator.hasNext()) {
+			Break original = (Break) iterator.next();
+			result.addBreak(original.main, original.subFrom, original.subTo);
+		}
+		return result;
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java?rev=683081&r1=683080&r2=683081&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java Tue Aug  5 18:39:44 2008
@@ -14,19 +14,19 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
+
 package org.apache.poi.hssf.record.aggregates;
 
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.poi.hssf.model.RecordStream;
 import org.apache.poi.hssf.record.CFHeaderRecord;
 import org.apache.poi.hssf.record.CFRuleRecord;
 import org.apache.poi.hssf.record.Record;
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.util.CellRangeAddress;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
 
 /**
  * CFRecordsAggregate - aggregates Conditional Formatting records CFHeaderRecord 
@@ -36,15 +36,12 @@
  * @author Dmitriy Kumshayev
  *
  */
-public final class CFRecordsAggregate extends Record
-{
+public final class CFRecordsAggregate extends Record {
 	/** Excel allows up to 3 conditional formating rules */
 	private static final int MAX_CONDTIONAL_FORMAT_RULES = 3;
 
 	public final static short sid = -2008; // not a real BIFF record
 
-	private static POILogger log = POILogFactory.getLogger(CFRecordsAggregate.class);
-
 	private final CFHeaderRecord header;
 
 	/** List of CFRuleRecord objects */
@@ -78,9 +75,8 @@
 	 * @param offset - position of {@link CFHeaderRecord} object in the list of Record objects
 	 * @return CFRecordsAggregate object
 	 */
-	public static CFRecordsAggregate createCFAggregate(List recs, int pOffset)
-	{
-		Record rec = ( Record ) recs.get(pOffset);
+	public static CFRecordsAggregate createCFAggregate(RecordStream rs) {
+		Record rec = rs.getNext();
 		if (rec.getSid() != CFHeaderRecord.sid) {
 			throw new IllegalStateException("next record sid was " + rec.getSid() 
 					+ " instead of " + CFHeaderRecord.sid + " as expected");
@@ -90,35 +86,10 @@
 		int nRules = header.getNumberOfConditionalFormats();
 
 		CFRuleRecord[] rules = new CFRuleRecord[nRules];
-		int offset = pOffset;
-		int countFound = 0;
-		while (countFound < rules.length) {
-			offset++;
-			if(offset>=recs.size()) {
-				break;
-			}
-			rec = (Record)recs.get(offset);
-			if(rec instanceof CFRuleRecord) {
-				rules[countFound] = (CFRuleRecord) rec;
-				countFound++;
-			} else {
-				break;
-			}
-		}
-
-		if (countFound < nRules)
-		{ // TODO -(MAR-2008) can this ever happen? write junit 
-			
-			if (log.check(POILogger.DEBUG))
-			{
-				log.log(POILogger.DEBUG, "Expected  " + nRules + " Conditional Formats, "
-						+ "but found " + countFound + " rules");
-			}
-			header.setNumberOfConditionalFormats(nRules);
-			CFRuleRecord[] lessRules = new CFRuleRecord[countFound];
-			System.arraycopy(rules, 0, lessRules, 0, countFound);
-			rules = lessRules;
+		for (int i = 0; i < rules.length; i++) {
+			rules[i] = (CFRuleRecord) rs.getNext();
 		}
+		
 		return new CFRecordsAggregate(header, rules);
 	}
 

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java?rev=683081&r1=683080&r2=683081&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java Tue Aug  5 18:39:44 2008
@@ -1,72 +1,52 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements.  See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License.  You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.apache.poi.hssf.record.aggregates;
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
 
-import org.apache.poi.hssf.record.ColumnInfoRecord;
-import org.apache.poi.hssf.record.Record;
-import org.apache.poi.hssf.record.RecordInputStream;
+package org.apache.poi.hssf.record.aggregates;
 
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
+import org.apache.poi.hssf.model.RecordStream;
+import org.apache.poi.hssf.record.ColumnInfoRecord;
+import org.apache.poi.hssf.record.Record;
+
 /**
  * @author Glen Stampoultzis
  * @version $Id$
  */
-public class ColumnInfoRecordsAggregate
-    extends Record
-{
-//    int     size     = 0;
-    List records = null;
-
-    public ColumnInfoRecordsAggregate()
-    {
-        records = new ArrayList();
-    }
-
-    /** You never fill an aggregate */
-    protected void fillFields(RecordInputStream in)
-    {
-    }
-
-    /** Not required by an aggregate */
-    protected void validateSid(short id)
-    {
-    }
-
-    /** It's an aggregate... just made something up */
-    public short getSid()
-    {
-        return -1012;
-    }
+public final class ColumnInfoRecordsAggregate extends RecordAggregate {
+	private final List records;
 
-    public int getRecordSize()
-    {
-        int size = 0;
-        for ( Iterator iterator = records.iterator(); iterator.hasNext(); )
-            size += ( (ColumnInfoRecord) iterator.next() ).getRecordSize();
-        return size;
-    }
-
-    public Iterator getIterator()
-    {
-        return records.iterator();
-    }
+	/**
+	 * Creates an empty aggregate
+	 */
+	public ColumnInfoRecordsAggregate() {
+		records = new ArrayList();
+	}
+    public ColumnInfoRecordsAggregate(RecordStream rs) {
+        this();
+        
+        while(rs.peekNextClass() == ColumnInfoRecord.class) {
+        	records.add(rs.getNext());
+        }
+        if (records.size() < 1) {
+        	throw new RuntimeException("No column info records found");
+        }
+   }
 
     /**
      * Performs a deep clone of the record
@@ -105,25 +85,14 @@
         return records.size();
     }
 
-    /**
-     * called by the class that is responsible for writing this sucker.
-     * Subclasses should implement this so that their data is passed back in a
-     * byte array.
-     *
-     * @param offset    offset to begin writing at
-     * @param data      byte array containing instance data
-     * @return          number of bytes written
-     */
-    public int serialize(int offset, byte [] data)
-    {
-        Iterator itr = records.iterator();
-        int      pos = offset;
-
-        while (itr.hasNext())
-        {
-            pos += (( Record ) itr.next()).serialize(pos, data);
-        }
-        return pos - offset;
+    public void visitContainedRecords(RecordVisitor rv) {
+    	int nItems = records.size();
+    	if (nItems < 1) {
+    		return;
+    	}
+    	for(int i=0; i<nItems; i++) {
+    		rv.visitRecord((Record)records.get(i));
+    	}
     }
 
     public int findStartOfColumnOutlineGroup(int idx)
@@ -178,8 +147,7 @@
         return idx;
     }
 
-    public ColumnInfoRecord getColInfo(int idx)
-    {
+    private ColumnInfoRecord getColInfo(int idx) {
         return (ColumnInfoRecord) records.get( idx );
     }
 
@@ -191,7 +159,7 @@
             columnInfo.setHidden( hidden );
             if (idx + 1 < records.size())
             {
-                ColumnInfoRecord nextColumnInfo = (ColumnInfoRecord) records.get( idx + 1 );
+                ColumnInfoRecord nextColumnInfo = getColInfo(idx + 1);
                 if (columnInfo.getLastColumn() + 1 == nextColumnInfo.getFirstColumn())
                 {
                     if (nextColumnInfo.getOutlineLevel() < level)
@@ -279,7 +247,7 @@
             return;
 
         // Find the start of the group.
-        ColumnInfoRecord columnInfo = (ColumnInfoRecord) records.get( findStartOfColumnOutlineGroup( idx ) );
+        ColumnInfoRecord columnInfo = getColInfo( findStartOfColumnOutlineGroup( idx ) );
 
         // Hide all the columns until the end of the group
         columnInfo = writeHidden( columnInfo, idx, true );
@@ -331,7 +299,7 @@
      * @see org.apache.poi.hssf.record.ColumnInfoRecord
      * @return record containing a ColumnInfoRecord
      */
-    public static Record createColInfo()
+    public static ColumnInfoRecord createColInfo()
     {
         ColumnInfoRecord retval = new ColumnInfoRecord();
 
@@ -452,7 +420,7 @@
             ci.setCollapsed( collapsed.booleanValue() );
     }
 
-    public int findColumnIdx(int column, int fromIdx)
+    private int findColumnIdx(int column, int fromIdx)
     {
         if (column < 0)
             throw new IllegalArgumentException( "column parameter out of range: " + column );
@@ -462,7 +430,7 @@
         ColumnInfoRecord ci;
         for (int k = fromIdx; k < records.size(); k++)
         {
-            ci = ( ColumnInfoRecord ) records.get(k);
+            ci = getColInfo(k);
             if ((ci.getFirstColumn() <= column)
                     && (column <= ci.getLastColumn()))
             {
@@ -477,8 +445,8 @@
     {
         if (columnIdx == 0)
             return;
-        ColumnInfoRecord previousCol = (ColumnInfoRecord) records.get( columnIdx - 1);
-        ColumnInfoRecord currentCol = (ColumnInfoRecord) records.get( columnIdx );
+        ColumnInfoRecord previousCol = getColInfo( columnIdx - 1);
+        ColumnInfoRecord currentCol = getColInfo( columnIdx );
         boolean adjacentColumns = previousCol.getLastColumn() == currentCol.getFirstColumn() - 1;
         if (!adjacentColumns)
             return;
@@ -513,7 +481,7 @@
             int columnIdx = findColumnIdx( i, Math.max(0,fromIdx) );
             if (columnIdx != -1)
             {
-                level = ((ColumnInfoRecord)records.get( columnIdx )).getOutlineLevel();
+                level = getColInfo(columnIdx).getOutlineLevel();
                 if (indent) level++; else level--;
                 level = Math.max(0, level);
                 level = Math.min(7, level);
@@ -525,6 +493,30 @@
         }
 
     }
+    /**
+     * Finds the <tt>ColumnInfoRecord</tt> which contains the specified columnIndex
+     * @param columnIndex index of the column (not the index of the ColumnInfoRecord)
+     * @return <code>null</code> if no column info found for the specified column
+     */
+	public ColumnInfoRecord findColumnInfo(int columnIndex) {
+		int nInfos = records.size();
+		for(int i=0; i< nInfos; i++) {
+			ColumnInfoRecord ci = getColInfo(i);
+			if (ci.getFirstColumn() <= columnIndex && columnIndex <= ci.getLastColumn()) {
+				return ci;
+			}
+		}
+		return null;
+	}
+	public int getMaxOutlineLevel() {
+        int result = 0;
+        int count=records.size();
+        for (int i=0; i<count; i++) {
+            ColumnInfoRecord columnInfoRecord = getColInfo(i);
+            result = Math.max(columnInfoRecord.getOutlineLevel(), result);
+        }
+        return result;
+	}
 
 
 }

Added: poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/ConditionalFormattingTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/ConditionalFormattingTable.java?rev=683081&view=auto
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/ConditionalFormattingTable.java (added)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/ConditionalFormattingTable.java Tue Aug  5 18:39:44 2008
@@ -0,0 +1,88 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record.aggregates;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.poi.hssf.model.RecordStream;
+import org.apache.poi.hssf.record.CFHeaderRecord;
+import org.apache.poi.hssf.record.Record;
+
+/**
+ * Holds all the conditional formatting for a workbook sheet.<p/>
+ * 
+ * See OOO exelfileformat.pdf sec 4.12 'Conditional Formatting Table'
+ * 
+ * @author Josh Micich
+ */
+public final class ConditionalFormattingTable extends RecordAggregate {
+
+	private final List _cfHeaders;
+
+	/**
+	 * Creates an empty ConditionalFormattingTable
+	 */
+	public ConditionalFormattingTable() {
+		_cfHeaders = new ArrayList();
+	}
+
+	public ConditionalFormattingTable(RecordStream rs) {
+
+		List temp = new ArrayList();
+		while (rs.peekNextClass() == CFHeaderRecord.class) {
+			temp.add(CFRecordsAggregate.createCFAggregate(rs));
+		}
+		_cfHeaders = temp;
+	}
+
+	public void visitContainedRecords(RecordVisitor rv) {
+		for (int i = 0; i < _cfHeaders.size(); i++) {
+			rv.visitRecord((Record) _cfHeaders.get(i));
+		}
+	}
+
+	/**
+	 * @return index of the newly added CF header aggregate
+	 */
+	public int add(CFRecordsAggregate cfAggregate) {
+		_cfHeaders.add(cfAggregate);
+		return _cfHeaders.size() - 1;
+	}
+
+	public int size() {
+		return _cfHeaders.size();
+	}
+
+	public CFRecordsAggregate get(int index) {
+		checkIndex(index);
+		return (CFRecordsAggregate) _cfHeaders.get(index);
+	}
+
+	public void remove(int index) {
+		checkIndex(index);
+		_cfHeaders.remove(index);
+	}
+
+	private void checkIndex(int index) {
+		if (index < 0 || index >= _cfHeaders.size()) {
+			throw new IllegalArgumentException("Specified CF index " + index
+					+ " is outside the allowable range (0.." + (_cfHeaders.size() - 1) + ")");
+		}
+	}
+}

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/DataValidityTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/DataValidityTable.java?rev=683081&r1=683080&r2=683081&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/DataValidityTable.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/DataValidityTable.java Tue Aug  5 18:39:44 2008
@@ -21,17 +21,9 @@
 import java.util.List;
 
 import org.apache.poi.hssf.model.RecordStream;
-import org.apache.poi.hssf.record.CFHeaderRecord;
-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;
-import org.apache.poi.hssf.record.HyperlinkRecord;
-import org.apache.poi.hssf.record.MergeCellsRecord;
-import org.apache.poi.hssf.record.PaneRecord;
 import org.apache.poi.hssf.record.Record;
-import org.apache.poi.hssf.record.SelectionRecord;
-import org.apache.poi.hssf.record.WindowTwoRecord;
 
 /**
  * Manages the DVALRecord and DVRecords for a single sheet<br/>
@@ -40,7 +32,6 @@
  */
 public final class DataValidityTable extends RecordAggregate {
 
-	private static final short sid = -0x01B2; // not a real record
 	private final DVALRecord _headerRec;
 	/**
 	 * The list of data validations for the current sheet.
@@ -57,120 +48,21 @@
 		_validationList = temp;
 	}
 
-	private DataValidityTable() {
+	public DataValidityTable() {
 		_headerRec = new DVALRecord();
 		_validationList = new ArrayList();
 	}
 
-	public short getSid() {
-		return sid;
-	}
-
-	public int serialize(int offset, byte[] data) {
-		int result = _headerRec.serialize(offset, data);
-		for (int i = 0; i < _validationList.size(); i++) {
-			result += ((Record) _validationList.get(i)).serialize(offset + result, data);
+	public void visitContainedRecords(RecordVisitor rv) {
+		if (_validationList.isEmpty()) {
+			return;
 		}
-		return result;
-	}
-
-	public int getRecordSize() {
-		int result = _headerRec.getRecordSize();
-		for (int i = _validationList.size() - 1; i >= 0; i--) {
-			result += ((Record) _validationList.get(i)).getRecordSize();
+		rv.visitRecord(_headerRec);
+		for (int i = 0; i < _validationList.size(); i++) {
+			rv.visitRecord((Record) _validationList.get(i));
 		}
-		return result;
-	}
-
-	/**
-	 * Creates a new <tt>DataValidityTable</tt> and inserts it in the right
-	 * place in the sheetRecords list.
-	 */
-	public static DataValidityTable createForSheet(List sheetRecords) {
-		int index = findDVTableInsertPos(sheetRecords);
-
-		DataValidityTable result = new DataValidityTable();
-		sheetRecords.add(index, result);
-		return result;
 	}
 	
-    /**
-     * Finds the index where the sheet validations header record should be inserted
-     * @param records the records for this sheet
-     * 
-     * + WINDOW2
-     * o SCL
-     * o PANE
-     * oo SELECTION
-     * o STANDARDWIDTH
-     * oo MERGEDCELLS
-     * o LABELRANGES
-     * o PHONETICPR
-     * o Conditional Formatting Table
-     * o Hyperlink Table
-     * o Data Validity Table
-     * o SHEETLAYOUT
-     * o SHEETPROTECTION
-     * o RANGEPROTECTION
-     * + EOF
-     */
-    private static int findDVTableInsertPos(List records) {
-		int i = records.size() - 1;
-		if (!(records.get(i) instanceof EOFRecord)) {
-			throw new IllegalStateException("Last sheet record should be EOFRecord");
-		}
-		while (i > 0) {
-			i--;
-			Record rec = (Record) records.get(i);
-			if (isPriorRecord(rec.getSid())) {
-				Record nextRec = (Record) records.get(i + 1);
-				if (!isSubsequentRecord(nextRec.getSid())) {
-					throw new IllegalStateException("Unexpected (" + nextRec.getClass().getName()
-							+ ") found after (" + rec.getClass().getName() + ")");
-				}
-				return i;
-			}
-			if (!isSubsequentRecord(rec.getSid())) {
-				throw new IllegalStateException("Unexpected (" + rec.getClass().getName()
-						+ ") while looking for DV Table insert pos");
-			}
-		}
-		return 0;
-	}
-
-	// TODO - add UninterpretedRecord as base class for many of these
-	// unimplemented sids
-
-	private static boolean isPriorRecord(short sid) {
-		switch(sid) {
-			case WindowTwoRecord.sid:
-			case 0x00A0: // SCL
-			case PaneRecord.sid:
-			case SelectionRecord.sid:
-			case 0x0099: // STANDARDWIDTH
-			case MergeCellsRecord.sid:
-			case 0x015F: // LABELRANGES
-			case 0x00EF: // PHONETICPR
-			case CFHeaderRecord.sid:
-			case CFRuleRecord.sid:
-			case HyperlinkRecord.sid:
-			case 0x0800: // QUICKTIP
-				return true;
-		}
-		return false;
-	}
-
-	private static boolean isSubsequentRecord(short sid) {
-		switch(sid) {
-			case 0x0862: // SHEETLAYOUT
-			case 0x0867: // SHEETPROTECTION
-			case 0x0868: // RANGEPROTECTION
-			case EOFRecord.sid:
-				return true;
-		}
-		return false;
-	}
-
 	public void addDataValidation(DVRecord dvRecord) {
 		_validationList.add(dvRecord);
 		_headerRec.setDVRecNo(_validationList.size());

Added: poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/MergedCellsTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/MergedCellsTable.java?rev=683081&view=auto
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/MergedCellsTable.java (added)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/MergedCellsTable.java Tue Aug  5 18:39:44 2008
@@ -0,0 +1,122 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record.aggregates;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.poi.hssf.model.RecordStream;
+import org.apache.poi.hssf.record.MergeCellsRecord;
+import org.apache.poi.hssf.util.CellRangeAddress;
+import org.apache.poi.hssf.util.CellRangeAddressList;
+
+/**
+ * 
+ * @author Josh Micich
+ */
+public final class MergedCellsTable extends RecordAggregate {
+	private static int MAX_MERGED_REGIONS = 1027; // enforced by the 8224 byte limit
+
+	private final List _mergedRegions;
+
+	/**
+	 * Creates an empty aggregate
+	 */
+	public MergedCellsTable() {
+		_mergedRegions = new ArrayList();
+	}
+
+	public MergedCellsTable(RecordStream rs) {
+		List temp = new ArrayList();
+		while (rs.peekNextClass() == MergeCellsRecord.class) {
+			MergeCellsRecord mcr = (MergeCellsRecord) rs.getNext();
+			int nRegions = mcr.getNumAreas();
+			for (int i = 0; i < nRegions; i++) {
+				temp.add(mcr.getAreaAt(i));
+			}
+		}
+		_mergedRegions = temp;
+	}
+
+	public int getRecordSize() {
+		// a bit cheaper than the default impl
+		int nRegions = _mergedRegions.size();
+		if (nRegions < 1) {
+			// no need to write a single empty MergeCellsRecord
+			return 0;
+		}
+		int nMergedCellsRecords = nRegions / MAX_MERGED_REGIONS;
+		int nLeftoverMergedRegions = nRegions % MAX_MERGED_REGIONS;
+
+		int result = nMergedCellsRecords
+				* (4 + CellRangeAddressList.getEncodedSize(MAX_MERGED_REGIONS)) + 4
+				+ CellRangeAddressList.getEncodedSize(nLeftoverMergedRegions);
+		return result;
+	}
+
+	public void visitContainedRecords(RecordVisitor rv) {
+		int nRegions = _mergedRegions.size();
+		if (nRegions < 1) {
+			// no need to write a single empty MergeCellsRecord
+			return;
+		}
+
+		int nFullMergedCellsRecords = nRegions / MAX_MERGED_REGIONS;
+		int nLeftoverMergedRegions = nRegions % MAX_MERGED_REGIONS;
+		CellRangeAddress[] cras = new CellRangeAddress[nRegions];
+		_mergedRegions.toArray(cras);
+
+		for (int i = 0; i < nFullMergedCellsRecords; i++) {
+			int startIx = i * MAX_MERGED_REGIONS;
+			rv.visitRecord(new MergeCellsRecord(cras, startIx, MAX_MERGED_REGIONS));
+		}
+		if (nLeftoverMergedRegions > 0) {
+			int startIx = nFullMergedCellsRecords * MAX_MERGED_REGIONS;
+			rv.visitRecord(new MergeCellsRecord(cras, startIx, nLeftoverMergedRegions));
+		}
+	}
+
+	public void add(MergeCellsRecord mcr) {
+		_mergedRegions.add(mcr);
+	}
+
+	public CellRangeAddress get(int index) {
+		checkIndex(index);
+		return (CellRangeAddress) _mergedRegions.get(index);
+	}
+
+	public void remove(int index) {
+		checkIndex(index);
+		_mergedRegions.remove(index);
+	}
+
+	private void checkIndex(int index) {
+		if (index < 0 || index >= _mergedRegions.size()) {
+			throw new IllegalArgumentException("Specified CF index " + index
+					+ " is outside the allowable range (0.." + (_mergedRegions.size() - 1) + ")");
+		}
+	}
+
+	public void addArea(int rowFrom, int colFrom, int rowTo, int colTo) {
+		_mergedRegions.add(new CellRangeAddress(rowFrom, rowTo, colFrom, colTo));
+	}
+
+	public int getNumberOfMergedRegions() {
+		return _mergedRegions.size();
+	}
+}

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/RecordAggregate.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/RecordAggregate.java?rev=683081&r1=683080&r2=683081&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/RecordAggregate.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/RecordAggregate.java Tue Aug  5 18:39:44 2008
@@ -18,6 +18,7 @@
 package org.apache.poi.hssf.record.aggregates;
 
 import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.RecordBase;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -27,15 +28,66 @@
  * 
  * @author Josh Micich
  */
-public abstract class RecordAggregate extends Record {
-	// TODO - convert existing aggregate classes to proper subclasses of this one
+public abstract class RecordAggregate extends RecordBase {
+	// TODO - delete these methods when all subclasses have been converted
 	protected final void validateSid(short id) {
-		// TODO - break class hierarchy and make separate from Record
 		throw new RuntimeException("Should not be called");
 	}
 	protected final void fillFields(RecordInputStream in) {
 		throw new RuntimeException("Should not be called");
 	}
-	// force subclassses to provide better implementation than default
-	public abstract int getRecordSize();
+    public final short getSid() {
+		throw new RuntimeException("Should not be called");
+    }
+
+	public abstract void visitContainedRecords(RecordVisitor rv);
+	
+	public final int serialize(int offset, byte[] data) {
+		SerializingRecordVisitor srv = new SerializingRecordVisitor(data, offset);
+		visitContainedRecords(srv);
+		return srv.countBytesWritten();
+	}
+	public int getRecordSize() {
+		RecordSizingVisitor rsv = new RecordSizingVisitor();
+		visitContainedRecords(rsv);
+		return rsv.getTotalSize();
+	}
+	
+	public interface RecordVisitor {
+		void visitRecord(Record r);
+	}
+	
+	private static final class SerializingRecordVisitor implements RecordVisitor {
+
+		private final byte[] _data;
+		private final int _startOffset;
+		private int _countBytesWritten;
+
+		public SerializingRecordVisitor(byte[] data, int startOffset) {
+			_data = data;
+			_startOffset = startOffset;
+			_countBytesWritten = 0;
+		}
+		public int countBytesWritten() {
+			return _countBytesWritten;
+		}
+		public void visitRecord(Record r) {
+			int currentOffset = _startOffset + _countBytesWritten;
+			_countBytesWritten += r.serialize(currentOffset, _data);
+		}
+	}
+	private static final class RecordSizingVisitor implements RecordVisitor {
+
+		private int _totalSize;
+		
+		public RecordSizingVisitor() {
+			_totalSize = 0;
+		}
+		public int getTotalSize() {
+			return _totalSize;
+		}
+		public void visitRecord(Record r) {
+			_totalSize += r.getRecordSize();
+		}
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java?rev=683081&r1=683080&r2=683081&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java Tue Aug  5 18:39:44 2008
@@ -48,6 +48,7 @@
 import org.apache.poi.hssf.record.NumberRecord;
 import org.apache.poi.hssf.record.ObjRecord;
 import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.RecordBase;
 import org.apache.poi.hssf.record.StringRecord;
 import org.apache.poi.hssf.record.SubRecord;
 import org.apache.poi.hssf.record.TextObjectRecord;
@@ -1144,7 +1145,7 @@
         HSSFComment comment = null;
         HashMap txshapes = new HashMap(); //map shapeId and TextObjectRecord
         for (Iterator it = sheet.getRecords().iterator(); it.hasNext(); ) {
-           Record rec = ( Record ) it.next();
+           RecordBase rec = (RecordBase) it.next();
            if (rec instanceof NoteRecord){
                NoteRecord note = (NoteRecord)rec;
                if (note.getRow() == row && note.getColumn() == column){
@@ -1186,7 +1187,7 @@
      */
     public HSSFHyperlink getHyperlink(){
         for (Iterator it = sheet.getRecords().iterator(); it.hasNext(); ) {
-            Record rec = ( Record ) it.next();
+            RecordBase rec = (RecordBase) it.next();
             if (rec instanceof HyperlinkRecord){
                 HyperlinkRecord link = (HyperlinkRecord)rec;
                 if(link.getFirstColumn() == record.getColumn() && link.getFirstRow() == record.getRow()){

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java?rev=683081&r1=683080&r2=683081&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java Tue Aug  5 18:39:44 2008
@@ -1446,43 +1446,19 @@
     }
 
     /**
-     * Retrieves all the horizontal page breaks
-     * @return all the horizontal page breaks, or null if there are no row page breaks
+     * @return row indexes of all the horizontal page breaks, never <code>null</code>
      */
     public int[] getRowBreaks(){
         //we can probably cache this information, but this should be a sparsely used function
-        int count = sheet.getNumRowBreaks();
-        if (count > 0) {
-          int[] returnValue = new int[count];
-          Iterator iterator = sheet.getRowBreaks();
-          int i = 0;
-          while (iterator.hasNext()) {
-            PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
-            returnValue[i++] = breakItem.main;
-          }
-          return returnValue;
-        }
-        return null;
+        return sheet.getRowBreaks();
     }
 
     /**
-     * Retrieves all the vertical page breaks
-     * @return all the vertical page breaks, or null if there are no column page breaks
+     * @return column indexes of all the vertical page breaks, never <code>null</code>
      */
-    public short[] getColumnBreaks(){
+    public int[] getColumnBreaks(){
         //we can probably cache this information, but this should be a sparsely used function
-        int count = sheet.getNumColumnBreaks();
-        if (count > 0) {
-          short[] returnValue = new short[count];
-          Iterator iterator = sheet.getColumnBreaks();
-          int i = 0;
-          while (iterator.hasNext()) {
-            PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
-            returnValue[i++] = breakItem.main;
-          }
-          return returnValue;
-        }
-        return null;
+        return sheet.getColumnBreaks();
     }
 
 

Modified: poi/trunk/src/java/org/apache/poi/hssf/util/CellRangeAddressList.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/util/CellRangeAddressList.java?rev=683081&r1=683080&r2=683081&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/util/CellRangeAddressList.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/util/CellRangeAddressList.java Tue Aug  5 18:39:44 2008
@@ -125,7 +125,14 @@
 	}
 
 	public int getSize() {
-		return 2 + CellRangeAddress.getEncodedSize(_list.size());
+		return getEncodedSize(_list.size());
+	}
+	/**
+	 * @return the total size of for the specified number of ranges,
+	 *  including the initial 2 byte range count
+	 */
+	public static int getEncodedSize(int numberOfRanges) {
+		return 2 + CellRangeAddress.getEncodedSize(numberOfRanges);
 	}
 	public CellRangeAddressList copy() {
 		CellRangeAddressList result = new CellRangeAddressList();

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheet.java?rev=683081&r1=683080&r2=683081&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheet.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheet.java Tue Aug  5 18:39:44 2008
@@ -17,20 +17,31 @@
 
 package org.apache.poi.hssf.model;
 
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+import java.util.List;
+
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.eventmodel.ERFListener;
 import org.apache.poi.hssf.eventmodel.EventRecordFactory;
-import org.apache.poi.hssf.record.*;
+import org.apache.poi.hssf.record.BOFRecord;
+import org.apache.poi.hssf.record.BlankRecord;
+import org.apache.poi.hssf.record.CellValueRecordInterface;
+import org.apache.poi.hssf.record.ColumnInfoRecord;
+import org.apache.poi.hssf.record.DimensionsRecord;
+import org.apache.poi.hssf.record.EOFRecord;
+import org.apache.poi.hssf.record.IndexRecord;
+import org.apache.poi.hssf.record.MergeCellsRecord;
+import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.RowRecord;
+import org.apache.poi.hssf.record.StringRecord;
+import org.apache.poi.hssf.record.UncalcedRecord;
 import org.apache.poi.hssf.record.aggregates.ColumnInfoRecordsAggregate;
 import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate;
 import org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate;
-
-import java.io.ByteArrayInputStream;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import org.apache.poi.hssf.util.CellRangeAddress;
 
 /**
  * Unit test for the Sheet class.
@@ -55,10 +66,24 @@
         assertTrue( sheet.records.get(pos++) instanceof EOFRecord );
     }
 
+    private static final class MergedCellListener implements ERFListener {
+
+        private int _count;
+        public MergedCellListener() {
+            _count = 0;
+        }
+        public boolean processRecord(Record rec) {
+            _count++;
+            return true;
+        }
+        public int getCount() {
+            return _count;
+        }
+    }
+    
     public void testAddMergedRegion() {
         Sheet sheet = Sheet.createSheet();
         int regionsToAdd = 4096;
-        int startRecords = sheet.getRecords().size();
 
         //simple test that adds a load of regions
         for (int n = 0; n < regionsToAdd; n++)
@@ -71,11 +96,18 @@
         assertTrue(sheet.getNumMergedRegions() == regionsToAdd);
 
         //test that the regions were spread out over the appropriate number of records
-        int recordsAdded    = sheet.getRecords().size() - startRecords;
+        byte[] sheetData = new byte[sheet.getSize()];
+        sheet.serialize(0, sheetData);
+        MergedCellListener mcListener = new MergedCellListener();
+        EventRecordFactory erf = new EventRecordFactory(mcListener, new short[] { MergeCellsRecord.sid, });
+//        POIFSFileSystem poifs = new POIFSFileSystem(new ByteArrayInputStream(sheetData));
+        erf.processRecords(new ByteArrayInputStream(sheetData));
+        int recordsAdded    = mcListener.getCount();
         int recordsExpected = regionsToAdd/1027;
         if ((regionsToAdd % 1027) != 0)
             recordsExpected++;
-        assertTrue("The " + regionsToAdd + " merged regions should have been spread out over " + recordsExpected + " records, not " + recordsAdded, recordsAdded == recordsExpected);
+        assertTrue("The " + regionsToAdd + " merged regions should have been spread out over " 
+                + recordsExpected + " records, not " + recordsAdded, recordsAdded == recordsExpected);
         // Check we can't add one with invalid date
         try {
             sheet.addMergedRegion(10, (short)10, 9, (short)12);
@@ -97,22 +129,23 @@
         Sheet sheet = Sheet.createSheet();
         int regionsToAdd = 4096;
 
-        for (int n = 0; n < regionsToAdd; n++)
-            sheet.addMergedRegion(0, (short) 0, 1, (short) 1);
+        for (int n = 0; n < regionsToAdd; n++) {
+            sheet.addMergedRegion(n, 0, n, 1);
+        }
 
-        int records = sheet.getRecords().size();
+        int nSheetRecords = sheet.getRecords().size();
 
         //remove a third from the beginning
         for (int n = 0; n < regionsToAdd/3; n++)
         {
             sheet.removeMergedRegion(0);
             //assert they have been deleted
-            assertTrue("Num of regions should be " + (regionsToAdd - n - 1) + " not " + sheet.getNumMergedRegions(), sheet.getNumMergedRegions() == regionsToAdd - n - 1);
+            assertEquals("Num of regions", regionsToAdd - n - 1, sheet.getNumMergedRegions());
         }
-
-        //assert any record removing was done
-        int recordsRemoved = (regionsToAdd/3)/1027; //doesn't work for particular values of regionsToAdd
-        assertTrue("Expected " + recordsRemoved + " record to be removed from the starting " + records + ".  Currently there are " + sheet.getRecords().size() + " records", records - sheet.getRecords().size() == recordsRemoved);
+        
+        // merge records are removed from within the MergedCellsTable, 
+        // so the sheet record count should not change 
+        assertEquals("Sheet Records", nSheetRecords, sheet.getRecords().size());
     }
 
     /**
@@ -125,8 +158,11 @@
     public void testMovingMergedRegion() {
         List records = new ArrayList();
 
-        MergeCellsRecord merged = new MergeCellsRecord();
-        merged.addArea(0, (short)0, 1, (short)2);
+        CellRangeAddress[] cras = {
+            new CellRangeAddress(0, 1, 0, 2),
+        };
+        MergeCellsRecord merged = new MergeCellsRecord(cras, 0, cras.length);
+        records.add(new DimensionsRecord());
         records.add(new RowRecord(0));
         records.add(new RowRecord(1));
         records.add(new RowRecord(2));
@@ -155,6 +191,7 @@
     public void testRowAggregation() {
         List records = new ArrayList();
 
+        records.add(new DimensionsRecord());
         records.add(new RowRecord(0));
         records.add(new RowRecord(1));
         records.add(new StringRecord());
@@ -196,10 +233,9 @@
         boolean is0 = false;
         boolean is11 = false;
 
-        Iterator iterator = sheet.getRowBreaks();
-        while (iterator.hasNext()) {
-            PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
-            int main = breakItem.main;
+        int[] rowBreaks = sheet.getRowBreaks();
+        for (int i = 0; i < rowBreaks.length; i++) {
+            int main = rowBreaks[i];
             if (main != 0 && main != 10 && main != 11) fail("Invalid page break");
             if (main == 0)     is0 = true;
             if (main == 10) is10= true;
@@ -253,10 +289,9 @@
         boolean is1 = false;
         boolean is15 = false;
 
-        Iterator iterator = sheet.getColumnBreaks();
-        while (iterator.hasNext()) {
-            PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
-            int main = breakItem.main;
+        int[] colBreaks = sheet.getColumnBreaks();
+        for (int i = 0; i < colBreaks.length; i++) {
+            int main = colBreaks[i];
             if (main != 0 && main != 1 && main != 10 && main != 15) fail("Invalid page break");
             if (main == 0)  is0 = true;
             if (main == 1)  is1 = true;
@@ -297,9 +332,8 @@
         xfindex = sheet.getXFIndexForColAt((short) 1);
         assertEquals(DEFAULT_IDX, xfindex);
 
-        // TODO change return type to ColumnInfoRecord 
-        ColumnInfoRecord nci = (ColumnInfoRecord)ColumnInfoRecordsAggregate.createColInfo();
-        sheet.columns.insertColumn(nci);
+        ColumnInfoRecord nci = ColumnInfoRecordsAggregate.createColInfo();
+        sheet._columnInfos.insertColumn(nci);
 
         // single column ColumnInfoRecord
         nci.setFirstColumn((short) 2);
@@ -361,6 +395,7 @@
         List records = new ArrayList();
         records.add(new BOFRecord());
         records.add(new UncalcedRecord());
+        records.add(new DimensionsRecord());
         records.add(new EOFRecord());
         Sheet sheet = Sheet.createSheet(records, 0, 0);
 
@@ -369,7 +404,7 @@
         if (serializedSize != estimatedSize) {
             throw new AssertionFailedError("Identified bug 45066 b");
         }
-        assertEquals(50, serializedSize);
+        assertEquals(68, serializedSize);
     }
 
     /**
@@ -393,7 +428,7 @@
 
 
         int dbCellRecordPos = getDbCellRecordPos(sheet);
-        if (dbCellRecordPos == 264) {
+        if (dbCellRecordPos == 252) {
             // The overt symptom of the bug
             // DBCELL record pos is calculated wrong if VRA comes before RRA
             throw new AssertionFailedError("Identified  bug 45145");
@@ -405,7 +440,7 @@
         assertEquals(RowRecordsAggregate.class, recs.get(rraIx).getClass());
         assertEquals(ValueRecordsAggregate.class, recs.get(rraIx+1).getClass());
 
-        assertEquals(254, dbCellRecordPos);
+        assertEquals(242, dbCellRecordPos);
     }
 
     /**

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java?rev=683081&r1=683080&r2=683081&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java Tue Aug  5 18:39:44 2008
@@ -29,8 +29,7 @@
 	
 	public void testGetCellWidth() {
 		Sheet sheet = Sheet.createSheet();
-		// TODO change return type to ColumnInfoRecord 
-		ColumnInfoRecord nci = (ColumnInfoRecord)ColumnInfoRecordsAggregate.createColInfo();
+		ColumnInfoRecord nci = ColumnInfoRecordsAggregate.createColInfo();
 
 		// Prepare test model
 		nci.setFirstColumn((short)5);
@@ -38,7 +37,7 @@
 		nci.setColumnWidth((short)100);
 		
 		
-		sheet.columns.insertColumn(nci);
+		sheet._columnInfos.insertColumn(nci);
 
 		assertEquals((short)100,sheet.getColumnWidth((short)5));
 		assertEquals((short)100,sheet.getColumnWidth((short)6));
@@ -58,6 +57,3 @@
 	}
 
 }
-
-
-

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java?rev=683081&r1=683080&r2=683081&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java Tue Aug  5 18:39:44 2008
@@ -33,8 +33,8 @@
     * @throws Exception
     */
    public void testCloneReferences() throws Exception {
-      MergeCellsRecord merge = new MergeCellsRecord();
-      merge.addArea(0, (short)0, 1, (short)2);
+      CellRangeAddress[] cras = { new CellRangeAddress(0, 1, 0, 2), };
+      MergeCellsRecord merge = new MergeCellsRecord(cras, 0, cras.length);
       MergeCellsRecord clone = (MergeCellsRecord)merge.clone();
       
       assertNotSame("Merged and cloned objects are the same", merge, clone);
@@ -47,7 +47,6 @@
       assertEquals("New Clone Col From doesnt match", mergeRegion.getFirstColumn(), cloneRegion.getFirstColumn());
       assertEquals("New Clone Col To doesnt match", mergeRegion.getLastColumn(), cloneRegion.getLastColumn());      
       
-      merge.removeAreaAt(0);
-      assertNotNull("Clone's item not removed", clone.getAreaAt(0));
+      assertFalse(merge.getAreaAt(0) == clone.getAreaAt(0));
    }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java?rev=683081&r1=683080&r2=683081&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java Tue Aug  5 18:39:44 2008
@@ -24,6 +24,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.model.RecordStream;
 import org.apache.poi.hssf.record.CFHeaderRecord;
 import org.apache.poi.hssf.record.CFRuleRecord;
 import org.apache.poi.hssf.record.RecordFactory;
@@ -59,7 +60,7 @@
 		recs.add(rule2);
 		recs.add(rule3);
 		CFRecordsAggregate record;
-		record = CFRecordsAggregate.createCFAggregate(recs, 0);
+		record = CFRecordsAggregate.createCFAggregate(new RecordStream(recs, 0));
 
 		// Serialize
 		byte [] serializedRecord = record.serialize();
@@ -81,7 +82,7 @@
 		assertEquals(2, cellRanges.length);
 		assertEquals(3, header.getNumberOfConditionalFormats());
 
-		record = CFRecordsAggregate.createCFAggregate(recs, 0);
+		record = CFRecordsAggregate.createCFAggregate(new RecordStream(recs, 0));
 
 		record = record.cloneCFAggregate();
 

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java?rev=683081&r1=683080&r2=683081&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java Tue Aug  5 18:39:44 2008
@@ -19,42 +19,39 @@
 
 import junit.framework.TestCase;
 import org.apache.poi.hssf.record.ColumnInfoRecord;
+import org.apache.poi.hssf.record.RecordBase;
 
 /**
  * @author Glen Stampoultzis
  */
-public final class TestColumnInfoRecordsAggregate extends TestCase
-{
-    ColumnInfoRecordsAggregate columnInfoRecordsAggregate;
-
-    public void testGetRecordSize() throws Exception
-    {
-        columnInfoRecordsAggregate = new ColumnInfoRecordsAggregate();
-        columnInfoRecordsAggregate.insertColumn( createColumn( (short)1, (short)3 ));
-        columnInfoRecordsAggregate.insertColumn( createColumn( (short)4, (short)7 ));
-        columnInfoRecordsAggregate.insertColumn( createColumn( (short)8, (short)8 ));
-//        columnInfoRecordsAggregate.setColumn( (short)2, new Short( (short)200 ), new Integer( 1 ), new Boolean( true ), null);
-        columnInfoRecordsAggregate.groupColumnRange( (short)2, (short)5, true );
-        assertEquals(6, columnInfoRecordsAggregate.getNumColumns());
-
-        assertEquals(columnInfoRecordsAggregate.getRecordSize(), columnInfoRecordsAggregate.serialize().length);
-
-        columnInfoRecordsAggregate = new ColumnInfoRecordsAggregate();
-        columnInfoRecordsAggregate.groupColumnRange( (short)3, (short)6, true );
-
-        assertEquals(columnInfoRecordsAggregate.getRecordSize(), serializedSize());
-    }
-
-    private int serializedSize()
-    {
-        return columnInfoRecordsAggregate.serialize(0, new byte[columnInfoRecordsAggregate.getRecordSize()]);
-    }
-
-    private ColumnInfoRecord createColumn( short firstCol, short lastCol )
-    {
-        ColumnInfoRecord columnInfoRecord = new ColumnInfoRecord( );
-        columnInfoRecord.setFirstColumn(firstCol);
-        columnInfoRecord.setLastColumn(lastCol);
-        return columnInfoRecord;
-    }
+public final class TestColumnInfoRecordsAggregate extends TestCase {
+
+	public void testGetRecordSize() {
+		ColumnInfoRecordsAggregate agg = new ColumnInfoRecordsAggregate();
+		agg.insertColumn(createColumn(1, 3));
+		agg.insertColumn(createColumn(4, 7));
+		agg.insertColumn(createColumn(8, 8));
+		agg.groupColumnRange((short) 2, (short) 5, true);
+		assertEquals(6, agg.getNumColumns());
+
+		confirmSerializedSize(agg);
+
+		agg = new ColumnInfoRecordsAggregate();
+		agg.groupColumnRange((short) 3, (short) 6, true);
+		confirmSerializedSize(agg);
+	}
+
+	private static void confirmSerializedSize(RecordBase cirAgg) {
+		int estimatedSize = cirAgg.getRecordSize();
+		byte[] buf = new byte[estimatedSize];
+		int serializedSize = cirAgg.serialize(0, buf);
+		assertEquals(estimatedSize, serializedSize);
+	}
+
+	private static ColumnInfoRecord createColumn(int firstCol, int lastCol) {
+		ColumnInfoRecord columnInfoRecord = new ColumnInfoRecord();
+		columnInfoRecord.setFirstColumn((short) firstCol);
+		columnInfoRecord.setLastColumn((short) lastCol);
+		return columnInfoRecord;
+	}
 }
\ No newline at end of file

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=683081&r1=683080&r2=683081&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Tue Aug  5 18:39:44 2008
@@ -659,7 +659,7 @@
 
             HSSFSheet sheet = wb.getSheetAt( 0 );
             int[] breaks = sheet.getRowBreaks();
-            assertNull(breaks);
+            assertEquals(0, breaks.length);
 
             //add 3 row breaks
             for (int j = 1; j <= 3; j++) {



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


Mime
View raw message