From 4aef39ea237e5a7053477ac580de70e4db7a4f89 Mon Sep 17 00:00:00 2001 From: Danny Mui Date: Mon, 17 Nov 2003 21:34:06 +0000 Subject: [PATCH] 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 --- .../org/apache/poi/hssf/record/MergeCellsRecord.java | 8 +++++++- .../apache/poi/hssf/record/TestMergeCellsRecord.java | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java b/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java index 62bbafbfab..0d0b2684df 100644 --- a/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java +++ b/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java @@ -56,6 +56,7 @@ package org.apache.poi.hssf.record; import java.util.ArrayList; +import java.util.Iterator; import org.apache.poi.util.LittleEndian; @@ -327,7 +328,12 @@ public class MergeCellsRecord MergeCellsRecord rec = new MergeCellsRecord(); rec.field_1_num_areas = field_1_num_areas; 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; } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java b/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java index 2b1a7c6b9d..54c87a567a 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java @@ -55,6 +55,8 @@ package org.apache.poi.hssf.record; import junit.framework.TestCase; +import org.apache.poi.hssf.record.MergeCellsRecord.MergedRegion; + /** * Make sure the merge cells record behaves * @author Danny Mui (dmui at apache dot org) @@ -72,6 +74,15 @@ public class TestMergeCellsRecord extends TestCase { MergeCellsRecord clone = (MergeCellsRecord)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); assertNotNull("Clone's item not removed", clone.getAreaAt(0)); } -- 2.39.5