]> source.dussan.org Git - poi.git/commitdiff
Adjust some JavaDoc and remove some unnecessary String.valueOf() calls and fix some...
authorDominik Stadler <centic@apache.org>
Wed, 28 Sep 2016 08:44:14 +0000 (08:44 +0000)
committerDominik Stadler <centic@apache.org>
Wed, 28 Sep 2016 08:44:14 +0000 (08:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1762617 13f79535-47bb-0310-9956-ffa450edef68

src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java
src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
src/java/org/apache/poi/ss/formula/functions/Bin2Dec.java
src/java/org/apache/poi/ss/usermodel/Workbook.java
src/java/org/apache/poi/ss/util/SheetUtil.java
src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoUtils.java
src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java

index a666c6ab7b72bbb50fb2e1917b0ec4672f7007bf..e1d4cbcbf811ef919f43fa5856e5760a5f4d916a 100644 (file)
@@ -67,27 +67,21 @@ public class InCellLists {
      *                       the Excel spreadsheet file this code will create.\r
      */\r
     public void demonstrateMethodCalls(String outputFilename) throws IOException {\r
-        HSSFWorkbook workbook = null;\r
-        HSSFSheet sheet = null;\r
-        HSSFRow row = null;\r
-        HSSFCell cell = null;\r
-        ArrayList<MultiLevelListItem> multiLevelListItems = null;\r
-        ArrayList<String> listItems = null;\r
+        HSSFWorkbook workbook = new HSSFWorkbook();\r
         try {\r
-            workbook = new HSSFWorkbook();\r
-            sheet = workbook.createSheet("In Cell Lists");\r
-            row = sheet.createRow(0);\r
+            HSSFSheet sheet = workbook.createSheet("In Cell Lists");\r
+            HSSFRow row = sheet.createRow(0);\r
 \r
             // Create a cell at A1 and insert a single, bulleted, item into\r
             // that cell.\r
-            cell = row.createCell(0);\r
+            HSSFCell cell = row.createCell(0);\r
             this.bulletedItemInCell(workbook, "List Item", cell);\r
 \r
             // Create a cell at A2 and insert a plain list - that is one\r
             // whose items are neither bulleted or numbered - into that cell.\r
             row = sheet.createRow(1);\r
             cell = row.createCell(0);\r
-            listItems = new ArrayList<String>();\r
+            ArrayList<String> listItems = new ArrayList<String>();\r
             listItems.add("List Item One.");\r
             listItems.add("List Item Two.");\r
             listItems.add("List Item Three.");\r
@@ -131,7 +125,7 @@ public class InCellLists {
             // to preserve order.\r
             row = sheet.createRow(4);\r
             cell = row.createCell(0);\r
-            multiLevelListItems = new ArrayList<MultiLevelListItem>();\r
+            ArrayList<MultiLevelListItem> multiLevelListItems = new ArrayList<MultiLevelListItem>();\r
             listItems = new ArrayList<String>();\r
             listItems.add("ML List Item One - Sub Item One.");\r
             listItems.add("ML List Item One - Sub Item Two.");\r
@@ -189,9 +183,7 @@ public class InCellLists {
             ioEx.printStackTrace(System.out);\r
         }\r
         finally {\r
-            if (workbook != null) {\r
-                workbook.close();\r
-            }\r
+            workbook.close();\r
         }\r
     }\r
 \r
@@ -236,7 +228,7 @@ public class InCellLists {
      *             will be written.\r
      */\r
     public void listInCell(HSSFWorkbook workbook, ArrayList<String> listItems, HSSFCell cell) {\r
-        StringBuffer buffer = new StringBuffer();\r
+        StringBuilder buffer = new StringBuilder();\r
         HSSFCellStyle wrapStyle = workbook.createCellStyle();\r
         wrapStyle.setWrapText(true);\r
         for(String listItem : listItems) {\r
@@ -269,7 +261,7 @@ public class InCellLists {
                                    HSSFCell cell,\r
                                    int startingValue,\r
                                    int increment) {\r
-        StringBuffer buffer = new StringBuffer();\r
+        StringBuilder buffer = new StringBuilder();\r
         int itemNumber = startingValue;\r
         // Note that again, an HSSFCellStye object is required and that\r
         // it's wrap text property should be set to 'true'\r
@@ -278,7 +270,7 @@ public class InCellLists {
         // Note that the basic method is identical to the listInCell() method\r
         // with one difference; a number prefixed to the items text.\r
         for(String listItem : listItems) {\r
-            buffer.append(String.valueOf(itemNumber) + ". ");\r
+            buffer.append(itemNumber).append(". ");\r
             buffer.append(listItem);\r
             buffer.append("\n");\r
             itemNumber += increment;\r
@@ -303,7 +295,7 @@ public class InCellLists {
     public void bulletedListInCell(HSSFWorkbook workbook,\r
                                    ArrayList<String> listItems,\r
                                    HSSFCell cell) {\r
-        StringBuffer buffer = new StringBuffer();\r
+        StringBuilder buffer = new StringBuilder();\r
         // Note that again, an HSSFCellStye object is required and that\r
         // it's wrap text property should be set to 'true'\r
         HSSFCellStyle wrapStyle = workbook.createCellStyle();\r
@@ -339,8 +331,7 @@ public class InCellLists {
     public void multiLevelListInCell(HSSFWorkbook workbook,\r
                                      ArrayList<MultiLevelListItem> multiLevelListItems,\r
                                      HSSFCell cell) {\r
-        StringBuffer buffer = new StringBuffer();\r
-        ArrayList<String> lowerLevelItems = null;\r
+        StringBuilder buffer = new StringBuilder();\r
         // Note that again, an HSSFCellStye object is required and that\r
         // it's wrap text property should be set to 'true'\r
         HSSFCellStyle wrapStyle = workbook.createCellStyle();\r
@@ -353,7 +344,7 @@ public class InCellLists {
             buffer.append("\n");\r
             // and then an ArrayList whose elements encapsulate the text\r
             // for the lower level list items.\r
-            lowerLevelItems = multiLevelListItem.getLowerLevelItems();\r
+            ArrayList<String> lowerLevelItems = multiLevelListItem.getLowerLevelItems();\r
             if(!(lowerLevelItems == null) && !(lowerLevelItems.isEmpty())) {\r
                 for(String item : lowerLevelItems) {\r
                     buffer.append(InCellLists.TAB);\r
@@ -401,10 +392,8 @@ public class InCellLists {
                                              int highLevelIncrement,\r
                                              int lowLevelStartingValue,\r
                                              int lowLevelIncrement) {\r
-        StringBuffer buffer = new StringBuffer();\r
+        StringBuilder buffer = new StringBuilder();\r
         int highLevelItemNumber = highLevelStartingValue;\r
-        int lowLevelItemNumber = 0;\r
-        ArrayList<String> lowerLevelItems = null;\r
         // Note that again, an HSSFCellStye object is required and that\r
         // it's wrap text property should be set to 'true'\r
         HSSFCellStyle wrapStyle = workbook.createCellStyle();\r
@@ -413,20 +402,20 @@ public class InCellLists {
         for(MultiLevelListItem multiLevelListItem : multiLevelListItems) {\r
             // For each element in the ArrayList, get the text for the high\r
             // level list item......\r
-            buffer.append(String.valueOf(highLevelItemNumber));\r
+            buffer.append(highLevelItemNumber);\r
             buffer.append(". ");\r
             buffer.append(multiLevelListItem.getItemText());\r
             buffer.append("\n");\r
             // and then an ArrayList whose elements encapsulate the text\r
             // for the lower level list items.\r
-            lowerLevelItems = multiLevelListItem.getLowerLevelItems();\r
+            ArrayList<String> lowerLevelItems = multiLevelListItem.getLowerLevelItems();\r
             if(!(lowerLevelItems == null) && !(lowerLevelItems.isEmpty())) {\r
-                lowLevelItemNumber = lowLevelStartingValue;\r
+                int lowLevelItemNumber = lowLevelStartingValue;\r
                 for(String item : lowerLevelItems) {\r
                     buffer.append(InCellLists.TAB);\r
-                    buffer.append(String.valueOf(highLevelItemNumber));\r
+                    buffer.append(highLevelItemNumber);\r
                     buffer.append(".");\r
-                    buffer.append(String.valueOf(lowLevelItemNumber));\r
+                    buffer.append(lowLevelItemNumber);\r
                     buffer.append(" ");\r
                     buffer.append(item);\r
                     buffer.append("\n");\r
@@ -459,8 +448,7 @@ public class InCellLists {
     public void multiLevelBulletedListInCell(HSSFWorkbook workbook,\r
                                              ArrayList<MultiLevelListItem> multiLevelListItems,\r
                                              HSSFCell cell) {\r
-        StringBuffer buffer = new StringBuffer();\r
-        ArrayList<String> lowerLevelItems = null;\r
+        StringBuilder buffer = new StringBuilder();\r
         // Note that again, an HSSFCellStye object is required and that\r
         // it's wrap text property should be set to 'true'\r
         HSSFCellStyle wrapStyle = workbook.createCellStyle();\r
@@ -475,7 +463,7 @@ public class InCellLists {
             buffer.append("\n");\r
             // and then an ArrayList whose elements encapsulate the text\r
             // for the lower level list items.\r
-            lowerLevelItems = multiLevelListItem.getLowerLevelItems();\r
+            ArrayList<String> lowerLevelItems = multiLevelListItem.getLowerLevelItems();\r
             if(!(lowerLevelItems == null) && !(lowerLevelItems.isEmpty())) {\r
                 for(String item : lowerLevelItems) {\r
                     buffer.append(InCellLists.TAB);\r
index ba015a9f1136e6ad773cfd125c2bdff47dfe0125..f6456bffa3ed1031f2a5ebbc46bacd47f196d8a9 100644 (file)
@@ -954,8 +954,9 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
      * Get the HSSFSheet object at the given index.
      * @param index of the sheet number (0-based physical & logical)
      * @return HSSFSheet at the provided index
+     * @throws IllegalArgumentException if the index is out of range (index
+     *            &lt; 0 || index &gt;= getNumberOfSheets()).
      */
-
     @Override
     public HSSFSheet getSheetAt(int index)
     {
index 9617877ca6675925576746e8a43dc9b79b36b538..cb206051c090c07d83c7b3657c802beb454ee080 100644 (file)
@@ -84,7 +84,7 @@ public class Bin2Dec extends Fixed1ArgFunction implements FreeRefFunction {
                 //Add 1 to obtained number\r
                 sum++;\r
     \r
-                value = "-" + String.valueOf(sum);\r
+                value = "-" + sum;\r
             }\r
         } catch (NumberFormatException e) {\r
             return ErrorEval.NUM_ERROR;\r
index 85c7ca7248c273e428dda45b417c64f912018e78..f5043b727f326a0ea837ff61942e391fdcd07806 100644 (file)
@@ -253,6 +253,8 @@ public interface Workbook extends Closeable, Iterable<Sheet> {
      *
      * @param index of the sheet number (0-based physical & logical)
      * @return Sheet at the provided index
+     * @throws IllegalArgumentException if the index is out of range (index
+     *            &lt; 0 || index &gt;= getNumberOfSheets()).
      */
     Sheet getSheetAt(int index);
 
index d64dbeba82ad579df87f61b1edc67064c5dc5847..f234380fe9c86f871789177f7c40f4b96ed4aa9b 100644 (file)
@@ -128,7 +128,7 @@ public class SheetUtil {
         // We should only be checking merged regions if useMergedCells is true. Why are we doing this for-loop?
         int colspan = 1;
         for (CellRangeAddress region : sheet.getMergedRegions()) {
-            if (containsCell(region, row.getRowNum(), column)) {
+            if (region.isInRange(row.getRowNum(), column)) {
                 if (!useMergedCells) {
                     // If we're not using merged cells, skip this one and move on to the next.
                     return -1;
@@ -151,8 +151,8 @@ public class SheetUtil {
         if (cellType == CellType.STRING) {
             RichTextString rt = cell.getRichStringCellValue();
             String[] lines = rt.getString().split("\\n");
-            for (int i = 0; i < lines.length; i++) {
-                String txt = lines[i] + defaultChar;
+            for (String line : lines) {
+                String txt = line + defaultChar;
 
                 AttributedString str = new AttributedString(txt);
                 copyAttributes(font, str, 0, txt.length());
@@ -193,7 +193,7 @@ public class SheetUtil {
      * @param defaultCharWidth the width of a character using the default font in a workbook
      * @param colspan the number of columns that is spanned by the cell (1 if the cell is not part of a merged region)
      * @param style the cell style, which contains text rotation and indention information needed to compute the cell width
-     * @param width the minimum best-fit width. This algorithm will only return values greater than or equal to the minimum width.
+     * @param minWidth the minimum best-fit width. This algorithm will only return values greater than or equal to the minimum width.
      * @param str the text contained in the cell
      * @return the best fit cell width
      */
@@ -219,8 +219,7 @@ public class SheetUtil {
         }
         // frameWidth accounts for leading spaces which is excluded from bounds.getWidth()
         final double frameWidth = bounds.getX() + bounds.getWidth();
-        final double width = Math.max(minWidth, ((frameWidth / colspan) / defaultCharWidth) + style.getIndention());
-        return width;
+        return Math.max(minWidth, ((frameWidth / colspan) / defaultCharWidth) + style.getIndention());
     }
 
     /**
@@ -273,13 +272,12 @@ public class SheetUtil {
         AttributedString str = new AttributedString(String.valueOf(defaultChar));
         copyAttributes(defaultFont, str, 0, 1);
         TextLayout layout = new TextLayout(str.getIterator(), fontRenderContext);
-        int defaultCharWidth = (int) layout.getAdvance();
-        return defaultCharWidth;
+        return (int) layout.getAdvance();
     }
 
     /**
      * Compute width of a single cell in a row
-     * Convenience method for {@link getCellWidth}
+     * Convenience method for {@link #getCellWidth}
      *
      * @param row the row that contains the cell of interest
      * @param column the column number of the cell whose width is to be calculated
@@ -334,7 +332,7 @@ public class SheetUtil {
     private static void copyAttributes(Font font, AttributedString str, int startIdx, int endIdx) {
         str.addAttribute(TextAttribute.FAMILY, font.getFontName(), startIdx, endIdx);
         str.addAttribute(TextAttribute.SIZE, (float)font.getFontHeightInPoints());
-        if (font.getBoldweight() == Font.BOLDWEIGHT_BOLD) str.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD, startIdx, endIdx);
+        if (font.getBold()) str.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD, startIdx, endIdx);
         if (font.getItalic() ) str.addAttribute(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE, startIdx, endIdx);
         if (font.getUnderline() == Font.U_SINGLE ) str.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, startIdx, endIdx);
     }
@@ -348,6 +346,7 @@ public class SheetUtil {
      * @return true if the range contains the cell [rowIx, colIx]
      * @deprecated 3.15 beta 2. Use {@link CellRangeAddressBase#isInRange(int, int)}.
      */
+    @Deprecated
     public static boolean containsCell(CellRangeAddress cr, int rowIx, int colIx) {
         return cr.isInRange(rowIx,  colIx);
     }
index e901de821662b8f3e4f421594d7a7f679e257860..32cf161a5c3a4df34e484a34fc0d5fd794c943b8 100644 (file)
@@ -154,37 +154,37 @@ public class WordToFoUtils extends AbstractWordUtils
         {
             block.setAttribute(
                     "text-indent",
-                    String.valueOf( paragraph.getFirstLineIndent()
-                            / TWIPS_PER_PT )
+                    paragraph.getFirstLineIndent()
+                            / TWIPS_PER_PT
                             + "pt" );
         }
         if ( paragraph.getIndentFromLeft() != 0 )
         {
             block.setAttribute(
                     "start-indent",
-                    String.valueOf( paragraph.getIndentFromLeft()
-                            / TWIPS_PER_PT )
+                    paragraph.getIndentFromLeft()
+                            / TWIPS_PER_PT
                             + "pt" );
         }
         if ( paragraph.getIndentFromRight() != 0 )
         {
             block.setAttribute(
                     "end-indent",
-                    String.valueOf( paragraph.getIndentFromRight()
-                            / TWIPS_PER_PT )
+                    paragraph.getIndentFromRight()
+                            / TWIPS_PER_PT
                             + "pt" );
         }
         if ( paragraph.getSpacingBefore() != 0 )
         {
             block.setAttribute(
                     "space-before",
-                    String.valueOf( paragraph.getSpacingBefore() / TWIPS_PER_PT )
+                    paragraph.getSpacingBefore() / TWIPS_PER_PT
                             + "pt" );
         }
         if ( paragraph.getSpacingAfter() != 0 )
         {
             block.setAttribute( "space-after",
-                    String.valueOf( paragraph.getSpacingAfter() / TWIPS_PER_PT )
+                    paragraph.getSpacingAfter() / TWIPS_PER_PT
                             + "pt" );
         }
     }
index fef200fdcbf76eccd263de84869ecbaa4b2762c1..0ca030438184318aacfa2fd2c970c32016f367bc 100644 (file)
@@ -227,7 +227,7 @@ public final class TestPOIFSDocumentPath extends TestCase {
         {
             for (int k = 0; k < paths.length; k++)
             {
-                assertEquals(String.valueOf(j) + "<>" + String.valueOf(k),
+                assertEquals(j + "<>" + k,
                              paths[ j ], paths[ k ]);
             }
         }
@@ -274,13 +274,13 @@ public final class TestPOIFSDocumentPath extends TestCase {
             {
                 if (k == j)
                 {
-                    assertEquals(String.valueOf(j) + "<>"
-                                 + String.valueOf(k), fullPaths[ j ],
+                    assertEquals(j + "<>"
+                                 + k, fullPaths[ j ],
                                                       builtUpPaths[ k ]);
                 }
                 else
                 {
-                    assertTrue(String.valueOf(j) + "<>" + String.valueOf(k),
+                    assertTrue(j + "<>" + k,
                                !(fullPaths[ j ].equals(builtUpPaths[ k ])));
                 }
             }
@@ -306,7 +306,7 @@ public final class TestPOIFSDocumentPath extends TestCase {
         {
             for (int j = 0; j < badPaths.length; j++)
             {
-                assertTrue(String.valueOf(j) + "<>" + String.valueOf(k),
+                assertTrue(j + "<>" + k,
                            !(fullPaths[ k ].equals(badPaths[ j ])));
             }
         }