poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Danny Mui <da...@muibros.com>
Subject Re: cvs commit: jakarta-poi/src/java/org/apache/poi/hssf/record M ergeCellsRecord.java
Date Mon, 17 Nov 2003 21:33:25 GMT
You're right....I convinced myself that it would be ok to do so.  Thanks 
for the sharp eye.

Height, Jason wrote:

>Danny,
>
>This still doesn't clone the elements within the collection. (elements
>within field_2_regions). So both collections will be pointing to the same
>object references. A change in one merged region that alters an element in
>field_2_regions will affect the other (if this can happen).
>
>I think that new objects should be placed into the new collection.
>
>Jason
>
>
>-----Original Message-----
>From: dmui@apache.org [mailto:dmui@apache.org] 
>Sent: Tuesday, 18 November 2003 7:41 AM
>To: jakarta-poi-cvs@apache.org
>Subject: cvs commit: jakarta-poi/src/java/org/apache/poi/hssf/record
>MergeCellsRecord.java
>
>dmui        2003/11/17 13:10:35
>
>  Modified:    src/testcases/org/apache/poi/hssf/usermodel Tag:
>                        REL_2_BRANCH TestBugs.java
>               src/java/org/apache/poi/hssf/record Tag: REL_2_BRANCH
>                        MergeCellsRecord.java
>  Added:       src/testcases/org/apache/poi/hssf/record Tag: REL_2_BRANCH
>                        TestMergeCellsRecord.java
>  Log:
>  The cloned reference for merged cells did not create a new collection,
>  so deletes cascaded to the original.
>  Reported by: huri@users.sourceforge.net
>  PR:  22720
>  
>  Revision  Changes    Path
>  No                   revision
>  No                   revision
>  1.1.2.1   +79 -0
>jakarta-poi/src/testcases/org/apache/poi/hssf/record/Attic/TestMergeCellsRec
>ord.java
>  
>  
>  
>  
>  No                   revision
>  No                   revision
>  1.1.2.15  +35 -4
>jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
>  
>  Index: TestBugs.java
>  ===================================================================
>  RCS file:
>/home/cvs/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.j
>ava,v
>  retrieving revision 1.1.2.14
>  retrieving revision 1.1.2.15
>  diff -u -r1.1.2.14 -r1.1.2.15
>  --- TestBugs.java	30 Oct 2003 17:20:26 -0000	1.1.2.14
>  +++ TestBugs.java	17 Nov 2003 21:10:35 -0000	1.1.2.15
>  @@ -54,16 +54,16 @@
>   
>   package org.apache.poi.hssf.usermodel;
>   
>  +import java.io.ByteArrayInputStream;
>  +import java.io.ByteArrayOutputStream;
>   import java.io.File;
>   import java.io.FileInputStream;
>   import java.io.FileOutputStream;
>  -import java.io.ByteArrayInputStream;
>  -import java.io.ByteArrayOutputStream;
>  -import java.io.IOException;
>  -import java.util.Date;
>   
>   import junit.framework.TestCase;
>   
>  +import org.apache.poi.hssf.util.Region;
>  +
>   
>   
>   /**
>  @@ -406,6 +406,37 @@
>           HSSFRow row = sheet.getRow(0);
>           HSSFCell cell = row.getCell((short)0);
>           System.out.println(cell.getStringCellValue());
>  +    }
>  +    
>  +    /**
>  +     * Merged regions were being removed from the parent in cloned sheets
>  +     * @throws Exception
>  +     */
>  +    public void test22720() throws Exception {
>  +       HSSFWorkbook workBook = new HSSFWorkbook();
>  +       workBook.createSheet("TEST");       
>  +       HSSFSheet template = workBook.getSheetAt(0);
>  +       
>  +       template.addMergedRegion(new Region(0, (short)0, 1, (short)2));
>  +       template.addMergedRegion(new Region(1, (short)0, 2, (short)2));
>  +       
>  +       HSSFSheet clone = workBook.cloneSheet(0);
>  +       int originalMerged = template.getNumMergedRegions();
>  +       assertEquals("2 merged regions", 2, originalMerged);
>  +
>  +//        remove merged regions from clone
>  +       for (int i=template.getNumMergedRegions()-1; i>=0; i--) {
>  +         clone.removeMergedRegion(i);
>  +       }
>  +
>  +      assertEquals("Original Sheet's Merged Regions were removed",
>originalMerged, template.getNumMergedRegions());
>  +//        check if template's merged regions are OK
>  +       if (template.getNumMergedRegions()>0) {
>  +          // fetch the first merged region...EXCEPTION OCCURS HERE
>  +          template.getMergedRegionAt(0);
>  +       }       
>  +       //make sure we dont exception
>  +       
>       }
>   }
>   
>  
>  
>  
>  No                   revision
>  No                   revision
>  1.6.2.1   +2 -1
>jakarta-poi/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java
>  
>  Index: MergeCellsRecord.java
>  ===================================================================
>  RCS file:
>/home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/record/MergeCellsRecord.j
>ava,v
>  retrieving revision 1.6
>  retrieving revision 1.6.2.1
>  diff -u -r1.6 -r1.6.2.1
>  --- MergeCellsRecord.java	30 Apr 2003 04:38:47 -0000	1.6
>  +++ MergeCellsRecord.java	17 Nov 2003 21:10:35 -0000	1.6.2.1
>  @@ -326,7 +326,8 @@
>       public Object clone() {
>           MergeCellsRecord rec = new MergeCellsRecord();
>           rec.field_1_num_areas = field_1_num_areas;
>  -        rec.field_2_regions = field_2_regions;
>  +        rec.field_2_regions = new ArrayList();
>  +        rec.field_2_regions.addAll(field_2_regions);
>           return rec;
>       }
>   }
>  
>  
>  
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: poi-dev-help@jakarta.apache.org
>
>--------------------------------------------------------------------------------------------------------------------
>This e-mail (including attachments) is confidential information of Australian Submarine
Corporation Pty Limited (ASC).  It may also be legally privileged.  Unauthorised use and disclosure
is prohibited.  ASC is not taken to have waived confidentiality or privilege if this e-mail
was sent to you in error. If you have received it in error, please notify the sender promptly.
 While ASC takes steps to identify and eliminate viruses, it cannot confirm that this e-mail
is free from them.  You should scan this e-mail for viruses before it is used.  The statements
in this e-mail are those of the sender only, unless specifically stated to be those of ASC
by someone with authority to do so.
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-dev-help@jakarta.apache.org


Mime
View raw message