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
This commit is contained in:
Javen O'Neal 2016-06-20 01:49:46 +00:00
parent 2804197bdb
commit 55cb9381de

View File

@ -931,7 +931,8 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
@Override @Override
public List<CellRangeAddress> getMergedRegions() { public List<CellRangeAddress> getMergedRegions() {
List<CellRangeAddress> addresses = new ArrayList<CellRangeAddress>(); 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)); addresses.add(_sheet.getMergedRegionAt(i));
} }
return addresses; return addresses;
@ -1465,16 +1466,26 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
} }
/** /**
* Shifts the merged regions left or right depending on mode * Shifts, grows, or shrinks the merged regions due to a row shift
* <p/>
* TODO: MODE , this is only row specific
* *
* @param startRow the start-index of the rows to shift, zero-based * @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 endRow the end-index of the rows to shift, zero-based
* @param n how far to shift, negative to shift up * @param n how far to shift, negative to shift up
* @param isRow unused, kept for backwards compatibility * @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) { 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>(); List<CellRangeAddress> shiftedRegions = new ArrayList<CellRangeAddress>();
//move merged regions completely if they fall within the new region boundaries when they are shifted //move merged regions completely if they fall within the new region boundaries when they are shifted
for (int i = 0; i < getNumMergedRegions(); i++) { 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 //only shift if the region outside the shifted rows is not merged too
if (!SheetUtil.containsCell(merged, startRow - 1, 0) && if (!merged.containsRow(startRow - 1) &&
!SheetUtil.containsCell(merged, endRow + 1, 0)) { !merged.containsRow(endRow + 1)) {
merged.setFirstRow(merged.getFirstRow() + n); merged.setFirstRow(merged.getFirstRow() + n);
merged.setLastRow(merged.getLastRow() + n); merged.setLastRow(merged.getLastRow() + n);
//have to remove/add it back //have to remove/add it back
@ -1589,7 +1600,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
} }
// Shift Merged Regions // Shift Merged Regions
shiftMerged(startRow, endRow, n, true); shiftMerged(startRow, endRow, n);
// Shift Row Breaks // Shift Row Breaks
_sheet.getPageSettings().shiftRowBreaks(startRow, endRow, n); _sheet.getPageSettings().shiftRowBreaks(startRow, endRow, n);