Fix some Eclipse warnings and adjust use of Generics, Comments, close()

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691308 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2015-07-16 03:41:57 +00:00
parent c54cc66158
commit 0c410544a9
7 changed files with 202 additions and 191 deletions

View File

@ -50,5 +50,7 @@ public class CreateCells {
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
wb.close();
}
}

View File

@ -168,25 +168,29 @@ public class BigGridDemo {
private static void substitute(File zipfile, File tmpfile, String entry, OutputStream out) throws IOException {
ZipFile zip = ZipHelper.openZipFile(zipfile);
ZipOutputStream zos = new ZipOutputStream(out);
try {
ZipOutputStream zos = new ZipOutputStream(out);
@SuppressWarnings("unchecked")
Enumeration<ZipEntry> en = (Enumeration<ZipEntry>) zip.entries();
while (en.hasMoreElements()) {
ZipEntry ze = en.nextElement();
if(!ze.getName().equals(entry)){
zos.putNextEntry(new ZipEntry(ze.getName()));
InputStream is = zip.getInputStream(ze);
copyStream(is, zos);
is.close();
@SuppressWarnings("unchecked")
Enumeration<ZipEntry> en = (Enumeration<ZipEntry>) zip.entries();
while (en.hasMoreElements()) {
ZipEntry ze = en.nextElement();
if(!ze.getName().equals(entry)){
zos.putNextEntry(new ZipEntry(ze.getName()));
InputStream is = zip.getInputStream(ze);
copyStream(is, zos);
is.close();
}
}
}
zos.putNextEntry(new ZipEntry(entry));
InputStream is = new FileInputStream(tmpfile);
copyStream(is, zos);
is.close();
zos.putNextEntry(new ZipEntry(entry));
InputStream is = new FileInputStream(tmpfile);
copyStream(is, zos);
is.close();
zos.close();
zos.close();
} finally {
zip.close();
}
}
private static void copyStream(InputStream in, OutputStream out) throws IOException {

View File

@ -285,7 +285,7 @@ public class Section
/*
* Extract the dictionary (if available).
*/
dictionary = (Map) getProperty(0);
dictionary = (Map<Long,String>) getProperty(0);
}

View File

@ -57,7 +57,7 @@ public final class OperandResolver {
*/
public static ValueEval getSingleValue(ValueEval arg, int srcCellRow, int srcCellCol)
throws EvaluationException {
ValueEval result;
final ValueEval result;
if (arg instanceof RefEval) {
result = chooseSingleElementFromRef((RefEval) arg);
} else if (arg instanceof AreaEval) {

View File

@ -491,7 +491,7 @@ public final class Countif extends Fixed2ArgFunction {
*/
private static ValueEval evaluateCriteriaArg(ValueEval arg, int srcRowIndex, int srcColumnIndex) {
try {
return OperandResolver.getSingleValue(arg, srcRowIndex, (short)srcColumnIndex);
return OperandResolver.getSingleValue(arg, srcRowIndex, srcColumnIndex);
} catch (EvaluationException e) {
return e.getErrorEval();
}

View File

@ -54,6 +54,7 @@ public final class Sumifs implements FreeRefFunction {
public static final FreeRefFunction instance = new Sumifs();
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
// need at least 3 arguments and need to have an odd number of arguments (sum-range plus x*(criteria_range, criteria))
if(args.length < 3 || args.length % 2 == 0) {
return ErrorEval.VALUE_INVALID;
}

View File

@ -32,6 +32,7 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
@ -110,9 +111,12 @@ public final class TestBugs extends BaseTestBugzillaIssues {
File file;
try {
file = TempFile.createTempFile(simpleFileName + "#", ".xls");
FileOutputStream out = new FileOutputStream(file);
wb.write(out);
out.close();
OutputStream out = new FileOutputStream(file);
try {
wb.write(out);
} finally {
out.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
@ -178,7 +182,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
cell = row.createCell(3);
// Write test
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellType(Cell.CELL_TYPE_STRING);
setCellText(cell, "a test");
// change existing numeric cell value
@ -460,7 +464,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
HSSFRow row = sheet.getRow(i);
if (row != null) {
HSSFCell cell = row .getCell(0);
assertEquals(HSSFCell.CELL_TYPE_STRING, cell.getCellType());
assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType());
count++;
}
}
@ -1151,13 +1155,13 @@ public final class TestBugs extends BaseTestBugzillaIssues {
}
private static void confirmCachedValue(double expectedValue, HSSFCell cell) {
assertEquals(HSSFCell.CELL_TYPE_FORMULA, cell.getCellType());
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cell.getCachedFormulaResultType());
assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType());
assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCachedFormulaResultType());
assertEquals(expectedValue, cell.getNumericCellValue(), 0.0);
}
private static void confirmCachedValue(String expectedValue, HSSFCell cell) {
assertEquals(HSSFCell.CELL_TYPE_FORMULA, cell.getCellType());
assertEquals(HSSFCell.CELL_TYPE_STRING, cell.getCachedFormulaResultType());
assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType());
assertEquals(Cell.CELL_TYPE_STRING, cell.getCachedFormulaResultType());
assertEquals(expectedValue, cell.getRichStringCellValue().getString());
}
@ -1270,7 +1274,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
s = wb.getSheet("OneVariable Table Completed");
r = s.getRow(3);
c = r.getCell(4);
assertEquals(HSSFCell.CELL_TYPE_FORMULA, c.getCellType());
assertEquals(Cell.CELL_TYPE_FORMULA, c.getCellType());
// TODO - check the formula once tables and
// arrays are properly supported
@ -1280,7 +1284,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
s = wb.getSheet("TwoVariable Table Example");
r = s.getRow(3);
c = r.getCell(4);
assertEquals(HSSFCell.CELL_TYPE_FORMULA, c.getCellType());
assertEquals(Cell.CELL_TYPE_FORMULA, c.getCellType());
// TODO - check the formula once tables and
// arrays are properly supported
@ -1333,7 +1337,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
assertTrue(wb.isSheetVeryHidden(2));
// Change 0 to be very hidden, and re-load
wb.setSheetHidden(0, HSSFWorkbook.SHEET_STATE_VERY_HIDDEN);
wb.setSheetHidden(0, Workbook.SHEET_STATE_VERY_HIDDEN);
HSSFWorkbook nwb = writeOutAndReadBack(wb);
@ -1579,7 +1583,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
OPOIFSFileSystem fs = new OPOIFSFileSystem(
HSSFITestDataProvider.instance.openWorkbookStream("46904.xls"));
new HSSFWorkbook(fs.getRoot(), false).close();
fail();
fail("Should catch exception here");
} catch(OldExcelFormatException e) {
assertTrue(e.getMessage().startsWith(
"The supplied spreadsheet seems to be Excel"
@ -1590,7 +1594,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
HSSFITestDataProvider.instance.openWorkbookStream("46904.xls"));
try {
new HSSFWorkbook(fs.getRoot(), false).close();
fail();
fail("Should catch exception here");
} finally {
fs.close();
}
@ -1846,17 +1850,15 @@ public final class TestBugs extends BaseTestBugzillaIssues {
assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0);
// TODO - Fix these so they work...
if(1==2) {
row = s.getRow(4);
assertEquals(Cell.CELL_TYPE_FORMULA, row.getCell(1).getCellType());
assertEquals("'[$http://gagravarr.org/FormulaRefs2.xls]Sheet1'!B2", row.getCell(1).getCellFormula());
assertEquals(123.0, row.getCell(1).getNumericCellValue(), 0);
/*row = s.getRow(4);
assertEquals(Cell.CELL_TYPE_FORMULA, row.getCell(1).getCellType());
assertEquals("'[$http://gagravarr.org/FormulaRefs2.xls]Sheet1'!B2", row.getCell(1).getCellFormula());
assertEquals(123.0, row.getCell(1).getNumericCellValue(), 0);
row = s.getRow(5);
assertEquals(Cell.CELL_TYPE_FORMULA, row.getCell(1).getCellType());
assertEquals("'[$http://example.com/FormulaRefs.xls]Sheet1'!B1", row.getCell(1).getCellFormula());
assertEquals(234.0, row.getCell(1).getNumericCellValue(), 0);
}
row = s.getRow(5);
assertEquals(Cell.CELL_TYPE_FORMULA, row.getCell(1).getCellType());
assertEquals("'[$http://example.com/FormulaRefs.xls]Sheet1'!B1", row.getCell(1).getCellFormula());
assertEquals(234.0, row.getCell(1).getNumericCellValue(), 0);*/
}
/**
@ -2419,9 +2421,11 @@ public final class TestBugs extends BaseTestBugzillaIssues {
Workbook wb = new HSSFWorkbook(); //or new HSSFWorkbook();
wb.addPicture(new byte[]{123,22}, Workbook.PICTURE_TYPE_JPEG);
assertEquals(wb.getAllPictures().size(), 1);
wb.close();
wb.close();
wb = new HSSFWorkbook();
wb = writeOutAndReadBack((HSSFWorkbook) wb);
assertEquals(wb.getAllPictures().size(), 0);
wb.addPicture(new byte[]{123,22}, Workbook.PICTURE_TYPE_JPEG);
@ -2482,7 +2486,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(0);
HSSFCellStyle rstyle = row.getRowStyle();
assertEquals(rstyle.getBorderBottom(), HSSFCellStyle.BORDER_DOUBLE);
assertEquals(rstyle.getBorderBottom(), CellStyle.BORDER_DOUBLE);
}
@Test