poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From one...@apache.org
Subject svn commit: r1749258 - in /poi/trunk/src: java/org/apache/poi/hssf/usermodel/ java/org/apache/poi/ss/usermodel/ ooxml/java/org/apache/poi/xssf/streaming/ ooxml/java/org/apache/poi/xssf/usermodel/ testcases/org/apache/poi/ss/usermodel/
Date Mon, 20 Jun 2016 03:40:33 GMT
Author: onealj
Date: Mon Jun 20 03:40:32 2016
New Revision: 1749258

URL: http://svn.apache.org/viewvc?rev=1749258&view=rev
Log:
bug 59730: promote XSSFSheet#removeMergedRegions to Sheet interface

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/Sheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java?rev=1749258&r1=1749257&r2=1749258&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java Mon Jun 20 03:40:32 2016
@@ -19,10 +19,12 @@ package org.apache.poi.hssf.usermodel;
 
 import java.io.PrintWriter;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
+import java.util.TreeSet;
 
 import org.apache.poi.ddf.EscherRecord;
 import org.apache.poi.hssf.model.DrawingManager2;
@@ -901,11 +903,22 @@ public final class HSSFSheet implements
      *
      * @param index of the region to unmerge
      */
-
     @Override
     public void removeMergedRegion(int index) {
         _sheet.removeMergedRegion(index);
     }
+    
+    /**
+     * Removes a number of merged regions of cells (hence letting them free)
+     *
+     * @param indices A set of the regions to unmerge
+     */
+    @Override
+    public void removeMergedRegions(Collection<Integer> indices) {
+        for (int i : (new TreeSet<Integer>(indices)).descendingSet()) {
+            _sheet.removeMergedRegion(i);
+        }
+    }
 
     /**
      * returns the number of merged regions

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/Sheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/Sheet.java?rev=1749258&r1=1749257&r2=1749258&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/Sheet.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/Sheet.java Mon Jun 20 03:40:32 2016
@@ -17,6 +17,7 @@
 
 package org.apache.poi.ss.usermodel;
 
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -331,6 +332,13 @@ public interface Sheet extends Iterable<
      * @param index of the region to unmerge
      */
     void removeMergedRegion(int index);
+    
+    /**
+     * Removes a number of merged regions of cells (hence letting them free)
+     *
+     * @param indices A set of the regions to unmerge
+     */
+    void removeMergedRegions(Collection<Integer> indices);
 
     /**
      * Returns the number of merged regions

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java?rev=1749258&r1=1749257&r2=1749258&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java Mon Jun 20 03:40:32
2016
@@ -463,6 +463,17 @@ public class SXSSFSheet implements Sheet
     {
         _sh.removeMergedRegion(index);
     }
+    
+    /**
+     * Removes a merged region of cells (hence letting them free)
+     *
+     * @param indices of the regions to unmerge
+     */
+    @Override
+    public void removeMergedRegions(Collection<Integer> indices)
+    {
+        _sh.removeMergedRegions(indices);
+    }
 
     /**
      * Returns the number of merged regions

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1749258&r1=1749257&r2=1749258&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Mon Jun 20 03:40:32
2016
@@ -1867,6 +1867,7 @@ public class XSSFSheet extends POIXMLDoc
      *
      * @param indices A set of the regions to unmerge
      */
+    @Override
     public void removeMergedRegions(Collection<Integer> indices) {
         if (!worksheet.isSetMergeCells()) return;
         

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java?rev=1749258&r1=1749257&r2=1749258&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java Mon Jun 20 03:40:32
2016
@@ -27,10 +27,17 @@ import static org.junit.Assert.fail;
 import static org.junit.Assume.assumeTrue;
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Set;
 
 import org.apache.poi.hssf.util.PaneInformation;
 import org.apache.poi.ss.ITestDataProvider;
@@ -418,6 +425,36 @@ public abstract class BaseTestSheet {
         
         wb.close();
     }
+    
+    /**
+     * Remove multiple merged regions
+     */
+    @Test
+    public void removeMergedRegions() throws IOException {
+        Workbook wb = _testDataProvider.createWorkbook();
+        Sheet sheet = wb.createSheet();
+        
+        Map<Integer, CellRangeAddress> mergedRegions = new HashMap<Integer, CellRangeAddress>();
+        for (int r=0; r<10; r++) {
+            CellRangeAddress region = new CellRangeAddress(r, r, 0, 1);
+            mergedRegions.put(r, region);
+            sheet.addMergedRegion(region);
+        }
+        assertCollectionEquals(mergedRegions.values(), sheet.getMergedRegions());
+        
+        Collection<Integer> removed = Arrays.asList(0, 2, 3, 6, 8);
+        mergedRegions.keySet().removeAll(removed);
+        sheet.removeMergedRegions(removed);
+        assertCollectionEquals(mergedRegions.values(), sheet.getMergedRegions());
+        
+        wb.close();
+    }
+    
+    private static void assertCollectionEquals(Collection<? extends Object> expected,
Collection<? extends Object> actual) {
+        Set<Object> e = new HashSet<Object>(expected);
+        Set<Object> a = new HashSet<Object>(actual);
+        assertEquals(e, a);
+    }
 
     @Test
     public void shiftMerged() throws IOException {



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


Mime
View raw message