Fix some Eclipse warnings

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1649123 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2015-01-02 21:06:51 +00:00
parent ffcc20f60e
commit 302db39cb7
12 changed files with 183 additions and 178 deletions

View File

@ -63,7 +63,7 @@ public class PieChartDemo {
} }
BufferedReader modelReader = new BufferedReader(new FileReader(args[1])); BufferedReader modelReader = new BufferedReader(new FileReader(args[1]));
try {
String chartTitle = modelReader.readLine(); // first line is chart title String chartTitle = modelReader.readLine(); // first line is chart title
XMLSlideShow pptx = new XMLSlideShow(new FileInputStream(args[0])); XMLSlideShow pptx = new XMLSlideShow(new FileInputStream(args[0]));
@ -83,6 +83,7 @@ public class PieChartDemo {
// embedded Excel workbook that holds the chart data // embedded Excel workbook that holds the chart data
POIXMLDocumentPart xlsPart = chart.getRelations().get(0); POIXMLDocumentPart xlsPart = chart.getRelations().get(0);
XSSFWorkbook wb = new XSSFWorkbook(); XSSFWorkbook wb = new XSSFWorkbook();
try {
XSSFSheet sheet = wb.createSheet(); XSSFSheet sheet = wb.createSheet();
CTChart ctChart = chart.getCTChart(); CTChart ctChart = chart.getCTChart();
@ -99,7 +100,6 @@ public class PieChartDemo {
String titleRef = new CellReference(sheet.getSheetName(), 0, 1, true, true).formatAsString(); String titleRef = new CellReference(sheet.getSheetName(), 0, 1, true, true).formatAsString();
tx.getStrRef().setF(titleRef); tx.getStrRef().setF(titleRef);
// Category Axis Data // Category Axis Data
CTAxDataSource cat = ser.getCat(); CTAxDataSource cat = ser.getCat();
CTStrData strData = cat.getStrRef().getStrCache(); CTStrData strData = cat.getStrRef().getStrCache();
@ -111,7 +111,6 @@ public class PieChartDemo {
strData.setPtArray(null); // unset old axis text strData.setPtArray(null); // unset old axis text
numData.setPtArray(null); // unset old values numData.setPtArray(null); // unset old values
// set model // set model
int idx = 0; int idx = 0;
int rownum = 1; int rownum = 1;
@ -141,12 +140,24 @@ public class PieChartDemo {
// updated the embedded workbook with the data // updated the embedded workbook with the data
OutputStream xlsOut = xlsPart.getPackagePart().getOutputStream(); OutputStream xlsOut = xlsPart.getPackagePart().getOutputStream();
try {
wb.write(xlsOut); wb.write(xlsOut);
} finally {
xlsOut.close(); xlsOut.close();
}
// save the result // save the result
FileOutputStream out = new FileOutputStream("pie-chart-demo-output.pptx"); OutputStream out = new FileOutputStream("pie-chart-demo-output.pptx");
try {
pptx.write(out); pptx.write(out);
} finally {
out.close(); out.close();
} }
} finally {
wb.close();
}
} finally {
modelReader.close();
}
}
} }

View File

@ -34,7 +34,7 @@ public class Tutorial1 {
XMLSlideShow ppt = new XMLSlideShow(); XMLSlideShow ppt = new XMLSlideShow();
// XSLFSlide#createSlide() with no arguments creates a blank slide // XSLFSlide#createSlide() with no arguments creates a blank slide
XSLFSlide blankSlide = ppt.createSlide(); /*XSLFSlide blankSlide =*/ ppt.createSlide();
XSLFSlideMaster master = ppt.getSlideMasters()[0]; XSLFSlideMaster master = ppt.getSlideMasters()[0];

View File

@ -41,7 +41,7 @@ public class Tutorial5 {
byte[] data = IOUtils.toByteArray(new FileInputStream(img)); byte[] data = IOUtils.toByteArray(new FileInputStream(img));
int pictureIndex = ppt.addPicture(data, XSLFPictureData.PICTURE_TYPE_PNG); int pictureIndex = ppt.addPicture(data, XSLFPictureData.PICTURE_TYPE_PNG);
XSLFPictureShape shape = slide.createPicture(pictureIndex); /*XSLFPictureShape shape =*/ slide.createPicture(pictureIndex);
FileOutputStream out = new FileOutputStream("images.pptx"); FileOutputStream out = new FileOutputStream("images.pptx");
ppt.write(out); ppt.write(out);

View File

@ -47,7 +47,7 @@ public class Step2 {
} }
// blank slide // blank slide
XSLFSlide blankSlide = ppt.createSlide(); /*XSLFSlide blankSlide =*/ ppt.createSlide();
XSLFSlideMaster defaultMaster = ppt.getSlideMasters()[0]; XSLFSlideMaster defaultMaster = ppt.getSlideMasters()[0];

View File

@ -25,6 +25,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.OutputStream;
/** /**
* Demonstrates how to insert pictures in a SpreadsheetML document * Demonstrates how to insert pictures in a SpreadsheetML document
@ -36,6 +37,7 @@ public class WorkingWithPictures {
//create a new workbook //create a new workbook
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook(); Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
try {
CreationHelper helper = wb.getCreationHelper(); CreationHelper helper = wb.getCreationHelper();
//add a picture in this workbook. //add a picture in this workbook.
@ -62,8 +64,14 @@ public class WorkingWithPictures {
//save workbook //save workbook
String file = "picture.xls"; String file = "picture.xls";
if(wb instanceof XSSFWorkbook) file += "x"; if(wb instanceof XSSFWorkbook) file += "x";
FileOutputStream fileOut = new FileOutputStream(file); OutputStream fileOut = new FileOutputStream(file);
try {
wb.write(fileOut); wb.write(fileOut);
} finally {
fileOut.close(); fileOut.close();
} }
} finally {
wb.close();
}
}
} }

View File

@ -20,6 +20,7 @@ package org.apache.poi.xssf.usermodel.examples;
import org.apache.poi.xssf.usermodel.*; import org.apache.poi.xssf.usermodel.*;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.OutputStream;
/** /**
* Demonstrates how to work with rich text * Demonstrates how to work with rich text
@ -29,7 +30,7 @@ public class WorkingWithRichText {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
XSSFWorkbook wb = new XSSFWorkbook(); //or new HSSFWorkbook(); XSSFWorkbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
try {
XSSFSheet sheet = wb.createSheet(); XSSFSheet sheet = wb.createSheet();
XSSFRow row = sheet.createRow((short) 2); XSSFRow row = sheet.createRow((short) 2);
@ -54,8 +55,14 @@ public class WorkingWithRichText {
cell.setCellValue(rt); cell.setCellValue(rt);
// Write the output to a file // Write the output to a file
FileOutputStream fileOut = new FileOutputStream("xssf-richtext.xlsx"); OutputStream fileOut = new FileOutputStream("xssf-richtext.xlsx");
try {
wb.write(fileOut); wb.write(fileOut);
} finally {
fileOut.close(); fileOut.close();
} }
} finally {
wb.close();
}
}
} }

View File

@ -19,6 +19,8 @@
package org.apache.poi.xwpf.usermodel; package org.apache.poi.xwpf.usermodel;
import static org.junit.Assert.assertEquals;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -27,7 +29,6 @@ import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Iterator; import java.util.Iterator;
import junit.framework.Assert;
import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.ss.usermodel.WorkbookFactory; import org.apache.poi.ss.usermodel.WorkbookFactory;
@ -194,7 +195,7 @@ public class UpdateEmbeddedDoc {
sheet = workbook.getSheetAt(SHEET_NUM); sheet = workbook.getSheetAt(SHEET_NUM);
row = sheet.getRow(ROW_NUM); row = sheet.getRow(ROW_NUM);
cell = row.getCell(CELL_NUM); cell = row.getCell(CELL_NUM);
Assert.assertEquals(cell.getNumericCellValue(), NEW_VALUE); assertEquals(cell.getNumericCellValue(), NEW_VALUE, 0.0001);
} }
} }
} }

View File

@ -61,7 +61,7 @@ public class ExcelAntHandlerTask extends Task {
public void execute() throws BuildException { public void execute() throws BuildException {
log( "handling the workbook with class " + className, Project.MSG_INFO ) ; log( "handling the workbook with class " + className, Project.MSG_INFO ) ;
try { try {
Class clazz = Class.forName( className ) ; Class<?> clazz = Class.forName( className ) ;
Object handlerObj = clazz.newInstance() ; Object handlerObj = clazz.newInstance() ;
if( handlerObj instanceof IExcelAntWorkbookHandler ) { if( handlerObj instanceof IExcelAntWorkbookHandler ) {
IExcelAntWorkbookHandler iHandler = (IExcelAntWorkbookHandler)handlerObj ; IExcelAntWorkbookHandler iHandler = (IExcelAntWorkbookHandler)handlerObj ;

View File

@ -1627,9 +1627,9 @@ public final class InternalSheet {
private void recalcRowGutter() { private void recalcRowGutter() {
int maxLevel = 0; int maxLevel = 0;
Iterator iterator = _rowsAggregate.getIterator(); Iterator<RowRecord> iterator = _rowsAggregate.getIterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
RowRecord rowRecord = (RowRecord) iterator.next(); RowRecord rowRecord = iterator.next();
maxLevel = Math.max(rowRecord.getOutlineLevel(), maxLevel); maxLevel = Math.max(rowRecord.getOutlineLevel(), maxLevel);
} }

View File

@ -164,7 +164,7 @@ public class HSSFColor implements Color {
String hexString = color.getHexString(); String hexString = color.getHexString();
if (result.containsKey(hexString)) { if (result.containsKey(hexString)) {
HSSFColor other = (HSSFColor)result.get(hexString); HSSFColor other = result.get(hexString);
throw new RuntimeException( throw new RuntimeException(
"Dup color hexString (" + hexString "Dup color hexString (" + hexString
+ ") for color (" + color.getClass().getName() + ") - " + ") for color (" + color.getClass().getName() + ") - "

View File

@ -18,13 +18,7 @@
package org.apache.poi.xssf.usermodel; package org.apache.poi.xssf.usermodel;
import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -52,29 +46,11 @@ import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval; import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.ValueEval; import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.functions.Function; import org.apache.poi.ss.formula.functions.Function;
import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.FormulaError;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Hyperlink;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Name;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.util.AreaReference; import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellReference; import org.apache.poi.ss.util.CellReference;
import org.apache.poi.ss.util.RegionUtil;
import org.apache.poi.util.TempFile; import org.apache.poi.util.TempFile;
import org.apache.poi.xssf.XLSBUnsupportedException; import org.apache.poi.xssf.XLSBUnsupportedException;
import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFITestDataProvider;
@ -1800,9 +1776,10 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
/** /**
* New hyperlink with no initial cell reference, still need * New hyperlink with no initial cell reference, still need
* to be able to change it * to be able to change it
* @throws IOException
*/ */
@Test @Test
public void testBug56527() { public void testBug56527() throws IOException {
XSSFWorkbook wb = new XSSFWorkbook(); XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet(); XSSFSheet sheet = wb.createSheet();
XSSFCreationHelper creationHelper = wb.getCreationHelper(); XSSFCreationHelper creationHelper = wb.getCreationHelper();
@ -1829,6 +1806,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
assertEquals(3, hyperlink.getFirstColumn()); assertEquals(3, hyperlink.getFirstColumn());
assertEquals(5, hyperlink.getLastRow()); assertEquals(5, hyperlink.getLastRow());
assertEquals(3, hyperlink.getLastColumn()); assertEquals(3, hyperlink.getLastColumn());
wb.close();
} }
/** /**

View File

@ -64,7 +64,7 @@ public final class TestMergeCellsRecord extends TestCase {
}; };
public void testMCTable_bug46009() { public void testMCTable_bug46009() {
MergedCellsTable mct = new MergedCellsTable(); MergedCellsTable mct = new MergedCellsTable();
List recList = new ArrayList(); List<Record> recList = new ArrayList<Record>();
CellRangeAddress[] cras = new CellRangeAddress[] { CellRangeAddress[] cras = new CellRangeAddress[] {
new CellRangeAddress(0, 0, 0, 3), new CellRangeAddress(0, 0, 0, 3),
}; };