From: Javen O'Neal Date: Mon, 20 Jun 2016 01:49:46 +0000 (+0000) Subject: bug 56454: deprecate shiftMerged with unused parameter, move loop-invariant out of... X-Git-Tag: REL_3_15_BETA2~37 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fe73d687cdc596bfde4b695cd9be9a688c318877;p=poi.git bug 56454: deprecate shiftMerged with unused parameter, move loop-invariant out of for-loop git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1749247 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java index c7788d09bb..36dcaa0f20 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java @@ -931,7 +931,8 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { @Override public List getMergedRegions() { List addresses = new ArrayList(); - 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 - *

- * 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 shiftedRegions = new ArrayList(); //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);