From 753f6f9dc676404d7b0af5ad1ed3a4a744ba691b Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Thu, 22 Feb 2018 22:32:25 +0000 Subject: [PATCH] further uptake of int methods for font lookups git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1825103 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hssf/usermodel/HSSFCellStyle.java | 2 +- src/java/org/apache/poi/ss/util/CellUtil.java | 2 +- .../streaming/TestAutoSizeColumnTracker.java | 2 +- .../TestSXSSFSheetAutoSizeColumn.java | 2 +- .../poi/xssf/usermodel/TestXSSFSheet.java | 2 +- .../apache/poi/hssf/usermodel/TestBugs.java | 34 +++++++++---------- .../apache/poi/ss/usermodel/BaseTestFont.java | 28 +++++++-------- 7 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java index a2169018c..fde539c6e 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java @@ -849,7 +849,7 @@ public final class HSSFCellStyle implements CellStyle { FontRecord fr = _workbook.createNewFont(); fr.cloneStyleFrom( source._workbook.getFontRecordAt( - source.getFontIndex() + source.getFontIntIndex() ) ); diff --git a/src/java/org/apache/poi/ss/util/CellUtil.java b/src/java/org/apache/poi/ss/util/CellUtil.java index 15036761a..ce72bd88e 100644 --- a/src/java/org/apache/poi/ss/util/CellUtil.java +++ b/src/java/org/apache/poi/ss/util/CellUtil.java @@ -346,7 +346,7 @@ public final class CellUtil { put(properties, FILL_PATTERN, style.getFillPattern()); put(properties, FILL_FOREGROUND_COLOR, style.getFillForegroundColor()); put(properties, FILL_BACKGROUND_COLOR, style.getFillBackgroundColor()); - put(properties, FONT, style.getFontIndex()); + put(properties, FONT, style.getFontIntIndex()); put(properties, HIDDEN, style.getHidden()); put(properties, INDENTION, style.getIndention()); put(properties, LEFT_BORDER_COLOR, style.getLeftBorderColor()); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestAutoSizeColumnTracker.java b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestAutoSizeColumnTracker.java index 02a0a3334..6afcdd8d9 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestAutoSizeColumnTracker.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestAutoSizeColumnTracker.java @@ -210,7 +210,7 @@ public class TestAutoSizeColumnTracker { private static void assumeRequiredFontsAreInstalled(final Workbook workbook, final Cell cell) { // autoSize will fail if required fonts are not installed, skip this test then - Font font = workbook.getFontAt(cell.getCellStyle().getFontIndex()); + Font font = workbook.getFontAt(cell.getCellStyle().getFontIntIndex()); Assume.assumeTrue("Cannot verify autoSizeColumn() because the necessary Fonts are not installed on this machine: " + font, SheetUtil.canComputeColumnWidth(font)); } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFSheetAutoSizeColumn.java b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFSheetAutoSizeColumn.java index 8a82e8d4c..04dd83ed5 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFSheetAutoSizeColumn.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFSheetAutoSizeColumn.java @@ -350,7 +350,7 @@ public class TestSXSSFSheetAutoSizeColumn { private static void assumeRequiredFontsAreInstalled(final Workbook workbook, final Cell cell) { // autoSize will fail if required fonts are not installed, skip this test then - Font font = workbook.getFontAt(cell.getCellStyle().getFontIndex()); + Font font = workbook.getFontAt(cell.getCellStyle().getFontIntIndex()); Assume.assumeTrue("Cannot verify autoSizeColumn() because the necessary Fonts are not installed on this machine: " + font, SheetUtil.canComputeColumnWidth(font)); } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java index c8b5821c4..b26d177df 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java @@ -324,7 +324,7 @@ public final class TestXSSFSheet extends BaseTestXSheet { cellXf.setXfId(1); stylesTable.putCellXf(cellXf); XSSFCellStyle cellStyle = new XSSFCellStyle(1, 1, stylesTable, null); - assertEquals(1, cellStyle.getFontIndex()); + assertEquals(1, cellStyle.getFontIntIndex()); sheet.setDefaultColumnStyle(3, cellStyle); assertEquals(1, ctWorksheet.getColsArray(0).getColArray(0).getStyle()); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index 52a6c1d22..ca96f0d7c 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -1017,7 +1017,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { @Test public void bug45338() throws IOException { HSSFWorkbook wb = new HSSFWorkbook(); - assertEquals(4, wb.getNumberOfFonts()); + assertEquals(4, wb.getNumberOfFontsAsInt()); HSSFSheet s = wb.createSheet(); s.createRow(0); @@ -1025,7 +1025,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { s.getRow(0).createCell(0); s.getRow(1).createCell(0); - assertEquals(4, wb.getNumberOfFonts()); + assertEquals(4, wb.getNumberOfFontsAsInt()); HSSFFont f1 = wb.getFontAt((short) 0); assertFalse(f1.getBold()); @@ -1033,19 +1033,19 @@ public final class TestBugs extends BaseTestBugzillaIssues { // Check that asking for the same font // multiple times gives you the same thing. // Otherwise, our tests wouldn't work! - assertSame(wb.getFontAt((short) 0), wb.getFontAt((short) 0)); + assertSame(wb.getFontAt(0), wb.getFontAt(0)); assertEquals( - wb.getFontAt((short) 0), - wb.getFontAt((short) 0) + wb.getFontAt(0), + wb.getFontAt(0) ); assertEquals( - wb.getFontAt((short) 2), - wb.getFontAt((short) 2) + wb.getFontAt(2), + wb.getFontAt(2) ); assertTrue( - wb.getFontAt((short) 0) + wb.getFontAt(0) != - wb.getFontAt((short) 2) + wb.getFontAt(2) ); // Look for a new font we have @@ -1058,10 +1058,10 @@ public final class TestBugs extends BaseTestBugzillaIssues { ); HSSFFont nf = wb.createFont(); - assertEquals(5, wb.getNumberOfFonts()); + assertEquals(5, wb.getNumberOfFontsAsInt()); assertEquals(5, nf.getIndex()); - assertEquals(nf, wb.getFontAt((short) 5)); + assertEquals(nf, wb.getFontAt(5)); nf.setBold(false); nf.setColor((short) 123); @@ -1072,8 +1072,8 @@ public final class TestBugs extends BaseTestBugzillaIssues { nf.setTypeOffset((short) 2); nf.setUnderline((byte) 2); - assertEquals(5, wb.getNumberOfFonts()); - assertEquals(nf, wb.getFontAt((short) 5)); + assertEquals(5, wb.getNumberOfFontsAsInt()); + assertEquals(nf, wb.getFontAt(5)); // Find it now assertNotNull( @@ -3130,20 +3130,20 @@ public final class TestBugs extends BaseTestBugzillaIssues { Cell cell = row.getCell(1); CellStyle style = cell.getCellStyle(); - assertEquals(26, style.getFontIndex()); + assertEquals(26, style.getFontIntIndex()); row = sheet.getRow(3); cell = row.getCell(1); style = cell.getCellStyle(); - assertEquals(28, style.getFontIndex()); + assertEquals(28, style.getFontIntIndex()); // check the two fonts - HSSFFont font = wb.getFontAt((short) 26); + HSSFFont font = wb.getFontAt(26); assertTrue(font.getBold()); assertEquals(10, font.getFontHeightInPoints()); assertEquals("\uFF2D\uFF33 \uFF30\u30B4\u30B7\u30C3\u30AF", font.getFontName()); - font = wb.getFontAt((short) 28); + font = wb.getFontAt(28); assertTrue(font.getBold()); assertEquals(10, font.getFontHeightInPoints()); assertEquals("\uFF2D\uFF33 \uFF30\u30B4\u30B7\u30C3\u30AF", font.getFontName()); diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java index 30756ab60..889b72caf 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java @@ -101,9 +101,9 @@ public abstract class BaseTestFont { font.setStrikeout(true); font.setColor(IndexedColors.YELLOW.getIndex()); font.setFontName("Courier"); - short font1Idx = font.getIndex(); + int font1Idx = font.getIndexAsInt(); wb1.createCellStyle().setFont(font); - assertEquals(num0 + 1, wb1.getNumberOfFonts()); + assertEquals(num0 + 1, wb1.getNumberOfFontsAsInt()); CellStyle cellStyleTitle=wb1.createCellStyle(); cellStyleTitle.setFont(font); @@ -114,8 +114,8 @@ public abstract class BaseTestFont { wb1.close(); s1 = wb2.getSheetAt(0); - assertEquals(num0 + 1, wb2.getNumberOfFonts()); - short idx = s1.getRow(0).getCell(0).getCellStyle().getFontIndex(); + assertEquals(num0 + 1, wb2.getNumberOfFontsAsInt()); + int idx = s1.getRow(0).getCell(0).getCellStyle().getFontIntIndex(); Font fnt = wb2.getFontAt(idx); assertNotNull(fnt); assertEquals(IndexedColors.YELLOW.getIndex(), fnt.getColor()); @@ -125,9 +125,9 @@ public abstract class BaseTestFont { Font font2 = wb2.createFont(); font2.setItalic(true); font2.setFontHeightInPoints((short)15); - short font2Idx = font2.getIndex(); + int font2Idx = font2.getIndexAsInt(); wb2.createCellStyle().setFont(font2); - assertEquals(num0 + 2, wb2.getNumberOfFonts()); + assertEquals(num0 + 2, wb2.getNumberOfFontsAsInt()); // Save and re-load Workbook wb3 = _testDataProvider.writeOutAndReadBack(wb2); @@ -135,7 +135,7 @@ public abstract class BaseTestFont { s1 = wb3.getSheetAt(0); assertNotNull(s1); - assertEquals(num0 + 2, wb3.getNumberOfFonts()); + assertEquals(num0 + 2, wb3.getNumberOfFontsAsInt()); assertNotNull(wb3.getFontAt(font1Idx)); assertNotNull(wb3.getFontAt(font2Idx)); @@ -150,7 +150,7 @@ public abstract class BaseTestFont { @Test public final void test45338() throws IOException { Workbook wb = _testDataProvider.createWorkbook(); - int num0 = wb.getNumberOfFonts(); + int num0 = wb.getNumberOfFontsAsInt(); Sheet s = wb.createSheet(); s.createRow(0); @@ -159,13 +159,13 @@ public abstract class BaseTestFont { s.getRow(1).createCell(0); //default font - Font f1 = wb.getFontAt((short)0); + Font f1 = wb.getFontAt(0); assertFalse(f1.getBold()); // Check that asking for the same font // multiple times gives you the same thing. // Otherwise, our tests wouldn't work! - assertSame(wb.getFontAt((short)0), wb.getFontAt((short)0)); + assertSame(wb.getFontAt(0), wb.getFontAt(0)); // Look for a new font we have // yet to add @@ -177,8 +177,8 @@ public abstract class BaseTestFont { ); Font nf = wb.createFont(); - short nfIdx = nf.getIndex(); - assertEquals(num0 + 1, wb.getNumberOfFonts()); + int nfIdx = nf.getIndexAsInt(); + assertEquals(num0 + 1, wb.getNumberOfFontsAsInt()); assertSame(nf, wb.getFontAt(nfIdx)); @@ -191,11 +191,11 @@ public abstract class BaseTestFont { nf.setTypeOffset((short)2); nf.setUnderline((byte)2); - assertEquals(num0 + 1, wb.getNumberOfFonts()); + assertEquals(num0 + 1, wb.getNumberOfFontsAsInt()); assertEquals(nf, wb.getFontAt(nfIdx)); assertEquals(wb.getFontAt(nfIdx), wb.getFontAt(nfIdx)); - assertTrue(wb.getFontAt((short)0) != wb.getFontAt(nfIdx)); + assertTrue(wb.getFontAt(0) != wb.getFontAt(nfIdx)); // Find it now assertNotNull(