From 37ee513fc9616f4cb2162af0eca579753529ca28 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Sat, 4 Nov 2017 09:07:32 +0000 Subject: [PATCH] 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 --- .../usermodel/helpers/HSSFColumnShifter.java | 2 ++ .../usermodel/helpers/BaseRowColShifter.java | 24 +++++++++++++ .../ss/usermodel/helpers/ColumnShifter.java | 2 ++ .../poi/ss/usermodel/helpers/RowShifter.java | 34 ------------------- .../usermodel/helpers/XSSFColumnShifter.java | 2 ++ .../usermodel/helpers/XSSFRowColShifter.java | 8 +++-- .../usermodel/helpers/XSSFRowShifter.java | 6 ++++ 7 files changed, 41 insertions(+), 37 deletions(-) diff --git a/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFColumnShifter.java b/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFColumnShifter.java index 051e24ad5d..2e9af38f2d 100644 --- a/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFColumnShifter.java +++ b/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFColumnShifter.java @@ -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} diff --git a/src/java/org/apache/poi/ss/usermodel/helpers/BaseRowColShifter.java b/src/java/org/apache/poi/ss/usermodel/helpers/BaseRowColShifter.java index 306e515220..3b92cf26dd 100644 --- a/src/java/org/apache/poi/ss/usermodel/helpers/BaseRowColShifter.java +++ b/src/java/org/apache/poi/ss/usermodel/helpers/BaseRowColShifter.java @@ -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); diff --git a/src/java/org/apache/poi/ss/usermodel/helpers/ColumnShifter.java b/src/java/org/apache/poi/ss/usermodel/helpers/ColumnShifter.java index fdd064a3d7..444039a41b 100644 --- a/src/java/org/apache/poi/ss/usermodel/helpers/ColumnShifter.java +++ b/src/java/org/apache/poi/ss/usermodel/helpers/ColumnShifter.java @@ -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) diff --git a/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java b/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java index ad7520715b..d0ac13d7f2 100644 --- a/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java +++ b/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java @@ -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); - } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFColumnShifter.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFColumnShifter.java index 12ca45b81a..8f8a712000 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFColumnShifter.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFColumnShifter.java @@ -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} diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowColShifter.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowColShifter.java index 03907b6c70..50ed79313f 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowColShifter.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowColShifter.java @@ -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 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 diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java index 6b5d8256dd..ebcb095d6f 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java @@ -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); -- 2.39.5