diff options
author | Dominik Stadler <centic@apache.org> | 2016-09-28 08:44:14 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2016-09-28 08:44:14 +0000 |
commit | 4b21aca823037d94162007a4a8af104e25aa989e (patch) | |
tree | 84f689af996265f341059ed5bed22e03ede9ea80 /src/examples | |
parent | bc58e97cbae5accc99792fcc8d65350e94cc98cf (diff) | |
download | poi-4b21aca823037d94162007a4a8af104e25aa989e.tar.gz poi-4b21aca823037d94162007a4a8af104e25aa989e.zip |
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
Diffstat (limited to 'src/examples')
-rw-r--r-- | src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java | 54 |
1 files changed, 21 insertions, 33 deletions
diff --git a/src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java b/src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java index a666c6ab7b..e1d4cbcbf8 100644 --- a/src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java +++ b/src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java @@ -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);
|