]> source.dussan.org Git - poi.git/commitdiff
Fixed merged pointer issues and brought over from HEAD
authorDanny Mui <dmui@apache.org>
Fri, 27 Jun 2003 23:21:17 +0000 (23:21 +0000)
committerDanny Mui <dmui@apache.org>
Fri, 27 Jun 2003 23:21:17 +0000 (23:21 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/branches/REL_2_BRANCH@353168 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/model/Sheet.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java

index 1dbafd7bc1e690efbc65623432be99384cae0fba..6efa15a60bc52b3f7ce577cd3b39da56e33c6e68 100644 (file)
@@ -469,13 +469,21 @@ public class Sheet implements Model
         numMergedRegions--;
         if (rec.getNumAreas() == 0)
         {
+                               mergedRecords.remove(pos);            
+            if (merged == rec) {
+               //pull up the LAST record for operations when we finally
+               //support continue records for mergedRegions
+               if (mergedRecords.size() > 0) {
+                       merged = (MergeCellsRecord) mergedRecords.get(mergedRecords.size() - 1);
+               } else {
+                       merged = null;
+               }
+            }
             
-            if (merged == rec)
-               merged = (MergeCellsRecord) mergedRecords.get(mergedRecords.size() - 1);
             int removePos = ((Integer) mergedLocs.get(pos)).intValue();
             records.remove(removePos);
-                               mergedRecords.remove(pos);
             mergedLocs.remove(pos);
+            
         }
     }
 
index 66d475edc9392b8f42ae75ca12d978578e941901..f021c5439b13c81a988366c5d547df8dfd396526 100644 (file)
@@ -276,6 +276,25 @@ public class TestHSSFSheet
        assertEquals("Left over region should be starting at row 1", 1, region.getRowFrom());
        
        sheet.removeMergedRegion(0);
+       
+               assertEquals("there should be no merged regions left!", 0, sheet.getNumMergedRegions());
+               
+               //an, add, remove, get(0) would null pointer
+               sheet.addMergedRegion(region);
+               assertEquals("there should now be one merged region!", 1, sheet.getNumMergedRegions());
+               sheet.removeMergedRegion(0);
+               assertEquals("there should now be zero merged regions!", 0, sheet.getNumMergedRegions());
+               //add it again!
+               region.setRowTo(4);
+       
+               sheet.addMergedRegion(region);
+               assertEquals("there should now be one merged region!", 1, sheet.getNumMergedRegions());
+               
+               //should exist now!
+               assertTrue("there isn't more than one merged region in there", 1 <= sheet.getNumMergedRegions());
+               region = sheet.getMergedRegionAt(0);
+               assertEquals("the merged row to doesnt match the one we put in ", 4, region.getRowTo());
+       
     }
 
        public static void main(java.lang.String[] args) {