]> source.dussan.org Git - poi.git/commitdiff
bug 56454: deprecate shiftMerged with unused parameter, move loop-invariant out of...
authorJaven O'Neal <onealj@apache.org>
Mon, 20 Jun 2016 01:49:46 +0000 (01:49 +0000)
committerJaven O'Neal <onealj@apache.org>
Mon, 20 Jun 2016 01:49:46 +0000 (01:49 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1749247 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java

index c7788d09bbcd9c17f1f93fadbf6691d279773e99..36dcaa0f205d02acbf58737e32c442ab712a5808 100644 (file)
@@ -931,7 +931,8 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
     @Override
     public List<CellRangeAddress> getMergedRegions() {
         List<CellRangeAddress> addresses = new ArrayList<CellRangeAddress>();
-        for (int i=0; i < _sheet.getNumMergedRegions(); i++) {
+        int count = _sheet.getNumMergedRegions();
+        for (int i=0; i < count; i++) {
             addresses.add(_sheet.getMergedRegionAt(i));
         }
         return addresses;
@@ -1463,18 +1464,28 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
         _sheet.setTopRow(toprow);
         _sheet.setLeftCol(leftcol);
     }
-
+    
     /**
-     * Shifts the merged regions left or right depending on mode
-     * <p/>
-     * TODO: MODE , this is only row specific
-     *
+     * Shifts, grows, or shrinks the merged regions due to a row shift
+     * 
      * @param startRow the start-index of the rows to shift, zero-based
      * @param endRow the end-index of the rows to shift, zero-based
      * @param n how far to shift, negative to shift up
      * @param isRow unused, kept for backwards compatibility
+     * @deprecated POI 3.15 beta 2. This will be made private in future releases.
      */
     protected void shiftMerged(int startRow, int endRow, int n, boolean isRow) {
+        shiftMerged(startRow, endRow, n);
+    }
+
+    /**
+     * Shifts, grows, or shrinks the merged regions due to a row shift
+     *  
+     * @param startRow the start-index of the rows to shift, zero-based
+     * @param endRow the end-index of the rows to shift, zero-based
+     * @param n how far to shift, negative to shift up
+     */
+    private void shiftMerged(int startRow, int endRow, int n) {
         List<CellRangeAddress> shiftedRegions = new ArrayList<CellRangeAddress>();
         //move merged regions completely if they fall within the new region boundaries when they are shifted
         for (int i = 0; i < getNumMergedRegions(); i++) {
@@ -1489,8 +1500,8 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
             }
 
             //only shift if the region outside the shifted rows is not merged too
-            if (!SheetUtil.containsCell(merged, startRow - 1, 0) &&
-                    !SheetUtil.containsCell(merged, endRow + 1, 0)) {
+            if (!merged.containsRow(startRow - 1) &&
+                    !merged.containsRow(endRow + 1)) {
                 merged.setFirstRow(merged.getFirstRow() + n);
                 merged.setLastRow(merged.getLastRow() + n);
                 //have to remove/add it back
@@ -1589,7 +1600,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
         }
 
         // Shift Merged Regions
-        shiftMerged(startRow, endRow, n, true);
+        shiftMerged(startRow, endRow, n);
         
         // Shift Row Breaks
         _sheet.getPageSettings().shiftRowBreaks(startRow, endRow, n);