Really clone the merged regions...Thanks to Jason for pointing this out.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353454 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Danny Muid 2003-11-17 21:34:06 +00:00
parent b552f42f82
commit 9d2c36fad3
2 changed files with 18 additions and 1 deletions

View File

@ -56,6 +56,7 @@
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
@ -327,7 +328,12 @@ public class MergeCellsRecord
MergeCellsRecord rec = new MergeCellsRecord(); MergeCellsRecord rec = new MergeCellsRecord();
rec.field_1_num_areas = field_1_num_areas; rec.field_1_num_areas = field_1_num_areas;
rec.field_2_regions = new ArrayList(); rec.field_2_regions = new ArrayList();
rec.field_2_regions.addAll(field_2_regions); Iterator iterator = field_2_regions.iterator();
while (iterator.hasNext()) {
MergedRegion oldRegion = (MergedRegion)iterator.next();
rec.addArea(oldRegion.row_from, oldRegion.col_from, oldRegion.row_to, oldRegion.col_to);
}
return rec; return rec;
} }
} }

View File

@ -55,6 +55,8 @@ package org.apache.poi.hssf.record;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hssf.record.MergeCellsRecord.MergedRegion;
/** /**
* Make sure the merge cells record behaves * Make sure the merge cells record behaves
* @author Danny Mui (dmui at apache dot org) * @author Danny Mui (dmui at apache dot org)
@ -72,6 +74,15 @@ public class TestMergeCellsRecord extends TestCase {
MergeCellsRecord clone = (MergeCellsRecord)merge.clone(); MergeCellsRecord clone = (MergeCellsRecord)merge.clone();
assertNotSame("Merged and cloned objects are the same", merge, clone); assertNotSame("Merged and cloned objects are the same", merge, clone);
MergedRegion mergeRegion = merge.getAreaAt(0);
MergedRegion cloneRegion = clone.getAreaAt(0);
assertNotSame("Should not point to same objects when cloning", mergeRegion, cloneRegion);
assertEquals("New Clone Row From doesnt match", mergeRegion.row_from, cloneRegion.row_from);
assertEquals("New Clone Row To doesnt match", mergeRegion.row_to, cloneRegion.row_to);
assertEquals("New Clone Col From doesnt match", mergeRegion.col_from, cloneRegion.col_from);
assertEquals("New Clone Col To doesnt match", mergeRegion.col_to, cloneRegion.col_to);
merge.removeAreaAt(0); merge.removeAreaAt(0);
assertNotNull("Clone's item not removed", clone.getAreaAt(0)); assertNotNull("Clone's item not removed", clone.getAreaAt(0));
} }