mirror of https://github.com/apache/poi.git
fix some Eclipse warnings, adjust some unit tests slightly
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1516818 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cb6ca3554d
commit
5a067c6b97
|
@ -61,7 +61,7 @@ public final class StyleRecord extends StandardRecord {
|
||||||
field_3_outline_style_level = in.readByte();
|
field_3_outline_style_level = in.readByte();
|
||||||
} else {
|
} else {
|
||||||
int field_2_name_length = in.readShort();
|
int field_2_name_length = in.readShort();
|
||||||
|
|
||||||
if(in.remaining() < 1) {
|
if(in.remaining() < 1) {
|
||||||
// Some files from Crystal Reports lack the is16BitUnicode byte
|
// Some files from Crystal Reports lack the is16BitUnicode byte
|
||||||
// the remaining fields, which is naughty
|
// the remaining fields, which is naughty
|
||||||
|
@ -71,7 +71,7 @@ public final class StyleRecord extends StandardRecord {
|
||||||
// guess this is OK if the string length is zero
|
// guess this is OK if the string length is zero
|
||||||
field_4_name = "";
|
field_4_name = "";
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
field_3_stringHasMultibyte = in.readByte() != 0x00;
|
field_3_stringHasMultibyte = in.readByte() != 0x00;
|
||||||
if (field_3_stringHasMultibyte) {
|
if (field_3_stringHasMultibyte) {
|
||||||
field_4_name = StringUtil.readUnicodeLE(in, field_2_name_length);
|
field_4_name = StringUtil.readUnicodeLE(in, field_2_name_length);
|
||||||
|
@ -92,7 +92,7 @@ public final class StyleRecord extends StandardRecord {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the actual index of the style extended format record
|
* get the actual index of the style extended format record
|
||||||
* @see #getXFIndex()
|
* @see #getXFIndex()
|
||||||
* @return index of the xf record
|
* @return index of the xf record
|
||||||
*/
|
*/
|
||||||
public int getXFIndex() {
|
public int getXFIndex() {
|
||||||
|
@ -138,6 +138,7 @@ public final class StyleRecord extends StandardRecord {
|
||||||
return field_4_name;
|
return field_4_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
|
@ -155,16 +156,18 @@ public final class StyleRecord extends StandardRecord {
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
protected int getDataSize() {
|
protected int getDataSize() {
|
||||||
if (isBuiltin()) {
|
if (isBuiltin()) {
|
||||||
return 4; // short, byte, byte
|
return 4; // short, byte, byte
|
||||||
}
|
}
|
||||||
return 2 // short xf index
|
return 2 // short xf index
|
||||||
+ 3 // str len + flag
|
+ 3 // str len + flag
|
||||||
+ field_4_name.length() * (field_3_stringHasMultibyte ? 2 : 1);
|
+ field_4_name.length() * (field_3_stringHasMultibyte ? 2 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void serialize(LittleEndianOutput out) {
|
public void serialize(LittleEndianOutput out) {
|
||||||
out.writeShort(field_1_xf_index);
|
out.writeShort(field_1_xf_index);
|
||||||
if (isBuiltin()) {
|
if (isBuiltin()) {
|
||||||
|
@ -181,6 +184,7 @@ public final class StyleRecord extends StandardRecord {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public short getSid() {
|
public short getSid() {
|
||||||
return sid;
|
return sid;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ import org.apache.poi.ss.formula.udf.UDFFinder;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Analysis Toolpack Function Definitions
|
* Analysis Toolpack Function Definitions
|
||||||
*/
|
*/
|
||||||
public final class AnalysisToolPak implements UDFFinder {
|
public final class AnalysisToolPak implements UDFFinder {
|
||||||
|
|
||||||
|
@ -229,9 +229,9 @@ public final class AnalysisToolPak implements UDFFinder {
|
||||||
if(metaData != null) {
|
if(metaData != null) {
|
||||||
throw new IllegalArgumentException(name + " is a built-in Excel function. " +
|
throw new IllegalArgumentException(name + " is a built-in Excel function. " +
|
||||||
"Use FunctoinEval.registerFunction(String name, Function func) instead.");
|
"Use FunctoinEval.registerFunction(String name, Function func) instead.");
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException(name + " is not a function from the Excel Analysis Toolpack.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new IllegalArgumentException(name + " is not a function from the Excel Analysis Toolpack.");
|
||||||
}
|
}
|
||||||
FreeRefFunction f = inst.findFunction(name);
|
FreeRefFunction f = inst.findFunction(name);
|
||||||
if(f != null && !(f instanceof NotImplemented)) {
|
if(f != null && !(f instanceof NotImplemented)) {
|
||||||
|
|
|
@ -106,7 +106,7 @@ public class POIXMLDocumentPart {
|
||||||
*
|
*
|
||||||
* @param part - The package part that holds xml data represenring this sheet.
|
* @param part - The package part that holds xml data represenring this sheet.
|
||||||
* @param rel - the relationship of the given package part
|
* @param rel - the relationship of the given package part
|
||||||
* @see #read(POIXMLFactory, java.util.Map)
|
* @see #read(POIXMLFactory, java.util.Map)
|
||||||
*/
|
*/
|
||||||
public POIXMLDocumentPart(PackagePart part, PackageRelationship rel){
|
public POIXMLDocumentPart(PackagePart part, PackageRelationship rel){
|
||||||
this.packagePart = part;
|
this.packagePart = part;
|
||||||
|
@ -131,7 +131,7 @@ public class POIXMLDocumentPart {
|
||||||
/**
|
/**
|
||||||
* When you open something like a theme, call this to
|
* When you open something like a theme, call this to
|
||||||
* re-base the XML Document onto the core child of the
|
* re-base the XML Document onto the core child of the
|
||||||
* current core document
|
* current core document
|
||||||
*/
|
*/
|
||||||
protected final void rebase(OPCPackage pkg) throws InvalidFormatException {
|
protected final void rebase(OPCPackage pkg) throws InvalidFormatException {
|
||||||
PackageRelationshipCollection cores =
|
PackageRelationshipCollection cores =
|
||||||
|
@ -179,7 +179,7 @@ public class POIXMLDocumentPart {
|
||||||
* {@link POIXMLDocumentPart} to the {@link PackagePart} of the target
|
* {@link POIXMLDocumentPart} to the {@link PackagePart} of the target
|
||||||
* {@link POIXMLDocumentPart} with a {@link PackageRelationship#getId()}
|
* {@link POIXMLDocumentPart} with a {@link PackageRelationship#getId()}
|
||||||
* matching the given parameter value.
|
* matching the given parameter value.
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* The relation id to look for
|
* The relation id to look for
|
||||||
* @return the target part of the relation, or null, if none exists
|
* @return the target part of the relation, or null, if none exists
|
||||||
|
@ -193,7 +193,7 @@ public class POIXMLDocumentPart {
|
||||||
* {@link PackageRelationship}, that sources from the {@link PackagePart} of
|
* {@link PackageRelationship}, that sources from the {@link PackagePart} of
|
||||||
* this {@link POIXMLDocumentPart} to the {@link PackagePart} of the given
|
* this {@link POIXMLDocumentPart} to the {@link PackagePart} of the given
|
||||||
* parameter value.
|
* parameter value.
|
||||||
*
|
*
|
||||||
* @param part
|
* @param part
|
||||||
* The {@link POIXMLDocumentPart} for which the according
|
* The {@link POIXMLDocumentPart} for which the according
|
||||||
* relation-id shall be found.
|
* relation-id shall be found.
|
||||||
|
@ -233,7 +233,7 @@ public class POIXMLDocumentPart {
|
||||||
/**
|
/**
|
||||||
* Remove the relation to the specified part in this package and remove the
|
* Remove the relation to the specified part in this package and remove the
|
||||||
* part, if it is no longer needed and flag is set to true.
|
* part, if it is no longer needed and flag is set to true.
|
||||||
*
|
*
|
||||||
* @param part
|
* @param part
|
||||||
* The related part, to which the relation shall be removed.
|
* The related part, to which the relation shall be removed.
|
||||||
* @param removeUnusedParts
|
* @param removeUnusedParts
|
||||||
|
@ -343,7 +343,8 @@ public class POIXMLDocumentPart {
|
||||||
* @param noRelation if true, then no relationship is added.
|
* @param noRelation if true, then no relationship is added.
|
||||||
* @return the created child POIXMLDocumentPart
|
* @return the created child POIXMLDocumentPart
|
||||||
*/
|
*/
|
||||||
protected final POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, boolean noRelation){
|
@SuppressWarnings("null")
|
||||||
|
protected final POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, boolean noRelation){
|
||||||
try {
|
try {
|
||||||
PackagePartName ppName = PackagingURIHelper.createPartName(descriptor.getFileName(idx));
|
PackagePartName ppName = PackagingURIHelper.createPartName(descriptor.getFileName(idx));
|
||||||
PackageRelationship rel = null;
|
PackageRelationship rel = null;
|
||||||
|
@ -414,7 +415,7 @@ public class POIXMLDocumentPart {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the PackagePart that is the target of a relationship from this Part.
|
* Get the PackagePart that is the target of a relationship from this Part.
|
||||||
*
|
*
|
||||||
|
|
|
@ -16,7 +16,12 @@
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi;
|
package org.apache.poi;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Centralises logic for finding/opening sample files
|
* Centralises logic for finding/opening sample files
|
||||||
|
@ -219,16 +224,20 @@ public final class POIDataSamples {
|
||||||
_is = is;
|
_is = is;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int read() throws IOException {
|
@Override
|
||||||
|
public int read() throws IOException {
|
||||||
return _is.read();
|
return _is.read();
|
||||||
}
|
}
|
||||||
public int read(byte[] b, int off, int len) throws IOException {
|
@Override
|
||||||
|
public int read(byte[] b, int off, int len) throws IOException {
|
||||||
return _is.read(b, off, len);
|
return _is.read(b, off, len);
|
||||||
}
|
}
|
||||||
public boolean markSupported() {
|
@Override
|
||||||
|
public boolean markSupported() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
public void close() throws IOException {
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
_is.close();
|
_is.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,9 +71,8 @@ public class AllUserModelTests {
|
||||||
result.addTestSuite(TestRowStyle.class);
|
result.addTestSuite(TestRowStyle.class);
|
||||||
result.addTestSuite(TestSanityChecker.class);
|
result.addTestSuite(TestSanityChecker.class);
|
||||||
result.addTestSuite(TestSheetHiding.class);
|
result.addTestSuite(TestSheetHiding.class);
|
||||||
if (false) { // deliberately avoiding this one
|
/* deliberately avoiding this one
|
||||||
result.addTestSuite(TestUnfixedBugs.class);
|
result.addTestSuite(TestUnfixedBugs.class);*/
|
||||||
}
|
|
||||||
result.addTestSuite(TestUnicodeWorkbook.class);
|
result.addTestSuite(TestUnicodeWorkbook.class);
|
||||||
result.addTestSuite(TestNonStandardWorkbookStreamNames.class);
|
result.addTestSuite(TestNonStandardWorkbookStreamNames.class);
|
||||||
result.addTestSuite(TestWorkbook.class);
|
result.addTestSuite(TestWorkbook.class);
|
||||||
|
|
|
@ -89,36 +89,41 @@ public abstract class BaseTestRow extends TestCase {
|
||||||
|
|
||||||
public void testRemoveCell() {
|
public void testRemoveCell() {
|
||||||
Workbook workbook = _testDataProvider.createWorkbook();
|
Workbook workbook = _testDataProvider.createWorkbook();
|
||||||
Sheet sheet = workbook.createSheet();
|
{
|
||||||
Row row = sheet.createRow(0);
|
Sheet sheet = workbook.createSheet();
|
||||||
|
Row row = sheet.createRow(0);
|
||||||
|
|
||||||
assertEquals(0, row.getPhysicalNumberOfCells());
|
assertEquals(0, row.getPhysicalNumberOfCells());
|
||||||
assertEquals(-1, row.getLastCellNum());
|
assertEquals(-1, row.getLastCellNum());
|
||||||
assertEquals(-1, row.getFirstCellNum());
|
assertEquals(-1, row.getFirstCellNum());
|
||||||
|
|
||||||
row.createCell(1);
|
row.createCell(1);
|
||||||
assertEquals(2, row.getLastCellNum());
|
assertEquals(2, row.getLastCellNum());
|
||||||
assertEquals(1, row.getFirstCellNum());
|
assertEquals(1, row.getFirstCellNum());
|
||||||
assertEquals(1, row.getPhysicalNumberOfCells());
|
assertEquals(1, row.getPhysicalNumberOfCells());
|
||||||
row.createCell(3);
|
row.createCell(3);
|
||||||
assertEquals(4, row.getLastCellNum());
|
assertEquals(4, row.getLastCellNum());
|
||||||
assertEquals(1, row.getFirstCellNum());
|
assertEquals(1, row.getFirstCellNum());
|
||||||
assertEquals(2, row.getPhysicalNumberOfCells());
|
assertEquals(2, row.getPhysicalNumberOfCells());
|
||||||
row.removeCell(row.getCell(3));
|
row.removeCell(row.getCell(3));
|
||||||
assertEquals(2, row.getLastCellNum());
|
assertEquals(2, row.getLastCellNum());
|
||||||
assertEquals(1, row.getFirstCellNum());
|
assertEquals(1, row.getFirstCellNum());
|
||||||
assertEquals(1, row.getPhysicalNumberOfCells());
|
assertEquals(1, row.getPhysicalNumberOfCells());
|
||||||
row.removeCell(row.getCell(1));
|
row.removeCell(row.getCell(1));
|
||||||
assertEquals(-1, row.getLastCellNum());
|
assertEquals(-1, row.getLastCellNum());
|
||||||
assertEquals(-1, row.getFirstCellNum());
|
assertEquals(-1, row.getFirstCellNum());
|
||||||
assertEquals(0, row.getPhysicalNumberOfCells());
|
assertEquals(0, row.getPhysicalNumberOfCells());
|
||||||
|
}
|
||||||
|
|
||||||
workbook = _testDataProvider.writeOutAndReadBack(workbook);
|
workbook = _testDataProvider.writeOutAndReadBack(workbook);
|
||||||
sheet = workbook.getSheetAt(0);
|
|
||||||
row = sheet.getRow(0);
|
{
|
||||||
assertEquals(-1, row.getLastCellNum());
|
Sheet sheet = workbook.getSheetAt(0);
|
||||||
assertEquals(-1, row.getFirstCellNum());
|
Row row = sheet.getRow(0);
|
||||||
assertEquals(0, row.getPhysicalNumberOfCells());
|
assertEquals(-1, row.getLastCellNum());
|
||||||
|
assertEquals(-1, row.getFirstCellNum());
|
||||||
|
assertEquals(0, row.getPhysicalNumberOfCells());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void baseTestRowBounds(int maxRowNum) {
|
public void baseTestRowBounds(int maxRowNum) {
|
||||||
|
@ -387,30 +392,30 @@ public abstract class BaseTestRow extends TestCase {
|
||||||
assertTrue(cell2 == it.next());
|
assertTrue(cell2 == it.next());
|
||||||
assertEquals(Cell.CELL_TYPE_STRING, cell5.getCellType());
|
assertEquals(Cell.CELL_TYPE_STRING, cell5.getCellType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRowStyle() {
|
public void testRowStyle() {
|
||||||
Workbook workbook = _testDataProvider.createWorkbook();
|
Workbook workbook = _testDataProvider.createWorkbook();
|
||||||
Sheet sheet = workbook.createSheet("test");
|
Sheet sheet = workbook.createSheet("test");
|
||||||
Row row1 = sheet.createRow(0);
|
Row row1 = sheet.createRow(0);
|
||||||
Row row2 = sheet.createRow(1);
|
Row row2 = sheet.createRow(1);
|
||||||
|
|
||||||
// Won't be styled currently
|
// Won't be styled currently
|
||||||
assertEquals(false, row1.isFormatted());
|
assertEquals(false, row1.isFormatted());
|
||||||
assertEquals(false, row2.isFormatted());
|
assertEquals(false, row2.isFormatted());
|
||||||
assertEquals(null, row1.getRowStyle());
|
assertEquals(null, row1.getRowStyle());
|
||||||
assertEquals(null, row2.getRowStyle());
|
assertEquals(null, row2.getRowStyle());
|
||||||
|
|
||||||
// Style one
|
// Style one
|
||||||
CellStyle style = workbook.createCellStyle();
|
CellStyle style = workbook.createCellStyle();
|
||||||
style.setDataFormat((short)4);
|
style.setDataFormat((short)4);
|
||||||
row2.setRowStyle(style);
|
row2.setRowStyle(style);
|
||||||
|
|
||||||
// Check
|
// Check
|
||||||
assertEquals(false, row1.isFormatted());
|
assertEquals(false, row1.isFormatted());
|
||||||
assertEquals(true, row2.isFormatted());
|
assertEquals(true, row2.isFormatted());
|
||||||
assertEquals(null, row1.getRowStyle());
|
assertEquals(null, row1.getRowStyle());
|
||||||
assertEquals(style, row2.getRowStyle());
|
assertEquals(style, row2.getRowStyle());
|
||||||
|
|
||||||
// Save, load and re-check
|
// Save, load and re-check
|
||||||
workbook = _testDataProvider.writeOutAndReadBack(workbook);
|
workbook = _testDataProvider.writeOutAndReadBack(workbook);
|
||||||
sheet = workbook.getSheetAt(0);
|
sheet = workbook.getSheetAt(0);
|
||||||
|
@ -418,7 +423,7 @@ public abstract class BaseTestRow extends TestCase {
|
||||||
row1 = sheet.getRow(0);
|
row1 = sheet.getRow(0);
|
||||||
row2 = sheet.getRow(1);
|
row2 = sheet.getRow(1);
|
||||||
style = workbook.getCellStyleAt(style.getIndex());
|
style = workbook.getCellStyleAt(style.getIndex());
|
||||||
|
|
||||||
assertEquals(false, row1.isFormatted());
|
assertEquals(false, row1.isFormatted());
|
||||||
assertEquals(true, row2.isFormatted());
|
assertEquals(true, row2.isFormatted());
|
||||||
assertEquals(null, row1.getRowStyle());
|
assertEquals(null, row1.getRowStyle());
|
||||||
|
|
Loading…
Reference in New Issue