bug 61474, github #81: pull up methods from RowShifter to BaseRowColShifter, since both row and column shifting should be able to shift formulas, comments, merged regions, conditional formatting, etc; add @since decorators for new *ColumnShifter and *RowColShifter classes

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1814261 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2017-11-04 09:07:32 +00:00
parent 890d6e70e6
commit 37ee513fc9
7 changed files with 41 additions and 37 deletions

View File

@ -28,6 +28,8 @@ import org.apache.poi.util.POILogger;
/**
* Helper for shifting columns up or down
*
* @since POI 4.0.0
*/
// non-Javadoc: When possible, code should be implemented in the ColumnShifter abstract class to avoid duplication with
// {@link org.apache.poi.xssf.usermodel.helpers.XSSFColumnShifter}

View File

@ -28,10 +28,34 @@ import org.apache.poi.util.Internal;
/**
* Class for code common to {@link RowShifter} and {@link ColumnShifter}
* Helper for shifting rows up or down and columns left and right
*
* @since POI 4.0.0
*/
@Internal
public abstract class BaseRowColShifter {
/**
* Updated named ranges
*/
protected abstract void updateNamedRanges(FormulaShifter formulaShifter);
/**
* Update formulas.
*/
protected abstract void updateFormulas(FormulaShifter formulaShifter);
public abstract void updateConditionalFormatting(FormulaShifter formulaShifter);
/**
* Shift the Hyperlink anchors (not the hyperlink text, even if the hyperlink
* is of type LINK_DOCUMENT and refers to a cell that was shifted). Hyperlinks
* do not track the content they point to.
*
* @param formulaShifter the formula shifting policy
*/
public abstract void updateHyperlinks(FormulaShifter formulaShifter);
public static CellRangeAddress shiftRange(FormulaShifter formulaShifter, CellRangeAddress cra, int currentExternSheetIx) {
// FormulaShifter works well in terms of Ptgs - so convert CellRangeAddress to AreaPtg (and back) here
AreaPtg aptg = new AreaPtg(cra.getFirstRow(), cra.getLastRow(), cra.getFirstColumn(), cra.getLastColumn(), false, false, false, false);

View File

@ -29,6 +29,8 @@ import org.apache.poi.util.Beta;
/**
* Helper for shifting columns up or down
*
* @since POI 4.0.0
*/
// non-Javadoc: This abstract class exists to consolidate duplicated code between XSSFColumnShifter and HSSFColumnShifter
// (currently methods sprinkled throughout HSSFSheet)

View File

@ -22,11 +22,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.poi.ss.formula.FormulaShifter;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.Internal;
/**
* Helper for shifting rows up or down
@ -118,35 +115,4 @@ public abstract class RowShifter extends BaseRowColShifter {
// if the merged-region and the overwritten area intersect, we need to remove it
return merged.intersects(overwrite);
}
/**
* Updated named ranges
*/
public abstract void updateNamedRanges(FormulaShifter formulaShifter);
/**
* Update formulas.
*/
public abstract void updateFormulas(FormulaShifter formulaShifter);
/**
* Update the formulas in specified row using the formula shifting policy specified by shifter
*
* @param row the row to update the formulas on
* @param formulaShifter the formula shifting policy
*/
//@Internal
//public abstract void updateRowFormulas(Row row, FormulaShifter formulaShifter);
public abstract void updateConditionalFormatting(FormulaShifter formulaShifter);
/**
* Shift the Hyperlink anchors (not the hyperlink text, even if the hyperlink
* is of type LINK_DOCUMENT and refers to a cell that was shifted). Hyperlinks
* do not track the content they point to.
*
* @param formulaShifter the formula shifting policy
*/
public abstract void updateHyperlinks(FormulaShifter formulaShifter);
}

View File

@ -26,6 +26,8 @@ import org.apache.poi.xssf.usermodel.XSSFSheet;
/**
* Helper for shifting columns up or down
*
* @since POI 4.0.0
*/
// non-Javadoc: When possible, code should be implemented in the ColumnShifter abstract class to avoid duplication with
// {@link org.apache.poi.hssf.usermodel.helpers.HSSFColumnShifter}

View File

@ -37,9 +37,11 @@ import java.util.List;
/**
* Class for code common to {@link XSSFRowShifter} and {@link XSSFColumnShifter}
*
* @since POI 4.0.0
*/
@Internal
/*private*/ final class XSSFRowColShifter extends BaseRowColShifter {
/*private*/ final class XSSFRowColShifter {
private static final POILogger logger = POILogFactory.getLogger(XSSFRowColShifter.class);
private XSSFRowColShifter() { /*no instances for static classes*/}
@ -189,7 +191,7 @@ import java.util.List;
boolean changed = false;
List<CellRangeAddress> temp = new ArrayList<>();
for (CellRangeAddress craOld : cellRanges) {
CellRangeAddress craNew = shiftRange(formulaShifter, craOld, sheetIndex);
CellRangeAddress craNew = BaseRowColShifter.shiftRange(formulaShifter, craOld, sheetIndex);
if (craNew == null) {
changed = true;
continue;
@ -234,7 +236,7 @@ import java.util.List;
XSSFHyperlink xhyperlink = (XSSFHyperlink) hyperlink;
String cellRef = xhyperlink.getCellRef();
CellRangeAddress cra = CellRangeAddress.valueOf(cellRef);
CellRangeAddress shiftedRange = shiftRange(formulaShifter, cra, sheetIndex);
CellRangeAddress shiftedRange = BaseRowColShifter.shiftRange(formulaShifter, cra, sheetIndex);
if (shiftedRange != null && shiftedRange != cra) {
// shiftedRange should not be null. If shiftedRange is null, that means
// that a hyperlink wasn't deleted at the beginning of shiftRows when

View File

@ -47,6 +47,12 @@ public final class XSSFRowShifter extends RowShifter {
XSSFRowColShifter.updateFormulas(sheet, formulaShifter);
}
/**
* Update the formulas in specified row using the formula shifting policy specified by shifter
*
* @param row the row to update the formulas on
* @param formulaShifter the formula shifting policy
*/
@Internal(since="3.15 beta 2")
public void updateRowFormulas(XSSFRow row, FormulaShifter formulaShifter) {
XSSFRowColShifter.updateRowFormulas(row, formulaShifter);