Adjust some JavaDoc and remove some unnecessary String.valueOf() calls and fix some other compiler warnings

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1762617 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2016-09-28 08:44:14 +00:00
parent e3ad266c4f
commit db79fe043c
7 changed files with 48 additions and 58 deletions

View File

@ -67,27 +67,21 @@ public class InCellLists {
* the Excel spreadsheet file this code will create. * the Excel spreadsheet file this code will create.
*/ */
public void demonstrateMethodCalls(String outputFilename) throws IOException { public void demonstrateMethodCalls(String outputFilename) throws IOException {
HSSFWorkbook workbook = null; HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = null;
HSSFRow row = null;
HSSFCell cell = null;
ArrayList<MultiLevelListItem> multiLevelListItems = null;
ArrayList<String> listItems = null;
try { try {
workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("In Cell Lists");
sheet = workbook.createSheet("In Cell Lists"); HSSFRow row = sheet.createRow(0);
row = sheet.createRow(0);
// Create a cell at A1 and insert a single, bulleted, item into // Create a cell at A1 and insert a single, bulleted, item into
// that cell. // that cell.
cell = row.createCell(0); HSSFCell cell = row.createCell(0);
this.bulletedItemInCell(workbook, "List Item", cell); this.bulletedItemInCell(workbook, "List Item", cell);
// Create a cell at A2 and insert a plain list - that is one // Create a cell at A2 and insert a plain list - that is one
// whose items are neither bulleted or numbered - into that cell. // whose items are neither bulleted or numbered - into that cell.
row = sheet.createRow(1); row = sheet.createRow(1);
cell = row.createCell(0); cell = row.createCell(0);
listItems = new ArrayList<String>(); ArrayList<String> listItems = new ArrayList<String>();
listItems.add("List Item One."); listItems.add("List Item One.");
listItems.add("List Item Two."); listItems.add("List Item Two.");
listItems.add("List Item Three."); listItems.add("List Item Three.");
@ -131,7 +125,7 @@ public class InCellLists {
// to preserve order. // to preserve order.
row = sheet.createRow(4); row = sheet.createRow(4);
cell = row.createCell(0); cell = row.createCell(0);
multiLevelListItems = new ArrayList<MultiLevelListItem>(); ArrayList<MultiLevelListItem> multiLevelListItems = new ArrayList<MultiLevelListItem>();
listItems = new ArrayList<String>(); listItems = new ArrayList<String>();
listItems.add("ML List Item One - Sub Item One."); listItems.add("ML List Item One - Sub Item One.");
listItems.add("ML List Item One - Sub Item Two."); listItems.add("ML List Item One - Sub Item Two.");
@ -189,11 +183,9 @@ public class InCellLists {
ioEx.printStackTrace(System.out); ioEx.printStackTrace(System.out);
} }
finally { finally {
if (workbook != null) {
workbook.close(); workbook.close();
} }
} }
}
/** /**
* Inserts a single bulleted item into a cell. * Inserts a single bulleted item into a cell.
@ -236,7 +228,7 @@ public class InCellLists {
* will be written. * will be written.
*/ */
public void listInCell(HSSFWorkbook workbook, ArrayList<String> listItems, HSSFCell cell) { public void listInCell(HSSFWorkbook workbook, ArrayList<String> listItems, HSSFCell cell) {
StringBuffer buffer = new StringBuffer(); StringBuilder buffer = new StringBuilder();
HSSFCellStyle wrapStyle = workbook.createCellStyle(); HSSFCellStyle wrapStyle = workbook.createCellStyle();
wrapStyle.setWrapText(true); wrapStyle.setWrapText(true);
for(String listItem : listItems) { for(String listItem : listItems) {
@ -269,7 +261,7 @@ public class InCellLists {
HSSFCell cell, HSSFCell cell,
int startingValue, int startingValue,
int increment) { int increment) {
StringBuffer buffer = new StringBuffer(); StringBuilder buffer = new StringBuilder();
int itemNumber = startingValue; int itemNumber = startingValue;
// Note that again, an HSSFCellStye object is required and that // Note that again, an HSSFCellStye object is required and that
// it's wrap text property should be set to 'true' // it's wrap text property should be set to 'true'
@ -278,7 +270,7 @@ public class InCellLists {
// Note that the basic method is identical to the listInCell() method // Note that the basic method is identical to the listInCell() method
// with one difference; a number prefixed to the items text. // with one difference; a number prefixed to the items text.
for(String listItem : listItems) { for(String listItem : listItems) {
buffer.append(String.valueOf(itemNumber) + ". "); buffer.append(itemNumber).append(". ");
buffer.append(listItem); buffer.append(listItem);
buffer.append("\n"); buffer.append("\n");
itemNumber += increment; itemNumber += increment;
@ -303,7 +295,7 @@ public class InCellLists {
public void bulletedListInCell(HSSFWorkbook workbook, public void bulletedListInCell(HSSFWorkbook workbook,
ArrayList<String> listItems, ArrayList<String> listItems,
HSSFCell cell) { HSSFCell cell) {
StringBuffer buffer = new StringBuffer(); StringBuilder buffer = new StringBuilder();
// Note that again, an HSSFCellStye object is required and that // Note that again, an HSSFCellStye object is required and that
// it's wrap text property should be set to 'true' // it's wrap text property should be set to 'true'
HSSFCellStyle wrapStyle = workbook.createCellStyle(); HSSFCellStyle wrapStyle = workbook.createCellStyle();
@ -339,8 +331,7 @@ public class InCellLists {
public void multiLevelListInCell(HSSFWorkbook workbook, public void multiLevelListInCell(HSSFWorkbook workbook,
ArrayList<MultiLevelListItem> multiLevelListItems, ArrayList<MultiLevelListItem> multiLevelListItems,
HSSFCell cell) { HSSFCell cell) {
StringBuffer buffer = new StringBuffer(); StringBuilder buffer = new StringBuilder();
ArrayList<String> lowerLevelItems = null;
// Note that again, an HSSFCellStye object is required and that // Note that again, an HSSFCellStye object is required and that
// it's wrap text property should be set to 'true' // it's wrap text property should be set to 'true'
HSSFCellStyle wrapStyle = workbook.createCellStyle(); HSSFCellStyle wrapStyle = workbook.createCellStyle();
@ -353,7 +344,7 @@ public class InCellLists {
buffer.append("\n"); buffer.append("\n");
// and then an ArrayList whose elements encapsulate the text // and then an ArrayList whose elements encapsulate the text
// for the lower level list items. // for the lower level list items.
lowerLevelItems = multiLevelListItem.getLowerLevelItems(); ArrayList<String> lowerLevelItems = multiLevelListItem.getLowerLevelItems();
if(!(lowerLevelItems == null) && !(lowerLevelItems.isEmpty())) { if(!(lowerLevelItems == null) && !(lowerLevelItems.isEmpty())) {
for(String item : lowerLevelItems) { for(String item : lowerLevelItems) {
buffer.append(InCellLists.TAB); buffer.append(InCellLists.TAB);
@ -401,10 +392,8 @@ public class InCellLists {
int highLevelIncrement, int highLevelIncrement,
int lowLevelStartingValue, int lowLevelStartingValue,
int lowLevelIncrement) { int lowLevelIncrement) {
StringBuffer buffer = new StringBuffer(); StringBuilder buffer = new StringBuilder();
int highLevelItemNumber = highLevelStartingValue; int highLevelItemNumber = highLevelStartingValue;
int lowLevelItemNumber = 0;
ArrayList<String> lowerLevelItems = null;
// Note that again, an HSSFCellStye object is required and that // Note that again, an HSSFCellStye object is required and that
// it's wrap text property should be set to 'true' // it's wrap text property should be set to 'true'
HSSFCellStyle wrapStyle = workbook.createCellStyle(); HSSFCellStyle wrapStyle = workbook.createCellStyle();
@ -413,20 +402,20 @@ public class InCellLists {
for(MultiLevelListItem multiLevelListItem : multiLevelListItems) { for(MultiLevelListItem multiLevelListItem : multiLevelListItems) {
// For each element in the ArrayList, get the text for the high // For each element in the ArrayList, get the text for the high
// level list item...... // level list item......
buffer.append(String.valueOf(highLevelItemNumber)); buffer.append(highLevelItemNumber);
buffer.append(". "); buffer.append(". ");
buffer.append(multiLevelListItem.getItemText()); buffer.append(multiLevelListItem.getItemText());
buffer.append("\n"); buffer.append("\n");
// and then an ArrayList whose elements encapsulate the text // and then an ArrayList whose elements encapsulate the text
// for the lower level list items. // for the lower level list items.
lowerLevelItems = multiLevelListItem.getLowerLevelItems(); ArrayList<String> lowerLevelItems = multiLevelListItem.getLowerLevelItems();
if(!(lowerLevelItems == null) && !(lowerLevelItems.isEmpty())) { if(!(lowerLevelItems == null) && !(lowerLevelItems.isEmpty())) {
lowLevelItemNumber = lowLevelStartingValue; int lowLevelItemNumber = lowLevelStartingValue;
for(String item : lowerLevelItems) { for(String item : lowerLevelItems) {
buffer.append(InCellLists.TAB); buffer.append(InCellLists.TAB);
buffer.append(String.valueOf(highLevelItemNumber)); buffer.append(highLevelItemNumber);
buffer.append("."); buffer.append(".");
buffer.append(String.valueOf(lowLevelItemNumber)); buffer.append(lowLevelItemNumber);
buffer.append(" "); buffer.append(" ");
buffer.append(item); buffer.append(item);
buffer.append("\n"); buffer.append("\n");
@ -459,8 +448,7 @@ public class InCellLists {
public void multiLevelBulletedListInCell(HSSFWorkbook workbook, public void multiLevelBulletedListInCell(HSSFWorkbook workbook,
ArrayList<MultiLevelListItem> multiLevelListItems, ArrayList<MultiLevelListItem> multiLevelListItems,
HSSFCell cell) { HSSFCell cell) {
StringBuffer buffer = new StringBuffer(); StringBuilder buffer = new StringBuilder();
ArrayList<String> lowerLevelItems = null;
// Note that again, an HSSFCellStye object is required and that // Note that again, an HSSFCellStye object is required and that
// it's wrap text property should be set to 'true' // it's wrap text property should be set to 'true'
HSSFCellStyle wrapStyle = workbook.createCellStyle(); HSSFCellStyle wrapStyle = workbook.createCellStyle();
@ -475,7 +463,7 @@ public class InCellLists {
buffer.append("\n"); buffer.append("\n");
// and then an ArrayList whose elements encapsulate the text // and then an ArrayList whose elements encapsulate the text
// for the lower level list items. // for the lower level list items.
lowerLevelItems = multiLevelListItem.getLowerLevelItems(); ArrayList<String> lowerLevelItems = multiLevelListItem.getLowerLevelItems();
if(!(lowerLevelItems == null) && !(lowerLevelItems.isEmpty())) { if(!(lowerLevelItems == null) && !(lowerLevelItems.isEmpty())) {
for(String item : lowerLevelItems) { for(String item : lowerLevelItems) {
buffer.append(InCellLists.TAB); buffer.append(InCellLists.TAB);

View File

@ -954,8 +954,9 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* Get the HSSFSheet object at the given index. * Get the HSSFSheet object at the given index.
* @param index of the sheet number (0-based physical & logical) * @param index of the sheet number (0-based physical & logical)
* @return HSSFSheet at the provided index * @return HSSFSheet at the provided index
* @throws IllegalArgumentException if the index is out of range (index
* &lt; 0 || index &gt;= getNumberOfSheets()).
*/ */
@Override @Override
public HSSFSheet getSheetAt(int index) public HSSFSheet getSheetAt(int index)
{ {

View File

@ -84,7 +84,7 @@ public class Bin2Dec extends Fixed1ArgFunction implements FreeRefFunction {
//Add 1 to obtained number //Add 1 to obtained number
sum++; sum++;
value = "-" + String.valueOf(sum); value = "-" + sum;
} }
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
return ErrorEval.NUM_ERROR; return ErrorEval.NUM_ERROR;

View File

@ -253,6 +253,8 @@ public interface Workbook extends Closeable, Iterable<Sheet> {
* *
* @param index of the sheet number (0-based physical & logical) * @param index of the sheet number (0-based physical & logical)
* @return Sheet at the provided index * @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); Sheet getSheetAt(int index);

View 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? // We should only be checking merged regions if useMergedCells is true. Why are we doing this for-loop?
int colspan = 1; int colspan = 1;
for (CellRangeAddress region : sheet.getMergedRegions()) { for (CellRangeAddress region : sheet.getMergedRegions()) {
if (containsCell(region, row.getRowNum(), column)) { if (region.isInRange(row.getRowNum(), column)) {
if (!useMergedCells) { if (!useMergedCells) {
// If we're not using merged cells, skip this one and move on to the next. // If we're not using merged cells, skip this one and move on to the next.
return -1; return -1;
@ -151,8 +151,8 @@ public class SheetUtil {
if (cellType == CellType.STRING) { if (cellType == CellType.STRING) {
RichTextString rt = cell.getRichStringCellValue(); RichTextString rt = cell.getRichStringCellValue();
String[] lines = rt.getString().split("\\n"); String[] lines = rt.getString().split("\\n");
for (int i = 0; i < lines.length; i++) { for (String line : lines) {
String txt = lines[i] + defaultChar; String txt = line + defaultChar;
AttributedString str = new AttributedString(txt); AttributedString str = new AttributedString(txt);
copyAttributes(font, str, 0, txt.length()); 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 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 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 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 * @param str the text contained in the cell
* @return the best fit cell width * @return the best fit cell width
*/ */
@ -219,8 +219,7 @@ public class SheetUtil {
} }
// frameWidth accounts for leading spaces which is excluded from bounds.getWidth() // frameWidth accounts for leading spaces which is excluded from bounds.getWidth()
final double frameWidth = bounds.getX() + bounds.getWidth(); final double frameWidth = bounds.getX() + bounds.getWidth();
final double width = Math.max(minWidth, ((frameWidth / colspan) / defaultCharWidth) + style.getIndention()); return Math.max(minWidth, ((frameWidth / colspan) / defaultCharWidth) + style.getIndention());
return width;
} }
/** /**
@ -273,13 +272,12 @@ public class SheetUtil {
AttributedString str = new AttributedString(String.valueOf(defaultChar)); AttributedString str = new AttributedString(String.valueOf(defaultChar));
copyAttributes(defaultFont, str, 0, 1); copyAttributes(defaultFont, str, 0, 1);
TextLayout layout = new TextLayout(str.getIterator(), fontRenderContext); TextLayout layout = new TextLayout(str.getIterator(), fontRenderContext);
int defaultCharWidth = (int) layout.getAdvance(); return (int) layout.getAdvance();
return defaultCharWidth;
} }
/** /**
* Compute width of a single cell in a row * 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 row the row that contains the cell of interest
* @param column the column number of the cell whose width is to be calculated * @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) { private static void copyAttributes(Font font, AttributedString str, int startIdx, int endIdx) {
str.addAttribute(TextAttribute.FAMILY, font.getFontName(), startIdx, endIdx); str.addAttribute(TextAttribute.FAMILY, font.getFontName(), startIdx, endIdx);
str.addAttribute(TextAttribute.SIZE, (float)font.getFontHeightInPoints()); 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.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); 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] * @return true if the range contains the cell [rowIx, colIx]
* @deprecated 3.15 beta 2. Use {@link CellRangeAddressBase#isInRange(int, int)}. * @deprecated 3.15 beta 2. Use {@link CellRangeAddressBase#isInRange(int, int)}.
*/ */
@Deprecated
public static boolean containsCell(CellRangeAddress cr, int rowIx, int colIx) { public static boolean containsCell(CellRangeAddress cr, int rowIx, int colIx) {
return cr.isInRange(rowIx, colIx); return cr.isInRange(rowIx, colIx);
} }

View File

@ -154,37 +154,37 @@ public class WordToFoUtils extends AbstractWordUtils
{ {
block.setAttribute( block.setAttribute(
"text-indent", "text-indent",
String.valueOf( paragraph.getFirstLineIndent() paragraph.getFirstLineIndent()
/ TWIPS_PER_PT ) / TWIPS_PER_PT
+ "pt" ); + "pt" );
} }
if ( paragraph.getIndentFromLeft() != 0 ) if ( paragraph.getIndentFromLeft() != 0 )
{ {
block.setAttribute( block.setAttribute(
"start-indent", "start-indent",
String.valueOf( paragraph.getIndentFromLeft() paragraph.getIndentFromLeft()
/ TWIPS_PER_PT ) / TWIPS_PER_PT
+ "pt" ); + "pt" );
} }
if ( paragraph.getIndentFromRight() != 0 ) if ( paragraph.getIndentFromRight() != 0 )
{ {
block.setAttribute( block.setAttribute(
"end-indent", "end-indent",
String.valueOf( paragraph.getIndentFromRight() paragraph.getIndentFromRight()
/ TWIPS_PER_PT ) / TWIPS_PER_PT
+ "pt" ); + "pt" );
} }
if ( paragraph.getSpacingBefore() != 0 ) if ( paragraph.getSpacingBefore() != 0 )
{ {
block.setAttribute( block.setAttribute(
"space-before", "space-before",
String.valueOf( paragraph.getSpacingBefore() / TWIPS_PER_PT ) paragraph.getSpacingBefore() / TWIPS_PER_PT
+ "pt" ); + "pt" );
} }
if ( paragraph.getSpacingAfter() != 0 ) if ( paragraph.getSpacingAfter() != 0 )
{ {
block.setAttribute( "space-after", block.setAttribute( "space-after",
String.valueOf( paragraph.getSpacingAfter() / TWIPS_PER_PT ) paragraph.getSpacingAfter() / TWIPS_PER_PT
+ "pt" ); + "pt" );
} }
} }

View File

@ -227,7 +227,7 @@ public final class TestPOIFSDocumentPath extends TestCase {
{ {
for (int k = 0; k < paths.length; k++) for (int k = 0; k < paths.length; k++)
{ {
assertEquals(String.valueOf(j) + "<>" + String.valueOf(k), assertEquals(j + "<>" + k,
paths[ j ], paths[ k ]); paths[ j ], paths[ k ]);
} }
} }
@ -274,13 +274,13 @@ public final class TestPOIFSDocumentPath extends TestCase {
{ {
if (k == j) if (k == j)
{ {
assertEquals(String.valueOf(j) + "<>" assertEquals(j + "<>"
+ String.valueOf(k), fullPaths[ j ], + k, fullPaths[ j ],
builtUpPaths[ k ]); builtUpPaths[ k ]);
} }
else else
{ {
assertTrue(String.valueOf(j) + "<>" + String.valueOf(k), assertTrue(j + "<>" + k,
!(fullPaths[ j ].equals(builtUpPaths[ k ]))); !(fullPaths[ j ].equals(builtUpPaths[ k ])));
} }
} }
@ -306,7 +306,7 @@ public final class TestPOIFSDocumentPath extends TestCase {
{ {
for (int j = 0; j < badPaths.length; j++) for (int j = 0; j < badPaths.length; j++)
{ {
assertTrue(String.valueOf(j) + "<>" + String.valueOf(k), assertTrue(j + "<>" + k,
!(fullPaths[ k ].equals(badPaths[ j ]))); !(fullPaths[ k ].equals(badPaths[ j ])));
} }
} }