poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: jakarta-poi/src/testcases/org/apache/poi/hssf/model SheetTest.java
Date Mon, 02 Jun 2003 02:47:45 GMT
dmui        2003/06/01 19:47:44

  Modified:    src/java/org/apache/poi/hssf/record FormulaRecord.java
               src/java/org/apache/poi/hssf/record/aggregates
                        FormulaRecordAggregate.java
               src/java/org/apache/poi/hssf/record/formula ExpPtg.java
               src/testcases/org/apache/poi/hssf/model SheetTest.java
  Log:
  Fixed support for Cloning SharedFormulas and FormulaAggregates leaving
  out other values after it.
  
  Revision  Changes    Path
  1.21      +2 -2      jakarta-poi/src/java/org/apache/poi/hssf/record/FormulaRecord.java
  
  Index: FormulaRecord.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/record/FormulaRecord.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- FormulaRecord.java	6 May 2003 13:08:08 -0000	1.20
  +++ FormulaRecord.java	2 Jun 2003 02:47:44 -0000	1.21
  @@ -607,8 +607,8 @@
         if (field_8_parsed_expr != null)
           size = field_8_parsed_expr.size();
         for (int i=0; i< size; i++) {
  -        Ptg ptg = (Ptg)((Ptg)field_8_parsed_expr.get(i)).clone();
  -        rec.field_8_parsed_expr.set(i, ptg);
  +        Ptg ptg = (Ptg)((Ptg)field_8_parsed_expr.get(i)).clone();        
  +        rec.field_8_parsed_expr.add(i, ptg);
         }
         rec.all_data = all_data;
         return rec;
  
  
  
  1.5       +27 -1     jakarta-poi/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java
  
  Index: FormulaRecordAggregate.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FormulaRecordAggregate.java	8 May 2003 00:02:03 -0000	1.4
  +++ FormulaRecordAggregate.java	2 Jun 2003 02:47:44 -0000	1.5
  @@ -82,6 +82,19 @@
           this.stringRecord = stringRecord;
       }
   
  +	/**
  +	 * Used only in the clone
  +	 * @param formulaRecord
  +	 * @param stringRecord
  +	 * @param sharedRecord
  +	 */
  +	public FormulaRecordAggregate( FormulaRecord formulaRecord, StringRecord stringRecord,
SharedFormulaRecord sharedRecord)
  +	{
  +		  this.formulaRecord = formulaRecord;
  +		  this.stringRecord = stringRecord;
  +		  this.sharedFormulaRecord = sharedRecord;
  +	}
  +
   
   
       protected void validateSid( short id )
  @@ -221,7 +234,10 @@
        * @see java.lang.Object#clone()
        */
       public Object clone() {
  -        return new FormulaRecordAggregate((FormulaRecord) this.formulaRecord.clone(), (StringRecord)
this.stringRecord.clone());
  +			StringRecord clonedString = (stringRecord == null) ? null : (StringRecord)stringRecord.clone();
  +    		SharedFormulaRecord clonedShared = (sharedFormulaRecord == null) ? null : (SharedFormulaRecord)sharedFormulaRecord.clone();
  +    		
  +        return new FormulaRecordAggregate((FormulaRecord) this.formulaRecord.clone(), clonedString,
clonedShared);
       }
   
   
  @@ -239,6 +255,16 @@
       */
      public void setSharedFormulaRecord(SharedFormulaRecord sharedFormulaRecord) {
         this.sharedFormulaRecord = sharedFormulaRecord;
  +   }
  +
  +   /* 
  +    * Setting to true so that this value does not abort the whole ValueAggregation
  +    * (non-Javadoc)
  +    * @see org.apache.poi.hssf.record.Record#isInValueSection()
  +    */
  +   public boolean isInValueSection() {
  +
  +      return true;
      }
   
   }
  
  
  
  1.8       +4 -1      jakarta-poi/src/java/org/apache/poi/hssf/record/formula/ExpPtg.java
  
  Index: ExpPtg.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/ExpPtg.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ExpPtg.java	8 May 2003 00:02:03 -0000	1.7
  +++ ExpPtg.java	2 Jun 2003 02:47:44 -0000	1.8
  @@ -110,7 +110,10 @@
       public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
       
       public Object clone() {
  -      throw new RuntimeException("NO IDEA SHARED FORMULA EXP PTG");
  +    	//can't clone one that doesnt have data can we??
  +		if (this.existing == null) throw new RuntimeException("NO IDEA SHARED FORMULA EXP PTG");

  +		
  +    	return new ExpPtg(this.existing, 0);
       }
   
   }
  
  
  
  1.4       +83 -0     jakarta-poi/src/testcases/org/apache/poi/hssf/model/SheetTest.java
  
  Index: SheetTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/testcases/org/apache/poi/hssf/model/SheetTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SheetTest.java	9 May 2003 12:39:08 -0000	1.3
  +++ SheetTest.java	2 Jun 2003 02:47:44 -0000	1.4
  @@ -6,9 +6,18 @@
   
   import junit.framework.TestCase;
   
  +import org.apache.poi.hssf.record.BOFRecord;
  +import org.apache.poi.hssf.record.BlankRecord;
   import org.apache.poi.hssf.record.ColumnInfoRecord;
  +import org.apache.poi.hssf.record.EOFRecord;
  +import org.apache.poi.hssf.record.FormulaRecord;
  +import org.apache.poi.hssf.record.LabelSSTRecord;
   import org.apache.poi.hssf.record.RowRecord;
  +import org.apache.poi.hssf.record.SharedFormulaRecord;
   import org.apache.poi.hssf.record.StringRecord;
  +import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
  +import org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate;
  +import org.apache.poi.hssf.record.formula.ExpPtg;
   
   /**
    * @author Tony Poppleton
  @@ -147,6 +156,80 @@
   		
   	}
   
  +	/**
  +	 * Make sure that a sheet with the sharedformula works when cloned, it used to not fail
  +	 *
  +	 */
  +	public void testSharedFormulaClone() {
  +		Sheet sheet;
  +		List records = new ArrayList();
  +		
  +		FormulaRecord formula = new FormulaRecord();
  +		byte[] array = {(byte)0,(byte)0,(byte)0,(byte)0,(byte)0};
  +		ExpPtg expPtg = new ExpPtg(array, 0);
  +		//an empty expptg will not be cloned
  +		
  +		formula.setExpressionLength((short)5);
  +		formula.pushExpressionToken(expPtg);
  +		
  +		records.add(new RowRecord());
  +		records.add(formula);	
  +		records.add(new SharedFormulaRecord());
  +		
  +		
  +		sheet = Sheet.createSheet(records, 0);
  +		
  +		sheet.cloneSheet();
  +		
  +	}
  +
  +
  +	/**
  +	 * FormulaRecordAggregates within blanks/values cause values afterwards to not be aggregated.
  +	 * This usually occurs during clones 
  +	 *
  +	 */
  +	public void testValueAggregateWithSharedFormulas() {
  +		Sheet sheet;
  +		List records = new ArrayList();
  +		
  +		FormulaRecord formula = new FormulaRecord();
  +		StringRecord stringRecord = new StringRecord();
  +		FormulaRecordAggregate formulaAggregate = new FormulaRecordAggregate(formula, stringRecord);
  +		
  +		formula.setExpressionLength((short)5);
  +		formula.pushExpressionToken(new ExpPtg());
  +		BlankRecord blank = new BlankRecord();
  +		blank.setColumn((short)0);
  +		blank.setRow(1);
  +		
  +		records.add(new BOFRecord());
  +		records.add(new RowRecord());
  +		
  +		blank.setColumn((short)0);
  +		blank.setRow(1);
  +		
  +		records.add(blank);
  +		records.add(new LabelSSTRecord());
  +		records.add(formula);	
  +		records.add(new SharedFormulaRecord());
  +		records.add(formulaAggregate);
  +		
  +		blank = new BlankRecord();		
  +		blank.setColumn((short)0);
  +		blank.setRow(2);
  +
  +		
  +		records.add(blank);
  +		records.add(new EOFRecord());
  +		
  +		sheet = Sheet.createSheet(records, 0);
  +		ValueRecordsAggregate valueAggregate = sheet.cells;
  +		
  +		assertEquals("Aggregated cells not correct, the blank record following sharedformula
is not here", 3, valueAggregate.getPhysicalNumberOfCells());		
  +		
  +		
  +	}
   
   	public static void main(String [] args) {
   		System.out
  
  
  

Mime
View raw message