From a745ce2c4e33e2af1724befd4e3d8ba977ad4665 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Tue, 26 Sep 2017 08:26:05 +0000 Subject: [PATCH] Replace deprecated CellReference class and some other warnings fixed git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1809714 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hssf/record/TableRecord.java | 4 +- .../poi/hssf/usermodel/HSSFPatriarch.java | 10 +- .../poi/hssf/usermodel/HSSFWorkbook.java | 12 +- .../poi/hssf/usermodel/TestBug42464.java | 7 +- .../poi/hssf/usermodel/TestFormulas.java | 129 ++++++++---------- .../poi/ss/formula/TestEvaluationCache.java | 7 +- .../BaseTestFunctionsFromSpreadsheet.java | 22 ++- .../ptg/TestExternalNameReference.java | 2 +- 8 files changed, 82 insertions(+), 111 deletions(-) diff --git a/src/java/org/apache/poi/hssf/record/TableRecord.java b/src/java/org/apache/poi/hssf/record/TableRecord.java index 4fa685190b..2dd1d0ee01 100644 --- a/src/java/org/apache/poi/hssf/record/TableRecord.java +++ b/src/java/org/apache/poi/hssf/record/TableRecord.java @@ -19,7 +19,7 @@ package org.apache.poi.hssf.record; import org.apache.poi.ss.formula.ptg.TblPtg; import org.apache.poi.hssf.util.CellRangeAddress8Bit; -import org.apache.poi.hssf.util.CellReference; +import org.apache.poi.ss.util.CellReference; import org.apache.poi.util.BitField; import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.HexDump; @@ -156,7 +156,7 @@ public final class TableRecord extends SharedValueRecordBase { } public String toString() { - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); buffer.append("[TABLE]\n"); buffer.append(" .range = ").append(getRange()).append("\n"); buffer.append(" .flags = ") .append(HexDump.byteToHex(field_5_flags)).append("\n"); diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java b/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java index 3c4385ab60..c52d4c8baf 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java @@ -42,7 +42,7 @@ import org.apache.poi.hssf.record.FtCfSubRecord; import org.apache.poi.hssf.record.FtPioGrbitSubRecord; import org.apache.poi.hssf.record.NoteRecord; import org.apache.poi.hssf.record.ObjRecord; -import org.apache.poi.hssf.util.CellReference; +import org.apache.poi.ss.util.CellReference; import org.apache.poi.poifs.filesystem.DirectoryEntry; import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.ss.usermodel.Chart; @@ -119,7 +119,7 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing tailRecords = _boundAggregate.getTailRecords(); - /** + /* * contains coordinates of comments we iterate over */ Set coordinates = new HashSet<>(tailRecords.size()); @@ -392,8 +392,7 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing iterator = _shapes.iterator(); iterator.hasNext(); ) { - HSSFShape shape = iterator.next(); + for (HSSFShape shape : _shapes) { count += shape.countOfAllChildren(); } return count; @@ -450,8 +449,7 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing it = optRecord.getEscherProperties().iterator(); it.hasNext(); ) { - EscherProperty prop = it.next(); + for (EscherProperty prop : optRecord.getEscherProperties()) { if (prop.getPropertyNumber() == 896 && prop.isComplex()) { EscherComplexProperty cp = (EscherComplexProperty) prop; String str = StringUtil.getFromUnicodeLE(cp.getComplexData()); diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index b8100d2767..70d947ee5f 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -82,7 +82,6 @@ import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor; import org.apache.poi.hssf.record.common.UnicodeString; import org.apache.poi.hssf.record.crypto.Biff8DecryptingStream; import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; -import org.apache.poi.hssf.util.CellReference; import org.apache.poi.poifs.crypt.ChunkedCipherOutputStream; import org.apache.poi.poifs.crypt.Decryptor; import org.apache.poi.poifs.crypt.EncryptionInfo; @@ -110,6 +109,7 @@ import org.apache.poi.ss.usermodel.Row.MissingCellPolicy; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.SheetVisibility; import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.util.CellReference; import org.apache.poi.util.Configurator; import org.apache.poi.util.HexDump; import org.apache.poi.util.IOUtils; @@ -1367,12 +1367,9 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss */ @Override public void write(File newFile) throws IOException { - POIFSFileSystem fs = POIFSFileSystem.create(newFile); - try { + try (POIFSFileSystem fs = POIFSFileSystem.create(newFile)) { write(fs); fs.writeFilesystem(); - } finally { - fs.close(); } } @@ -1393,12 +1390,9 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss */ @Override public void write(OutputStream stream) throws IOException { - NPOIFSFileSystem fs = new NPOIFSFileSystem(); - try { + try (NPOIFSFileSystem fs = new NPOIFSFileSystem()) { write(fs); fs.writeFilesystem(stream); - } finally { - fs.close(); } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java index f0f95261a7..5e414f08a7 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java @@ -24,8 +24,7 @@ import java.util.Iterator; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.record.FormulaRecord; import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate; -import org.apache.poi.hssf.util.CellReference; -import org.apache.poi.ss.formula.ptg.Ptg; +import org.apache.poi.ss.util.CellReference; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellValue; @@ -73,9 +72,9 @@ public final class TestBug42464 { } FormulaRecordAggregate record = (FormulaRecordAggregate) cell.getCellValueRecord(); FormulaRecord r = record.getFormulaRecord(); - Ptg[] ptgs = r.getParsedExpression(); + /*Ptg[] ptgs =*/ r.getParsedExpression(); - String cellRef = new CellReference(row.getRowNum(), cell.getColumnIndex(), false, false).formatAsString(); + /*String cellRef =*/ new CellReference(row.getRowNum(), cell.getColumnIndex(), false, false).formatAsString(); // if(false && cellRef.equals("BP24")) { // TODO - replace System.out.println()s with asserts // System.out.print(cellRef); // System.out.println(" - has " + ptgs.length + " ptgs:"); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java index 73d0de5828..fc065a6489 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java @@ -28,7 +28,7 @@ import java.util.Date; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.model.HSSFFormulaParser; -import org.apache.poi.hssf.util.CellReference; +import org.apache.poi.ss.util.CellReference; import org.apache.poi.ss.formula.FormulaType; import org.apache.poi.ss.formula.ptg.NamePtg; import org.apache.poi.ss.formula.ptg.Ptg; @@ -52,8 +52,8 @@ public final class TestFormulas { HSSFWorkbook wb1 = new HSSFWorkbook(); HSSFSheet s = wb1.createSheet(); - HSSFRow r = null; - HSSFCell c = null; + HSSFRow r; + HSSFCell c; //get our minimum values r = s.createRow(1); @@ -165,8 +165,8 @@ public final class TestFormulas { private static void floatTest(String operator) throws IOException { HSSFWorkbook wb1 = new HSSFWorkbook(); HSSFSheet s = wb1.createSheet(); - HSSFRow r = null; - HSSFCell c = null; + HSSFRow r; + HSSFCell c; //get our minimum values @@ -240,8 +240,8 @@ public final class TestFormulas { private static void operationRefTest(String operator) throws IOException { HSSFWorkbook wb1 = new HSSFWorkbook(); HSSFSheet s = wb1.createSheet(); - HSSFRow r = null; - HSSFCell c = null; + HSSFRow r; + HSSFCell c; //get our minimum values r = s.createRow(0); @@ -253,12 +253,12 @@ public final class TestFormulas { for (int y = 1; y < 256 && y > 0; y++) { - String ref=null; - String ref2=null; - short refx1=0; - short refy1=0; - short refx2=0; - short refy2=0; + String ref; + String ref2; + short refx1; + short refy1; + short refx2; + short refy2; if (x +50 < Short.MAX_VALUE) { refx1=(short)(x+50); refx2=(short)(x+46); @@ -309,8 +309,8 @@ public final class TestFormulas { private static void operationalRefVerify(String operator, HSSFWorkbook wb) { HSSFSheet s = wb.getSheetAt(0); - HSSFRow r = null; - HSSFCell c = null; + HSSFRow r; + HSSFCell c; //get our minimum values r = s.getRow(0); @@ -376,8 +376,8 @@ public final class TestFormulas { private static void orderTest(String formula) throws IOException { HSSFWorkbook wb1 = new HSSFWorkbook(); HSSFSheet s = wb1.createSheet(); - HSSFRow r = null; - HSSFCell c = null; + HSSFRow r; + HSSFCell c; //get our minimum values r = s.createRow(0); @@ -403,8 +403,8 @@ public final class TestFormulas { private static void binomialOperator(String operator) throws IOException { HSSFWorkbook wb1 = new HSSFWorkbook(); HSSFSheet s = wb1.createSheet(); - HSSFRow r = null; - HSSFCell c = null; + HSSFRow r; + HSSFCell c; //get our minimum values r = s.createRow(0); @@ -440,8 +440,8 @@ public final class TestFormulas { */ private static void binomialVerify(String operator, HSSFWorkbook wb) { HSSFSheet s = wb.getSheetAt(0); - HSSFRow r = null; - HSSFCell c = null; + HSSFRow r; + HSSFCell c; //get our minimum values r = s.getRow(0); @@ -481,8 +481,8 @@ public final class TestFormulas { HSSFWorkbook wb1 = new HSSFWorkbook(); HSSFSheet s = wb1.createSheet(); - HSSFRow r = null; - HSSFCell c = null; + HSSFRow r; + HSSFCell c; r = s.createRow(0); @@ -509,8 +509,8 @@ public final class TestFormulas { HSSFWorkbook wb1 = new HSSFWorkbook(); HSSFSheet s = wb1.createSheet(); - HSSFRow r = null; - HSSFCell c = null; + HSSFRow r; + HSSFCell c; r = s.createRow(0); @@ -539,8 +539,8 @@ public final class TestFormulas { HSSFWorkbook wb1 = new HSSFWorkbook(); HSSFSheet s = wb1.createSheet(); - HSSFRow r = null; - HSSFCell c = null; + HSSFRow r; + HSSFCell c; r = s.createRow(0); @@ -608,8 +608,8 @@ public final class TestFormulas { public void testSheetFunctions() throws IOException { HSSFWorkbook wb1 = new HSSFWorkbook(); HSSFSheet s = wb1.createSheet("A"); - HSSFRow r = null; - HSSFCell c = null; + HSSFRow r; + HSSFCell c; r = s.createRow(0); c = r.createCell(0);c.setCellValue(1); c = r.createCell(1);c.setCellValue(2); @@ -638,8 +638,8 @@ public final class TestFormulas { FileOutputStream out = new FileOutputStream(file); HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet s = wb.createSheet(); - HSSFRow r = null; - HSSFCell c = null; + HSSFRow r; + HSSFCell c; r = s.createRow(0); @@ -676,8 +676,8 @@ public final class TestFormulas { public void testStringFormulas() throws IOException { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet s = wb.createSheet("A"); - HSSFRow r = null; - HSSFCell c = null; + HSSFRow r; + HSSFCell c; r = s.createRow(0); c=r.createCell(1); c.setCellFormula("UPPER(\"abc\")"); c=r.createCell(2); c.setCellFormula("LOWER(\"ABC\")"); @@ -699,8 +699,8 @@ public final class TestFormulas { HSSFWorkbook wb1 = new HSSFWorkbook(); HSSFSheet s = wb1.createSheet("A"); - HSSFRow r = null; - HSSFCell c = null; + HSSFRow r; + HSSFCell c; r = s.createRow(0); c=r.createCell(1); c.setCellFormula("IF(A1 data, HSSFSheet sheet, final int startRowIndex, String testFocusFunctionName, String filename) { + private static void processFunctionGroup(List data, HSSFSheet sheet, final int startRowIndex, String filename) { HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet.getWorkbook()); String currentGroupComment = ""; @@ -224,13 +222,13 @@ public abstract class BaseTestFunctionsFromSpreadsheet { return ""; } - private static String formatValue(HSSFCell expecedCell) { - switch (expecedCell.getCellType()) { + private static String formatValue(HSSFCell expectedCell) { + switch (expectedCell.getCellType()) { case BLANK: return ""; - case BOOLEAN: return Boolean.toString(expecedCell.getBooleanCellValue()); - case NUMERIC: return Double.toString(expecedCell.getNumericCellValue()); - case STRING: return expecedCell.getRichStringCellValue().getString(); - default: fail("Unexpected cell type of expected value (" + expecedCell.getCellType() + ")"); + case BOOLEAN: return Boolean.toString(expectedCell.getBooleanCellValue()); + case NUMERIC: return Double.toString(expectedCell.getNumericCellValue()); + case STRING: return expectedCell.getRichStringCellValue().getString(); + default: fail("Unexpected cell type of expected value (" + expectedCell.getCellType() + ")"); } return ""; } diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestExternalNameReference.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestExternalNameReference.java index 16c77fdfb9..82bc535dd4 100644 --- a/src/testcases/org/apache/poi/ss/formula/ptg/TestExternalNameReference.java +++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestExternalNameReference.java @@ -24,7 +24,7 @@ import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.hssf.util.CellReference; +import org.apache.poi.ss.util.CellReference; /** * Tests for proper calculation of named ranges from external workbooks. * -- 2.39.5