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