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:
parent
cd1a9a6452
commit
0fcc9507a7
@ -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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -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());
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user