poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From one...@apache.org
Subject svn commit: r1814257 - in /poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers: ColumnShifter.java RowShifter.java
Date Sat, 04 Nov 2017 07:29:53 GMT
Author: onealj
Date: Sat Nov  4 07:29:53 2017
New Revision: 1814257

URL: http://svn.apache.org/viewvc?rev=1814257&view=rev
Log:
bug 61474, github #81: fix ColumnShifter#removalNeeded to use columns instead of rows

Modified:
    poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/ColumnShifter.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/ColumnShifter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/ColumnShifter.java?rev=1814257&r1=1814256&r2=1814257&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/ColumnShifter.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/ColumnShifter.java Sat Nov  4 07:29:53
2017
@@ -49,6 +49,7 @@ public abstract class ColumnShifter exte
      * @param n        the number of columns to shift
      * @return an array of affected merged regions, doesn't contain deleted ones
      */
+    // Keep this code in sync with {@link RowShifter#shiftMergedRegions}
     public List<CellRangeAddress> shiftMergedRegions(int startColumn, int endColumn,
int n) {
         List<CellRangeAddress> shiftedRegions = new ArrayList<>();
         Set<Integer> removedIndices = new HashSet<>();
@@ -93,6 +94,7 @@ public abstract class ColumnShifter exte
         return shiftedRegions;
     }
 
+    // Keep in sync with {@link RowShifter#removalNeeded}
     private boolean removalNeeded(CellRangeAddress merged, int startColumn, int endColumn,
int n) {
         final int movedColumns = endColumn - startColumn + 1;
 
@@ -101,10 +103,14 @@ public abstract class ColumnShifter exte
         final CellRangeAddress overwrite;
         if(n > 0) {
             // area is moved down => overwritten area is [endColumn + n - movedColumns,
endColumn + n]
-            overwrite = new CellRangeAddress(Math.max(endColumn + 1, endColumn + n - movedColumns),
endColumn + n, 0, 0);
+            final int firstCol = Math.max(endColumn + 1, endColumn + n - movedColumns);
+            final int lastCol = endColumn + n;
+            overwrite = new CellRangeAddress(0, 0, firstCol, lastCol);
         } else {
             // area is moved up => overwritten area is [startColumn + n, startColumn +
n + movedColumns]
-            overwrite = new CellRangeAddress(startColumn + n, Math.min(startColumn - 1, startColumn
+ n + movedColumns), 0, 0);
+            final int firstCol = startColumn + n;
+            final int lastCol = Math.min(startColumn - 1, startColumn + n + movedColumns);
+            overwrite = new CellRangeAddress(0, 0, firstCol, lastCol);
         }
 
         // if the merged-region and the overwritten area intersect, we need to remove it

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java?rev=1814257&r1=1814256&r2=1814257&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java Sat Nov  4 07:29:53
2017
@@ -51,6 +51,7 @@ public abstract class RowShifter extends
      * @param n        the number of rows to shift
      * @return an array of affected merged regions, doesn't contain deleted ones
      */
+    // Keep this code in sync with {@link ColumnShifter#shiftMergedRegions}
     public List<CellRangeAddress> shiftMergedRegions(int startRow, int endRow, int
n) {
         List<CellRangeAddress> shiftedRegions = new ArrayList<>();
         Set<Integer> removedIndices = new HashSet<>();
@@ -95,6 +96,7 @@ public abstract class RowShifter extends
         return shiftedRegions;
     }
 
+    // Keep in sync with {@link ColumnShifter#removalNeeded}
     private boolean removalNeeded(CellRangeAddress merged, int startRow, int endRow, int
n) {
         final int movedRows = endRow - startRow + 1;
 
@@ -103,10 +105,14 @@ public abstract class RowShifter extends
         final CellRangeAddress overwrite;
         if(n > 0) {
             // area is moved down => overwritten area is [endRow + n - movedRows, endRow
+ n]
-            overwrite = new CellRangeAddress(Math.max(endRow + 1, endRow + n - movedRows),
endRow + n, 0, 0);
+            final int firstRow = Math.max(endRow + 1, endRow + n - movedRows);
+            final int lastRow = endRow + n;
+            overwrite = new CellRangeAddress(firstRow, lastRow, 0, 0);
         } else {
             // area is moved up => overwritten area is [startRow + n, startRow + n + movedRows]
-            overwrite = new CellRangeAddress(startRow + n, Math.min(startRow - 1, startRow
+ n + movedRows), 0, 0);
+            final int firstRow = startRow + n;
+            final int lastRow = Math.min(startRow - 1, startRow + n + movedRows);
+            overwrite = new CellRangeAddress(firstRow, lastRow, 0, 0);
         }
 
         // if the merged-region and the overwritten area intersect, we need to remove it



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


Mime
View raw message