Add clone() to FormulaRecordAggregate

Original patch supplied by Henning Boeger
Changed to make it deeper clone, added clone to StringRecord in the process
Also added a test.


git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353033 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Avik Sengupta 2003-03-20 20:01:17 +00:00
parent cd1a9a6452
commit 0fcc9507a7
3 changed files with 51 additions and 0 deletions

View File

@ -237,5 +237,14 @@ public class StringRecord
buffer.append("[/STRING]\n");
return buffer.toString();
}
public Object clone() {
StringRecord rec = new StringRecord();
rec.field_1_string_length = this.field_1_string_length;
rec.field_2_unicode_flag= this.field_2_unicode_flag;
rec.field_3_string = this.field_3_string;
return rec;
}
}

View File

@ -205,6 +205,14 @@ public class FormulaRecordAggregate
{
return formulaRecord.toString();
}
/**
* @see java.lang.Object#clone()
*/
public Object clone() {
return new FormulaRecordAggregate((FormulaRecord) this.formulaRecord.clone(), (StringRecord) this.stringRecord.clone());
}
}

View File

@ -0,0 +1,34 @@
/*
* TestFormulaRecordAggregate.java
*
* Created on March 21, 2003, 12:32 AM
*/
package org.apache.poi.hssf.record.aggregates;
import org.apache.poi.hssf.record.FormulaRecord;
import org.apache.poi.hssf.record.StringRecord;
/**
*
* @author avik
*/
public class TestFormulaRecordAggregate extends junit.framework.TestCase {
/** Creates a new instance of TestFormulaRecordAggregate */
public TestFormulaRecordAggregate(String arg) {
super(arg);
}
public void testClone() {
FormulaRecord f = new FormulaRecord();
StringRecord s = new StringRecord();
FormulaRecordAggregate fagg = new FormulaRecordAggregate(f,s);
FormulaRecordAggregate newFagg = (FormulaRecordAggregate) fagg.clone();
assertTrue("objects are different", fagg!=newFagg);
assertTrue("deep clone", fagg.getFormulaRecord() != newFagg.getFormulaRecord());
assertTrue("deep clone", fagg.getStringRecord() != newFagg.getStringRecord());
}
}