This is an automated email from the ASF dual-hosted git repository.

pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git


The following commit(s) were added to refs/heads/trunk by this push:
     new f39b0b19b3 reduce casts in XSSFRowColShifter (#1178)
f39b0b19b3 is described below

commit f39b0b19b39dae5af4498ac0d33018270b18ef23
Author: PJ Fanning <[email protected]>
AuthorDate: Mon Jul 6 17:07:58 2026 +0100

    reduce casts in XSSFRowColShifter (#1178)
---
 .../xssf/usermodel/helpers/XSSFColumnShifter.java  | 10 +++--
 .../xssf/usermodel/helpers/XSSFRowColShifter.java  | 48 ++++++++++------------
 .../poi/xssf/usermodel/helpers/XSSFRowShifter.java | 11 +++--
 3 files changed, 35 insertions(+), 34 deletions(-)

diff --git 
a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFColumnShifter.java
 
b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFColumnShifter.java
index 86711a56bc..8a5a2db62a 100644
--- 
a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFColumnShifter.java
+++ 
b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFColumnShifter.java
@@ -31,28 +31,30 @@ import org.apache.poi.xssf.usermodel.XSSFSheet;
 // {@link org.apache.poi.hssf.usermodel.helpers.HSSFColumnShifter}
 @Beta
 public final class XSSFColumnShifter extends ColumnShifter {
+    private final XSSFSheet xssfSheet;
 
     public XSSFColumnShifter(XSSFSheet sh) {
         super(sh);
+        xssfSheet = sh;
     }
 
     @Override
     public void updateNamedRanges(FormulaShifter formulaShifter) {
-        XSSFRowColShifter.updateNamedRanges(sheet, formulaShifter);
+        XSSFRowColShifter.updateNamedRanges(xssfSheet, formulaShifter);
     }
 
     @Override
     public void updateFormulas(FormulaShifter formulaShifter) {
-        XSSFRowColShifter.updateFormulas(sheet, formulaShifter);
+        XSSFRowColShifter.updateFormulas(xssfSheet, formulaShifter);
     }
 
     @Override
     public void updateConditionalFormatting(FormulaShifter formulaShifter) {
-        XSSFRowColShifter.updateConditionalFormatting(sheet, formulaShifter);
+        XSSFRowColShifter.updateConditionalFormatting(xssfSheet, 
formulaShifter);
     }
 
     @Override
     public void updateHyperlinks(FormulaShifter formulaShifter) {
-        XSSFRowColShifter.updateHyperlinks(sheet, formulaShifter);
+        XSSFRowColShifter.updateHyperlinks(xssfSheet, formulaShifter);
     }
 }
diff --git 
a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowColShifter.java
 
b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowColShifter.java
index 9b5744336f..ab74e5e6ec 100644
--- 
a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowColShifter.java
+++ 
b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowColShifter.java
@@ -52,9 +52,9 @@ import static org.apache.logging.log4j.util.Unbox.box;
      * Updated named ranges
      */
     /*package*/
-    static void updateNamedRanges(Sheet sheet, FormulaShifter formulaShifter) {
-        Workbook wb = sheet.getWorkbook();
-        XSSFEvaluationWorkbook fpb = 
XSSFEvaluationWorkbook.create((XSSFWorkbook) wb);
+    static void updateNamedRanges(XSSFSheet sheet, FormulaShifter 
formulaShifter) {
+        XSSFWorkbook wb = sheet.getWorkbook();
+        XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
         for (Name name : wb.getAllNames()) {
             String formula = name.getRefersToFormula();
             int sheetIndex = name.getSheetIndex();
@@ -71,20 +71,20 @@ import static org.apache.logging.log4j.util.Unbox.box;
     /**
      * Update formulas.
      */
-    /*package*/ static void updateFormulas(Sheet sheet, FormulaShifter 
formulaShifter) {
+    /*package*/ static void updateFormulas(XSSFSheet sheet, FormulaShifter 
formulaShifter) {
         //update formulas on the parent sheet
-        updateSheetFormulas(sheet,formulaShifter);
+        updateSheetFormulas(sheet, formulaShifter);
 
         //update formulas on other sheets
-        Workbook wb = sheet.getWorkbook();
+        XSSFWorkbook wb = sheet.getWorkbook();
         for(Sheet sh : wb)
         {
             if (sheet == sh) continue;
-            updateSheetFormulas(sh, formulaShifter);
+            updateSheetFormulas((XSSFSheet) sh, formulaShifter);
         }
     }
 
-    /*package*/ static void updateSheetFormulas(Sheet sh, FormulaShifter 
formulashifter) {
+    /*package*/ static void updateSheetFormulas(XSSFSheet sh, FormulaShifter 
formulashifter) {
         for (Row r : sh) {
             XSSFRow row = (XSSFRow) r;
             updateRowFormulas(row, formulashifter);
@@ -106,7 +106,7 @@ import static org.apache.logging.log4j.util.Unbox.box;
             if (ctCell.isSetF()) {
                 CTCellFormula f = ctCell.getF();
                 String formula = f.getStringValue();
-                if (formula.length() > 0) {
+                if (!formula.isEmpty()) {
                     String shiftedFormula = shiftFormula(row, formula, 
formulaShifter);
                     if (shiftedFormula != null) {
                         f.setStringValue(shiftedFormula);
@@ -137,12 +137,12 @@ import static org.apache.logging.log4j.util.Unbox.box;
      * <code>null</code> if the formula wasn't modified
      */
     /*package*/
-    static String shiftFormula(Row row, String formula, FormulaShifter 
formulaShifter) {
-        Sheet sheet = row.getSheet();
-        Workbook wb = sheet.getWorkbook();
-        int sheetIndex = wb.getSheetIndex(sheet);
+    static String shiftFormula(XSSFRow row, String formula, FormulaShifter 
formulaShifter) {
+        XSSFSheet sheet = row.getSheet();
+        XSSFWorkbook wb = sheet.getWorkbook();
+        final int sheetIndex = wb.getSheetIndex(sheet);
         final int rowIndex = row.getRowNum();
-        XSSFEvaluationWorkbook fpb = 
XSSFEvaluationWorkbook.create((XSSFWorkbook) wb);
+        XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
 
         try {
             Ptg[] ptgs = FormulaParser.parse(formula, fpb, FormulaType.CELL, 
sheetIndex, rowIndex);
@@ -159,7 +159,7 @@ import static org.apache.logging.log4j.util.Unbox.box;
     }
 
     /*package*/
-    static void updateRefInCTCellFormula(Row row, FormulaShifter 
formulaShifter, CTCellFormula f) {
+    static void updateRefInCTCellFormula(XSSFRow row, FormulaShifter 
formulaShifter, CTCellFormula f) {
         if (f.isSetRef()) { //Range of cells which the formula applies to.
             String ref = f.getRef();
             String shiftedRef = shiftFormula(row, ref, formulaShifter);
@@ -167,16 +167,13 @@ import static org.apache.logging.log4j.util.Unbox.box;
         }
     }
 
-
-
-    /*package*/ static void updateConditionalFormatting(Sheet sheet, 
FormulaShifter formulaShifter) {
-        XSSFSheet xsheet = (XSSFSheet) sheet;
-        XSSFWorkbook wb = xsheet.getWorkbook();
+    /*package*/ static void updateConditionalFormatting(XSSFSheet sheet, 
FormulaShifter formulaShifter) {
+        XSSFWorkbook wb = sheet.getWorkbook();
         int sheetIndex = wb.getSheetIndex(sheet);
         final int rowIndex = -1; //don't care, structured references not 
allowed in conditional formatting
 
         XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
-        CTWorksheet ctWorksheet = xsheet.getCTWorksheet();
+        CTWorksheet ctWorksheet = sheet.getCTWorksheet();
         CTConditionalFormatting[] conditionalFormattingArray = 
ctWorksheet.getConditionalFormattingArray();
         // iterate backwards due to possible calls to 
ctWorksheet.removeConditionalFormatting(j)
         for (int j = conditionalFormattingArray.length - 1; j >= 0; j--) {
@@ -230,19 +227,18 @@ import static org.apache.logging.log4j.util.Unbox.box;
     }
 
 
-    /*package*/ static void updateHyperlinks(Sheet sheet, FormulaShifter 
formulaShifter) {
+    /*package*/ static void updateHyperlinks(XSSFSheet sheet, FormulaShifter 
formulaShifter) {
         final int sheetIndex = sheet.getWorkbook().getSheetIndex(sheet);
 
-        for (Hyperlink hyperlink : sheet.getHyperlinkList()) {
-            XSSFHyperlink xhyperlink = (XSSFHyperlink) hyperlink;
-            String cellRef = xhyperlink.getCellRef();
+        for (XSSFHyperlink hyperlink : sheet.getHyperlinkList()) {
+            String cellRef = hyperlink.getCellRef();
             CellRangeAddress cra = CellRangeAddress.valueOf(cellRef);
             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
                 // identifying rows that should be removed because they will 
be overwritten
-                xhyperlink.setCellReference(shiftedRange.formatAsString());
+                hyperlink.setCellReference(shiftedRange.formatAsString());
             }
         }
     }
diff --git 
a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java
 
b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java
index 0207eaef7b..0dab9cdff9 100644
--- 
a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java
+++ 
b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java
@@ -29,18 +29,21 @@ import org.apache.poi.xssf.usermodel.XSSFSheet;
 // non-Javadoc: When possible, code should be implemented in the RowShifter 
abstract class to avoid duplication with
 // {@link org.apache.poi.hssf.usermodel.helpers.HSSFRowShifter}
 public final class XSSFRowShifter extends RowShifter {
+    private final XSSFSheet xssfSheet;
 
     public XSSFRowShifter(XSSFSheet sh) {
         super(sh);
+        xssfSheet = sh;
     }
+
     @Override
     public void updateNamedRanges(FormulaShifter formulaShifter) {
-        XSSFRowColShifter.updateNamedRanges(sheet, formulaShifter);
+        XSSFRowColShifter.updateNamedRanges(xssfSheet, formulaShifter);
     }
 
     @Override
     public void updateFormulas(FormulaShifter formulaShifter) {
-        XSSFRowColShifter.updateFormulas(sheet, formulaShifter);
+        XSSFRowColShifter.updateFormulas(xssfSheet, formulaShifter);
     }
 
     /**
@@ -56,11 +59,11 @@ public final class XSSFRowShifter extends RowShifter {
 
     @Override
     public void updateConditionalFormatting(FormulaShifter formulaShifter) {
-        XSSFRowColShifter.updateConditionalFormatting(sheet, formulaShifter);
+        XSSFRowColShifter.updateConditionalFormatting(xssfSheet, 
formulaShifter);
     }
 
     @Override
     public void updateHyperlinks(FormulaShifter formulaShifter) {
-        XSSFRowColShifter.updateHyperlinks(sheet, formulaShifter);
+        XSSFRowColShifter.updateHyperlinks(xssfSheet, formulaShifter);
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to