diff --git a/src/examples/src/org/apache/poi/hssf/usermodel/examples/BigExample.java b/src/examples/src/org/apache/poi/hssf/usermodel/examples/BigExample.java index 3981a145d..14575aa00 100644 --- a/src/examples/src/org/apache/poi/hssf/usermodel/examples/BigExample.java +++ b/src/examples/src/org/apache/poi/hssf/usermodel/examples/BigExample.java @@ -19,6 +19,8 @@ package org.apache.poi.hssf.usermodel.examples; import org.apache.poi.hssf.usermodel.*; import org.apache.poi.hssf.util.HSSFColor; +import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.Font; import java.io.FileOutputStream; import java.io.IOException; @@ -57,14 +59,14 @@ public class BigExample { f.setColor(HSSFColor.RED.index); // make it bold //arial is the default font - f.setBoldweight(f.BOLDWEIGHT_BOLD); + f.setBoldweight(Font.BOLDWEIGHT_BOLD); //set font 2 to 10 point type f2.setFontHeightInPoints((short) 10); //make it the color at palette index 0xf (white) f2.setColor(HSSFColor.WHITE.index); //make it bold - f2.setBoldweight(f2.BOLDWEIGHT_BOLD); + f2.setBoldweight(Font.BOLDWEIGHT_BOLD); //set cell stlye cs.setFont(f); @@ -72,7 +74,7 @@ public class BigExample { cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0)")); //set a thin border - cs2.setBorderBottom(cs2.BORDER_THIN); + cs2.setBorderBottom(CellStyle.BORDER_THIN); //fill w fg fill color cs2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // set foreground fill to red @@ -141,7 +143,7 @@ public class BigExample { // define the third style to be the default // except with a thick black border at the bottom - cs3.setBorderBottom(cs3.BORDER_THICK); + cs3.setBorderBottom(CellStyle.BORDER_THICK); //create 50 cells for (int cellnum =0; cellnum < 50; cellnum++) { diff --git a/src/examples/src/org/apache/poi/hssf/usermodel/examples/EventExample.java b/src/examples/src/org/apache/poi/hssf/usermodel/examples/EventExample.java index c5644c959..7dd5ee3ca 100644 --- a/src/examples/src/org/apache/poi/hssf/usermodel/examples/EventExample.java +++ b/src/examples/src/org/apache/poi/hssf/usermodel/examples/EventExample.java @@ -47,11 +47,11 @@ public class EventExample // the BOFRecord can represent either the beginning of a sheet or the workbook case BOFRecord.sid: BOFRecord bof = (BOFRecord) record; - if (bof.getType() == bof.TYPE_WORKBOOK) + if (bof.getType() == BOFRecord.TYPE_WORKBOOK) { System.out.println("Encountered workbook"); // assigned to the class level member - } else if (bof.getType() == bof.TYPE_WORKSHEET) + } else if (bof.getType() == BOFRecord.TYPE_WORKSHEET) { System.out.println("Encountered sheet reference"); } diff --git a/src/examples/src/org/apache/poi/hssf/usermodel/examples/OfficeDrawing.java b/src/examples/src/org/apache/poi/hssf/usermodel/examples/OfficeDrawing.java index 1b580d35f..907d0f759 100644 --- a/src/examples/src/org/apache/poi/hssf/usermodel/examples/OfficeDrawing.java +++ b/src/examples/src/org/apache/poi/hssf/usermodel/examples/OfficeDrawing.java @@ -164,7 +164,7 @@ public class OfficeDrawing { HSSFPicture picture = patriarch.createPicture(anchor, loadPicture( "src/resources/logos/logoKarmokar4s.png", wb )); //Reset the image to the original size. picture.resize(); - picture.setLineStyle( picture.LINESTYLE_DASHDOTGEL ); + picture.setLineStyle( HSSFShape.LINESTYLE_DASHDOTGEL ); } diff --git a/src/java/org/apache/poi/ddf/EscherChildAnchorRecord.java b/src/java/org/apache/poi/ddf/EscherChildAnchorRecord.java index 6aa0efde9..b6193cea4 100644 --- a/src/java/org/apache/poi/ddf/EscherChildAnchorRecord.java +++ b/src/java/org/apache/poi/ddf/EscherChildAnchorRecord.java @@ -40,7 +40,7 @@ public class EscherChildAnchorRecord private int field_4_dy2; public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) { - int bytesRemaining = readHeader( data, offset ); + /*int bytesRemaining =*/ readHeader( data, offset ); int pos = offset + 8; int size = 0; field_1_dx1 = LittleEndian.getInt( data, pos + size );size+=4; diff --git a/src/java/org/apache/poi/ddf/EscherDgRecord.java b/src/java/org/apache/poi/ddf/EscherDgRecord.java index a4447dc01..c269ad446 100644 --- a/src/java/org/apache/poi/ddf/EscherDgRecord.java +++ b/src/java/org/apache/poi/ddf/EscherDgRecord.java @@ -37,7 +37,7 @@ public class EscherDgRecord private int field_2_lastMSOSPID; public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) { - int bytesRemaining = readHeader( data, offset ); + /*int bytesRemaining =*/ readHeader( data, offset ); int pos = offset + 8; int size = 0; field_1_numShapes = LittleEndian.getInt( data, pos + size ); size += 4; diff --git a/src/java/org/apache/poi/ddf/EscherSpRecord.java b/src/java/org/apache/poi/ddf/EscherSpRecord.java index 7d4dd5cfb..870bf575e 100644 --- a/src/java/org/apache/poi/ddf/EscherSpRecord.java +++ b/src/java/org/apache/poi/ddf/EscherSpRecord.java @@ -49,7 +49,7 @@ public class EscherSpRecord private int field_2_flags; public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) { - int bytesRemaining = readHeader( data, offset ); + /*int bytesRemaining =*/ readHeader( data, offset ); int pos = offset + 8; int size = 0; field_1_shapeId = LittleEndian.getInt( data, pos + size ); size += 4; diff --git a/src/java/org/apache/poi/hpsf/CustomProperties.java b/src/java/org/apache/poi/hpsf/CustomProperties.java index 83858eb73..9642e0dbc 100644 --- a/src/java/org/apache/poi/hpsf/CustomProperties.java +++ b/src/java/org/apache/poi/hpsf/CustomProperties.java @@ -131,7 +131,7 @@ public class CustomProperties extends HashMap final String name = customProperty.getName(); /* Check whether a property with this name is in the map already. */ - final Long oldId = (Long) dictionaryNameToID.get(name); + final Long oldId = dictionaryNameToID.get(name); if (oldId != null) customProperty.setID(oldId.longValue()); else @@ -159,7 +159,7 @@ public class CustomProperties extends HashMap */ public Object remove(final String name) { - final Long id = (Long) dictionaryNameToID.get(name); + final Long id = dictionaryNameToID.get(name); if (id == null) return null; dictionaryIDToName.remove(id); @@ -267,8 +267,8 @@ public class CustomProperties extends HashMap */ public Object get(final String name) { - final Long id = (Long) dictionaryNameToID.get(name); - final CustomProperty cp = (CustomProperty) super.get(id); + final Long id = dictionaryNameToID.get(name); + final CustomProperty cp = super.get(id); return cp != null ? cp.getValue() : null; } @@ -351,10 +351,10 @@ public class CustomProperties extends HashMap */ public boolean containsKey(Object key) { if(key instanceof Long) { - return super.containsKey((Long)key); + return super.containsKey(key); } if(key instanceof String) { - return super.containsKey((Long)dictionaryNameToID.get(key)); + return super.containsKey(dictionaryNameToID.get(key)); } return false; } @@ -364,7 +364,7 @@ public class CustomProperties extends HashMap */ public boolean containsValue(Object value) { if(value instanceof CustomProperty) { - return super.containsValue((CustomProperty)value); + return super.containsValue(value); } else { for(CustomProperty cp : super.values()) { if(cp.getValue() == value) { diff --git a/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java b/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java index 4a8303098..0dacd0d97 100644 --- a/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java +++ b/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java @@ -569,7 +569,7 @@ public class DocumentSummaryInformation extends SpecialPropertySet if (getSectionCount() >= 2) { cps = new CustomProperties(); - final Section section = (Section) getSections().get(1); + final Section section = getSections().get(1); final Map dictionary = section.getDictionary(); final Property[] properties = section.getProperties(); int propertyCount = 0; diff --git a/src/java/org/apache/poi/hpsf/MutableSection.java b/src/java/org/apache/poi/hpsf/MutableSection.java index 49eaa3227..a1b382466 100644 --- a/src/java/org/apache/poi/hpsf/MutableSection.java +++ b/src/java/org/apache/poi/hpsf/MutableSection.java @@ -576,7 +576,7 @@ public class MutableSection extends Section */ public Property[] getProperties() { - properties = (Property[]) preprops.toArray(new Property[0]); + properties = preprops.toArray(new Property[0]); return properties; } diff --git a/src/java/org/apache/poi/hpsf/Section.java b/src/java/org/apache/poi/hpsf/Section.java index 945cdf567..0c97a0e68 100644 --- a/src/java/org/apache/poi/hpsf/Section.java +++ b/src/java/org/apache/poi/hpsf/Section.java @@ -448,7 +448,7 @@ public class Section { String s = null; if (dictionary != null) - s = (String) dictionary.get(Long.valueOf(pid)); + s = dictionary.get(Long.valueOf(pid)); if (s == null) s = SectionIDMap.getPIDString(getFormatID().getBytes(), pid); if (s == null) diff --git a/src/java/org/apache/poi/hpsf/Variant.java b/src/java/org/apache/poi/hpsf/Variant.java index 8330a6d5a..fd1539ec0 100644 --- a/src/java/org/apache/poi/hpsf/Variant.java +++ b/src/java/org/apache/poi/hpsf/Variant.java @@ -352,9 +352,9 @@ public class Variant *

Maps the numbers denoting the variant types to their corresponding * variant type names.

*/ - private static Map numberToName; + private static Map numberToName; - private static Map numberToLength; + private static Map numberToLength; /** *

Denotes a variant type with a length that is unknown to HPSF yet.

@@ -391,7 +391,7 @@ public class Variant static { /* Initialize the number-to-name map: */ - Map tm1 = new HashMap(); + Map tm1 = new HashMap(); tm1.put(Long.valueOf(0), "VT_EMPTY"); tm1.put(Long.valueOf(1), "VT_NULL"); tm1.put(Long.valueOf(2), "VT_I2"); @@ -432,55 +432,55 @@ public class Variant tm1.put(Long.valueOf(70), "VT_BLOB_OBJECT"); tm1.put(Long.valueOf(71), "VT_CF"); tm1.put(Long.valueOf(72), "VT_CLSID"); - Map tm2 = new HashMap(tm1.size(), 1.0F); + Map tm2 = new HashMap(tm1.size(), 1.0F); tm2.putAll(tm1); numberToName = Collections.unmodifiableMap(tm2); /* Initialize the number-to-length map: */ - tm1.clear(); - tm1.put(Long.valueOf(0), LENGTH_0); - tm1.put(Long.valueOf(1), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(2), LENGTH_2); - tm1.put(Long.valueOf(3), LENGTH_4); - tm1.put(Long.valueOf(4), LENGTH_4); - tm1.put(Long.valueOf(5), LENGTH_8); - tm1.put(Long.valueOf(6), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(7), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(8), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(9), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(10), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(11), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(12), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(13), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(14), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(16), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(17), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(18), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(19), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(20), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(21), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(22), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(23), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(24), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(25), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(26), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(27), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(28), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(29), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(30), LENGTH_VARIABLE); - tm1.put(Long.valueOf(31), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(64), LENGTH_8); - tm1.put(Long.valueOf(65), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(66), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(67), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(68), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(69), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(70), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(71), LENGTH_UNKNOWN); - tm1.put(Long.valueOf(72), LENGTH_UNKNOWN); - tm2 = new HashMap(tm1.size(), 1.0F); - tm2.putAll(tm1); - numberToLength = Collections.unmodifiableMap(tm2); + Map tm3 = new HashMap(); + tm3.put(Long.valueOf(0), LENGTH_0); + tm3.put(Long.valueOf(1), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(2), LENGTH_2); + tm3.put(Long.valueOf(3), LENGTH_4); + tm3.put(Long.valueOf(4), LENGTH_4); + tm3.put(Long.valueOf(5), LENGTH_8); + tm3.put(Long.valueOf(6), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(7), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(8), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(9), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(10), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(11), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(12), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(13), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(14), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(16), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(17), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(18), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(19), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(20), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(21), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(22), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(23), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(24), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(25), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(26), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(27), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(28), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(29), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(30), LENGTH_VARIABLE); + tm3.put(Long.valueOf(31), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(64), LENGTH_8); + tm3.put(Long.valueOf(65), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(66), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(67), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(68), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(69), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(70), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(71), LENGTH_UNKNOWN); + tm3.put(Long.valueOf(72), LENGTH_UNKNOWN); + Map tm4 = new HashMap(tm1.size(), 1.0F); + tm4.putAll(tm3); + numberToLength = Collections.unmodifiableMap(tm4); } @@ -494,7 +494,7 @@ public class Variant */ public static String getVariantName(final long variantType) { - final String name = (String) numberToName.get(Long.valueOf(variantType)); + final String name = numberToName.get(Long.valueOf(variantType)); return name != null ? name : "unknown variant type"; } @@ -510,7 +510,7 @@ public class Variant public static int getVariantLength(final long variantType) { final Long key = Long.valueOf((int) variantType); - final Long length = (Long) numberToLength.get(key); + final Integer length = numberToLength.get(key); if (length == null) return -2; return length.intValue(); diff --git a/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java b/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java index 7150b6c1c..ce5301ac6 100644 --- a/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java +++ b/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java @@ -17,6 +17,7 @@ package org.apache.poi.hpsf.extractor; +import java.io.Closeable; import java.io.File; import java.io.IOException; import java.util.Iterator; @@ -39,6 +40,8 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem; * textual form. */ public class HPSFPropertiesExtractor extends POITextExtractor { + private Closeable toClose; + public HPSFPropertiesExtractor(POITextExtractor mainExtractor) { super(mainExtractor); } @@ -50,6 +53,7 @@ public class HPSFPropertiesExtractor extends POITextExtractor { } public HPSFPropertiesExtractor(NPOIFSFileSystem fs) { super(new HPSFPropertiesOnlyDocument(fs)); + this.toClose = fs; } public String getDocumentSummaryInformationText() { @@ -119,6 +123,19 @@ public class HPSFPropertiesExtractor extends POITextExtractor { throw new IllegalStateException("You already have the Metadata Text Extractor, not recursing!"); } + + + public void close() throws IOException { + super.close(); + + if(toClose != null) { + toClose.close(); + toClose = null; + } + } + + + private static abstract class HelperPropertySet extends SpecialPropertySet { public HelperPropertySet() { super(null); @@ -135,7 +152,11 @@ public class HPSFPropertiesExtractor extends POITextExtractor { for (String file : args) { HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor( new NPOIFSFileSystem(new File(file))); - System.out.println(ext.getText()); + try { + System.out.println(ext.getText()); + } finally { + ext.close(); + } } } } diff --git a/src/java/org/apache/poi/hpsf/wellknown/PropertyIDMap.java b/src/java/org/apache/poi/hpsf/wellknown/PropertyIDMap.java index 4eef8c4b0..02b73f329 100644 --- a/src/java/org/apache/poi/hpsf/wellknown/PropertyIDMap.java +++ b/src/java/org/apache/poi/hpsf/wellknown/PropertyIDMap.java @@ -34,7 +34,7 @@ import java.util.Map; * @author Rainer Klute <klute@rainer-klute.de> */ -public class PropertyIDMap extends HashMap { +public class PropertyIDMap extends HashMap { /* * The following definitions are for property IDs in the first @@ -271,7 +271,7 @@ public class PropertyIDMap extends HashMap { * * @param map The instance to be created is backed by this map. */ - public PropertyIDMap(final Map map) + public PropertyIDMap(final Map map) { super(map); } diff --git a/src/java/org/apache/poi/hssf/dev/ReSave.java b/src/java/org/apache/poi/hssf/dev/ReSave.java index 340d7b987..7e74b7a3a 100644 --- a/src/java/org/apache/poi/hssf/dev/ReSave.java +++ b/src/java/org/apache/poi/hssf/dev/ReSave.java @@ -17,13 +17,12 @@ package org.apache.poi.hssf.dev; -import org.apache.poi.hssf.usermodel.HSSFPatriarch; -import org.apache.poi.hssf.usermodel.HSSFSheet; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; - import java.io.FileInputStream; import java.io.FileOutputStream; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; + /** * Utility to test that POI produces readable output * after re-saving xls files. @@ -40,22 +39,28 @@ public class ReSave { System.out.print("reading " + arg + "..."); FileInputStream is = new FileInputStream(arg); HSSFWorkbook wb = new HSSFWorkbook(is); - is.close(); - System.out.println("done"); - - for(int i = 0; i < wb.getNumberOfSheets(); i++){ - HSSFSheet sheet = wb.getSheetAt(i); - if(initDrawing) { - HSSFPatriarch dg = sheet.getDrawingPatriarch(); + try { + System.out.println("done"); + + for(int i = 0; i < wb.getNumberOfSheets(); i++){ + HSSFSheet sheet = wb.getSheetAt(i); + if(initDrawing) { + /*HSSFPatriarch dg =*/ sheet.getDrawingPatriarch(); + } } + + String outputFile = arg.replace(".xls", "-saved.xls"); + System.out.print("saving to " + outputFile + "..."); + FileOutputStream out = new FileOutputStream(outputFile); + try { + wb.write(out); + } finally { + out.close(); + } + System.out.println("done"); + } finally { + wb.close(); } - - String outputFile = arg.replace(".xls", "-saved.xls"); - System.out.print("saving to " + outputFile + "..."); - FileOutputStream out = new FileOutputStream(outputFile); - wb.write(out); - out.close(); - System.out.println("done"); } } } diff --git a/src/java/org/apache/poi/hssf/model/DrawingManager2.java b/src/java/org/apache/poi/hssf/model/DrawingManager2.java index 8b2292e95..51abcde5b 100644 --- a/src/java/org/apache/poi/hssf/model/DrawingManager2.java +++ b/src/java/org/apache/poi/hssf/model/DrawingManager2.java @@ -30,7 +30,7 @@ import java.util.ArrayList; public class DrawingManager2 { EscherDggRecord dgg; - List drawingGroups = new ArrayList( ); + List drawingGroups = new ArrayList(); public DrawingManager2( EscherDggRecord dgg ) @@ -120,7 +120,7 @@ public class DrawingManager2 EscherDgRecord getDrawingGroup(int drawingGroupId) { - return (EscherDgRecord) drawingGroups.get(drawingGroupId-1); + return drawingGroups.get(drawingGroupId-1); } boolean drawingGroupExists( short dgId ) diff --git a/src/java/org/apache/poi/hssf/model/RecordStream.java b/src/java/org/apache/poi/hssf/model/RecordStream.java index d9f04f7e6..7c9dc8a60 100644 --- a/src/java/org/apache/poi/hssf/model/RecordStream.java +++ b/src/java/org/apache/poi/hssf/model/RecordStream.java @@ -53,7 +53,7 @@ public final class RecordStream { throw new RuntimeException("Attempt to read past end of record stream"); } _countRead ++; - return (Record) _list.get(_nextIndex++); + return _list.get(_nextIndex++); } /** @@ -73,7 +73,7 @@ public final class RecordStream { if(!hasNext()) { return -1; } - return ((Record)_list.get(_nextIndex)).getSid(); + return _list.get(_nextIndex).getSid(); } public int getCountRead() { diff --git a/src/java/org/apache/poi/hssf/record/TextObjectRecord.java b/src/java/org/apache/poi/hssf/record/TextObjectRecord.java index 8bc254855..56bc7bf8d 100644 --- a/src/java/org/apache/poi/hssf/record/TextObjectRecord.java +++ b/src/java/org/apache/poi/hssf/record/TextObjectRecord.java @@ -212,7 +212,7 @@ public final class TextObjectRecord extends ContinuableRecord { for (int i = 0; i < nRuns; i++) { out.writeShort(str.getIndexOfFormattingRun(i)); int fontIndex = str.getFontOfFormattingRun(i); - out.writeShort(fontIndex == str.NO_FONT ? 0 : fontIndex); + out.writeShort(fontIndex == HSSFRichTextString.NO_FONT ? 0 : fontIndex); out.writeInt(0); // skip reserved } out.writeShort(str.length()); diff --git a/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java b/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java index 1ad0488ce..6aed70faa 100644 --- a/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java +++ b/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java @@ -32,16 +32,16 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate { /** * List of {@link ColumnInfoRecord}s assumed to be in order */ - private final List records; + private final List records; - private static final class CIRComparator implements Comparator { - public static final Comparator instance = new CIRComparator(); + private static final class CIRComparator implements Comparator { + public static final Comparator instance = new CIRComparator(); private CIRComparator() { // enforce singleton } - public int compare(Object a, Object b) { - return compareColInfos((ColumnInfoRecord)a, (ColumnInfoRecord)b); + public int compare(ColumnInfoRecord a, ColumnInfoRecord b) { + return compareColInfos(a, b); } public static int compareColInfos(ColumnInfoRecord a, ColumnInfoRecord b) { return a.getFirstColumn()-b.getFirstColumn(); @@ -52,7 +52,7 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate { * Creates an empty aggregate */ public ColumnInfoRecordsAggregate() { - records = new ArrayList(); + records = new ArrayList(); } public ColumnInfoRecordsAggregate(RecordStream rs) { this(); @@ -81,8 +81,8 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate { public Object clone() { ColumnInfoRecordsAggregate rec = new ColumnInfoRecordsAggregate(); for (int k = 0; k < records.size(); k++) { - ColumnInfoRecord ci = ( ColumnInfoRecord ) records.get(k); - rec.records.add(ci.clone()); + ColumnInfoRecord ci = records.get(k); + rec.records.add((ColumnInfoRecord) ci.clone()); } return rec; } @@ -114,7 +114,7 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate { } ColumnInfoRecord cirPrev = null; for(int i=0; i 0) { // Excel probably wouldn't mind, but there is much logic in this class @@ -127,11 +127,11 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate { private int findStartOfColumnOutlineGroup(int pIdx) { // Find the start of the group. - ColumnInfoRecord columnInfo = (ColumnInfoRecord) records.get(pIdx); + ColumnInfoRecord columnInfo = records.get(pIdx); int level = columnInfo.getOutlineLevel(); int idx = pIdx; while (idx != 0) { - ColumnInfoRecord prevColumnInfo = (ColumnInfoRecord) records.get(idx - 1); + ColumnInfoRecord prevColumnInfo = records.get(idx - 1); if (!prevColumnInfo.isAdjacentBefore(columnInfo)) { break; } @@ -147,11 +147,11 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate { private int findEndOfColumnOutlineGroup(int colInfoIndex) { // Find the end of the group. - ColumnInfoRecord columnInfo = (ColumnInfoRecord) records.get(colInfoIndex); + ColumnInfoRecord columnInfo = records.get(colInfoIndex); int level = columnInfo.getOutlineLevel(); int idx = colInfoIndex; while (idx < records.size() - 1) { - ColumnInfoRecord nextColumnInfo = (ColumnInfoRecord) records.get(idx + 1); + ColumnInfoRecord nextColumnInfo = records.get(idx + 1); if (!columnInfo.isAdjacentBefore(nextColumnInfo)) { break; } @@ -165,7 +165,7 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate { } private ColumnInfoRecord getColInfo(int idx) { - return (ColumnInfoRecord) records.get( idx ); + return records.get( idx ); } /** @@ -305,7 +305,7 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate { int k = 0; for (k = 0; k < records.size(); k++) { - ColumnInfoRecord tci = (ColumnInfoRecord) records.get(k); + ColumnInfoRecord tci = records.get(k); if (tci.containsColumn(targetColumnIx)) { ci = tci; break; diff --git a/src/java/org/apache/poi/hssf/record/aggregates/ConditionalFormattingTable.java b/src/java/org/apache/poi/hssf/record/aggregates/ConditionalFormattingTable.java index cffa34173..33a2f7b29 100644 --- a/src/java/org/apache/poi/hssf/record/aggregates/ConditionalFormattingTable.java +++ b/src/java/org/apache/poi/hssf/record/aggregates/ConditionalFormattingTable.java @@ -33,18 +33,18 @@ import org.apache.poi.ss.formula.FormulaShifter; */ public final class ConditionalFormattingTable extends RecordAggregate { - private final List _cfHeaders; + private final List _cfHeaders; /** * Creates an empty ConditionalFormattingTable */ public ConditionalFormattingTable() { - _cfHeaders = new ArrayList(); + _cfHeaders = new ArrayList(); } public ConditionalFormattingTable(RecordStream rs) { - List temp = new ArrayList(); + List temp = new ArrayList(); while (rs.peekNextClass() == CFHeaderRecord.class) { temp.add(CFRecordsAggregate.createCFAggregate(rs)); } @@ -53,7 +53,7 @@ public final class ConditionalFormattingTable extends RecordAggregate { public void visitContainedRecords(RecordVisitor rv) { for (int i = 0; i < _cfHeaders.size(); i++) { - CFRecordsAggregate subAgg = (CFRecordsAggregate) _cfHeaders.get(i); + CFRecordsAggregate subAgg = _cfHeaders.get(i); subAgg.visitContainedRecords(rv); } } @@ -72,7 +72,7 @@ public final class ConditionalFormattingTable extends RecordAggregate { public CFRecordsAggregate get(int index) { checkIndex(index); - return (CFRecordsAggregate) _cfHeaders.get(index); + return _cfHeaders.get(index); } public void remove(int index) { @@ -89,7 +89,7 @@ public final class ConditionalFormattingTable extends RecordAggregate { public void updateFormulasAfterCellShift(FormulaShifter shifter, int externSheetIndex) { for (int i = 0; i < _cfHeaders.size(); i++) { - CFRecordsAggregate subAgg = (CFRecordsAggregate) _cfHeaders.get(i); + CFRecordsAggregate subAgg = _cfHeaders.get(i); boolean shouldKeep = subAgg.updateFormulasAfterCellShift(shifter, externSheetIndex); if (!shouldKeep) { _cfHeaders.remove(i); diff --git a/src/java/org/apache/poi/hssf/record/aggregates/DataValidityTable.java b/src/java/org/apache/poi/hssf/record/aggregates/DataValidityTable.java index e2dfcd6d3..ff5b9604b 100644 --- a/src/java/org/apache/poi/hssf/record/aggregates/DataValidityTable.java +++ b/src/java/org/apache/poi/hssf/record/aggregates/DataValidityTable.java @@ -23,7 +23,6 @@ import java.util.List; import org.apache.poi.hssf.model.RecordStream; import org.apache.poi.hssf.record.DVALRecord; import org.apache.poi.hssf.record.DVRecord; -import org.apache.poi.hssf.record.Record; /** * Manages the DVALRecord and DVRecords for a single sheet
@@ -37,20 +36,20 @@ public final class DataValidityTable extends RecordAggregate { * The list of data validations for the current sheet. * Note - this may be empty (contrary to OOO documentation) */ - private final List _validationList; + private final List _validationList; public DataValidityTable(RecordStream rs) { _headerRec = (DVALRecord) rs.getNext(); - List temp = new ArrayList(); + List temp = new ArrayList(); while (rs.peekNextClass() == DVRecord.class) { - temp.add(rs.getNext()); + temp.add((DVRecord) rs.getNext()); } _validationList = temp; } public DataValidityTable() { _headerRec = new DVALRecord(); - _validationList = new ArrayList(); + _validationList = new ArrayList(); } public void visitContainedRecords(RecordVisitor rv) { @@ -59,7 +58,7 @@ public final class DataValidityTable extends RecordAggregate { } rv.visitRecord(_headerRec); for (int i = 0; i < _validationList.size(); i++) { - rv.visitRecord((Record) _validationList.get(i)); + rv.visitRecord(_validationList.get(i)); } } diff --git a/src/java/org/apache/poi/hssf/usermodel/DVConstraint.java b/src/java/org/apache/poi/hssf/usermodel/DVConstraint.java index 8b6f56418..8e322ce80 100644 --- a/src/java/org/apache/poi/hssf/usermodel/DVConstraint.java +++ b/src/java/org/apache/poi/hssf/usermodel/DVConstraint.java @@ -162,7 +162,7 @@ public class DVConstraint implements DataValidationConstraint { // formula2 and value2 are mutually exclusive String formula2 = getFormulaFromTextExpression(expr2); Double value2 = formula2 == null ? convertTime(expr2) : null; - return new DVConstraint(VT.TIME, comparisonOperator, formula1, formula2, value1, value2, null); + return new DVConstraint(ValidationType.TIME, comparisonOperator, formula1, formula2, value1, value2, null); } /** @@ -192,7 +192,7 @@ public class DVConstraint implements DataValidationConstraint { // formula2 and value2 are mutually exclusive String formula2 = getFormulaFromTextExpression(expr2); Double value2 = formula2 == null ? convertDate(expr2, df) : null; - return new DVConstraint(VT.DATE, comparisonOperator, formula1, formula2, value1, value2, null); + return new DVConstraint(ValidationType.DATE, comparisonOperator, formula1, formula2, value1, value2, null); } /** @@ -270,7 +270,7 @@ public class DVConstraint implements DataValidationConstraint { if (formula == null) { throw new IllegalArgumentException("formula must be supplied"); } - return new DVConstraint(VT.FORMULA, OperatorType.IGNORED, formula, null, null, null, null); + return new DVConstraint(ValidationType.FORMULA, OperatorType.IGNORED, formula, null, null, null, null); } /* (non-Javadoc) @@ -284,14 +284,14 @@ public class DVConstraint implements DataValidationConstraint { * @return true if this constraint is a 'list' validation */ public boolean isListValidationType() { - return _validationType == VT.LIST; + return _validationType == ValidationType.LIST; } /** * Convenience method * @return true if this constraint is a 'list' validation with explicit values */ public boolean isExplicitList() { - return _validationType == VT.LIST && _explicitListValues != null; + return _validationType == ValidationType.LIST && _explicitListValues != null; } /* (non-Javadoc) * @see org.apache.poi.hssf.usermodel.DataValidationConstraint#getOperator() @@ -316,7 +316,7 @@ public class DVConstraint implements DataValidationConstraint { * @see org.apache.poi.hssf.usermodel.DataValidationConstraint#setExplicitListValues(java.lang.String[]) */ public void setExplicitListValues(String[] explicitListValues) { - if (_validationType != VT.LIST) { + if (_validationType != ValidationType.LIST) { throw new RuntimeException("Cannot setExplicitListValues on non-list constraint"); } _formula1 = null; diff --git a/src/java/org/apache/poi/ss/formula/constant/ErrorConstant.java b/src/java/org/apache/poi/ss/formula/constant/ErrorConstant.java index b3c7ee720..67b876923 100644 --- a/src/java/org/apache/poi/ss/formula/constant/ErrorConstant.java +++ b/src/java/org/apache/poi/ss/formula/constant/ErrorConstant.java @@ -33,13 +33,20 @@ public class ErrorConstant { // convenient access to name space private static final ErrorConstants EC = null; - private static final ErrorConstant NULL = new ErrorConstant(EC.ERROR_NULL); - private static final ErrorConstant DIV_0 = new ErrorConstant(EC.ERROR_DIV_0); - private static final ErrorConstant VALUE = new ErrorConstant(EC.ERROR_VALUE); - private static final ErrorConstant REF = new ErrorConstant(EC.ERROR_REF); - private static final ErrorConstant NAME = new ErrorConstant(EC.ERROR_NAME); - private static final ErrorConstant NUM = new ErrorConstant(EC.ERROR_NUM); - private static final ErrorConstant NA = new ErrorConstant(EC.ERROR_NA); + @SuppressWarnings("static-access") + private static final ErrorConstant NULL = new ErrorConstant(EC.ERROR_NULL); + @SuppressWarnings("static-access") + private static final ErrorConstant DIV_0 = new ErrorConstant(EC.ERROR_DIV_0); + @SuppressWarnings("static-access") + private static final ErrorConstant VALUE = new ErrorConstant(EC.ERROR_VALUE); + @SuppressWarnings("static-access") + private static final ErrorConstant REF = new ErrorConstant(EC.ERROR_REF); + @SuppressWarnings("static-access") + private static final ErrorConstant NAME = new ErrorConstant(EC.ERROR_NAME); + @SuppressWarnings("static-access") + private static final ErrorConstant NUM = new ErrorConstant(EC.ERROR_NUM); + @SuppressWarnings("static-access") + private static final ErrorConstant NA = new ErrorConstant(EC.ERROR_NA); private final int _errorCode; diff --git a/src/java/org/apache/poi/ss/formula/eval/ErrorEval.java b/src/java/org/apache/poi/ss/formula/eval/ErrorEval.java index 6cc8136b3..b2a46d831 100644 --- a/src/java/org/apache/poi/ss/formula/eval/ErrorEval.java +++ b/src/java/org/apache/poi/ss/formula/eval/ErrorEval.java @@ -29,18 +29,25 @@ public final class ErrorEval implements ValueEval { private static final ErrorConstants EC = null; /** #NULL! - Intersection of two cell ranges is empty */ + @SuppressWarnings("static-access") public static final ErrorEval NULL_INTERSECTION = new ErrorEval(EC.ERROR_NULL); /** #DIV/0! - Division by zero */ + @SuppressWarnings("static-access") public static final ErrorEval DIV_ZERO = new ErrorEval(EC.ERROR_DIV_0); /** #VALUE! - Wrong type of operand */ + @SuppressWarnings("static-access") public static final ErrorEval VALUE_INVALID = new ErrorEval(EC.ERROR_VALUE); /** #REF! - Illegal or deleted cell reference */ + @SuppressWarnings("static-access") public static final ErrorEval REF_INVALID = new ErrorEval(EC.ERROR_REF); /** #NAME? - Wrong function or range name */ + @SuppressWarnings("static-access") public static final ErrorEval NAME_INVALID = new ErrorEval(EC.ERROR_NAME); /** #NUM! - Value range overflow */ + @SuppressWarnings("static-access") public static final ErrorEval NUM_ERROR = new ErrorEval(EC.ERROR_NUM); /** #N/A - Argument or function not available */ + @SuppressWarnings("static-access") public static final ErrorEval NA = new ErrorEval(EC.ERROR_NA); diff --git a/src/java/org/apache/poi/ss/formula/ptg/ErrPtg.java b/src/java/org/apache/poi/ss/formula/ptg/ErrPtg.java index 2e38c3308..ebe656f39 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/ErrPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/ErrPtg.java @@ -30,18 +30,25 @@ public final class ErrPtg extends ScalarConstantPtg { private static final ErrorConstants EC = null; /** #NULL! - Intersection of two cell ranges is empty */ + @SuppressWarnings("static-access") public static final ErrPtg NULL_INTERSECTION = new ErrPtg(EC.ERROR_NULL); /** #DIV/0! - Division by zero */ + @SuppressWarnings("static-access") public static final ErrPtg DIV_ZERO = new ErrPtg(EC.ERROR_DIV_0); /** #VALUE! - Wrong type of operand */ + @SuppressWarnings("static-access") public static final ErrPtg VALUE_INVALID = new ErrPtg(EC.ERROR_VALUE); /** #REF! - Illegal or deleted cell reference */ + @SuppressWarnings("static-access") public static final ErrPtg REF_INVALID = new ErrPtg(EC.ERROR_REF); /** #NAME? - Wrong function or range name */ + @SuppressWarnings("static-access") public static final ErrPtg NAME_INVALID = new ErrPtg(EC.ERROR_NAME); /** #NUM! - Value range overflow */ + @SuppressWarnings("static-access") public static final ErrPtg NUM_ERROR = new ErrPtg(EC.ERROR_NUM); /** #N/A - Argument or function not available */ + @SuppressWarnings("static-access") public static final ErrPtg N_A = new ErrPtg(EC.ERROR_NA); diff --git a/src/java/org/apache/poi/ss/util/AreaReference.java b/src/java/org/apache/poi/ss/util/AreaReference.java index 5d747c59c..d59388873 100644 --- a/src/java/org/apache/poi/ss/util/AreaReference.java +++ b/src/java/org/apache/poi/ss/util/AreaReference.java @@ -17,11 +17,12 @@ package org.apache.poi.ss.util; -import org.apache.poi.ss.SpreadsheetVersion; - import java.util.ArrayList; +import java.util.List; import java.util.StringTokenizer; +import org.apache.poi.ss.SpreadsheetVersion; + public class AreaReference { /** The character (!) that separates sheet names from cell references */ @@ -199,14 +200,14 @@ public class AreaReference { * returns an array of contiguous area references. */ public static AreaReference[] generateContiguous(String reference) { - ArrayList refs = new ArrayList(); + List refs = new ArrayList(); StringTokenizer st = new StringTokenizer(reference, ","); while(st.hasMoreTokens()) { refs.add( new AreaReference(st.nextToken()) ); } - return (AreaReference[])refs.toArray(new AreaReference[refs.size()]); + return refs.toArray(new AreaReference[refs.size()]); } /** @@ -250,14 +251,14 @@ public class AreaReference { int maxCol = Math.max(_firstCell.getCol(), _lastCell.getCol()); String sheetName = _firstCell.getSheetName(); - ArrayList refs = new ArrayList(); + List refs = new ArrayList(); for(int row=minRow; row<=maxRow; row++) { for(int col=minCol; col<=maxCol; col++) { CellReference ref = new CellReference(sheetName, row, col, _firstCell.isRowAbsolute(), _firstCell.isColAbsolute()); refs.add(ref); } } - return (CellReference[])refs.toArray(new CellReference[refs.size()]); + return refs.toArray(new CellReference[refs.size()]); } /** diff --git a/src/java/org/apache/poi/ss/util/CellRangeAddressList.java b/src/java/org/apache/poi/ss/util/CellRangeAddressList.java index 54112c7d1..8d9919823 100644 --- a/src/java/org/apache/poi/ss/util/CellRangeAddressList.java +++ b/src/java/org/apache/poi/ss/util/CellRangeAddressList.java @@ -42,10 +42,10 @@ public class CellRangeAddressList { /** * List of CellRangeAddresses. Each structure represents a cell range */ - protected final List _list; + protected final List _list; public CellRangeAddressList() { - _list = new ArrayList(); + _list = new ArrayList(); } /** * Convenience constructor for creating a CellRangeAddressList with a single @@ -101,14 +101,14 @@ public class CellRangeAddressList { throw new RuntimeException("Range index (" + rangeIndex + ") is outside allowable range (0.." + (_list.size()-1) + ")"); } - return (CellRangeAddress) _list.remove(rangeIndex); + return _list.remove(rangeIndex); } /** * @return CellRangeAddress at the given index */ public CellRangeAddress getCellRangeAddress(int index) { - return (CellRangeAddress) _list.get(index); + return _list.get(index); } public int getSize() { @@ -131,7 +131,7 @@ public class CellRangeAddressList { int nItems = _list.size(); out.writeShort(nItems); for (int k = 0; k < nItems; k++) { - CellRangeAddress region = (CellRangeAddress) _list.get(k); + CellRangeAddress region = _list.get(k); region.serialize(out); } } @@ -142,7 +142,7 @@ public class CellRangeAddressList { int nItems = _list.size(); for (int k = 0; k < nItems; k++) { - CellRangeAddress region = (CellRangeAddress) _list.get(k); + CellRangeAddress region = _list.get(k); result.addCellRangeAddress(region.copy()); } return result; diff --git a/src/java/org/apache/poi/util/BinaryTree.java b/src/java/org/apache/poi/util/BinaryTree.java index 551d58878..e2ae5e58c 100644 --- a/src/java/org/apache/poi/util/BinaryTree.java +++ b/src/java/org/apache/poi/util/BinaryTree.java @@ -88,6 +88,7 @@ import java.util.*; * @author Marc Johnson (mjohnson at apache dot org) */ //for performance +@SuppressWarnings("rawtypes") public class BinaryTree extends AbstractMap { final Node[] _root; int _size = 0; diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/TextFragment.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/TextFragment.java index 6bdf45ae1..1114b8944 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/TextFragment.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/TextFragment.java @@ -23,6 +23,7 @@ import java.awt.*; import java.awt.font.TextLayout; import java.text.AttributedCharacterIterator; import java.text.AttributedString; +import java.text.CharacterIterator; /** * a renderable text fragment @@ -76,7 +77,7 @@ class TextFragment { AttributedCharacterIterator it = _str.getIterator(); StringBuffer buf = new StringBuffer(); - for (char c = it.first(); c != it.DONE; c = it.next()) { + for (char c = it.first(); c != CharacterIterator.DONE; c = it.next()) { buf.append(c); } return buf.toString(); diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java index bfa4c6d67..32eab8dc6 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java @@ -33,7 +33,6 @@ import org.apache.poi.ss.formula.udf.UDFFinder; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellValue; import org.apache.poi.ss.usermodel.FormulaEvaluator; -import org.apache.poi.ss.usermodel.Workbook; /** * Evaluates formula cells.

@@ -239,7 +238,7 @@ public class XSSFFormulaEvaluator implements FormulaEvaluator, WorkbookEvaluator * cells, and calling evaluateFormulaCell on each one. */ public static void evaluateAllFormulaCells(XSSFWorkbook wb) { - HSSFFormulaEvaluator.evaluateAllFormulaCells((Workbook)wb); + HSSFFormulaEvaluator.evaluateAllFormulaCells(wb); } /** * Loops over all cells in all sheets of the supplied diff --git a/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java b/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java index 6727f5257..15783163e 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java +++ b/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java @@ -312,7 +312,7 @@ public class XWPFHeaderFooterPolicy { private XmlOptions commit(XWPFHeaderFooter wrapper) { - XmlOptions xmlOptions = new XmlOptions(wrapper.DEFAULT_XML_OPTIONS); + XmlOptions xmlOptions = new XmlOptions(POIXMLDocumentPart.DEFAULT_XML_OPTIONS); Map map = new HashMap(); map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m"); map.put("urn:schemas-microsoft-com:office:office", "o"); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java index a99e0f75e..b4ab2834e 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java @@ -109,7 +109,7 @@ public final class TestColumnHelper extends TestCase { assertEquals(9, cols1.sizeOfColArray()); assertEquals(20, cols1.getColArray(8).getMin()); assertEquals(30, cols1.getColArray(8).getMax()); - helper.sortColumns(cols1); + ColumnHelper.sortColumns(cols1); assertEquals(9, cols1.sizeOfColArray()); assertEquals(25, cols1.getColArray(8).getMin()); assertEquals(27, cols1.getColArray(8).getMax()); diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java index cac18fa96..a607d0e3f 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java @@ -93,10 +93,10 @@ public final class TestXWPFHeader extends TestCase { pars2[1] = p3; // Set headers - XWPFHeader headerD = policy.createHeader(policy.DEFAULT, pars); - XWPFHeader headerF = policy.createHeader(policy.FIRST); + XWPFHeader headerD = policy.createHeader(XWPFHeaderFooterPolicy.DEFAULT, pars); + XWPFHeader headerF = policy.createHeader(XWPFHeaderFooterPolicy.FIRST); // Set a default footer and capture the returned XWPFFooter object. - XWPFFooter footer = policy.createFooter(policy.DEFAULT, pars2); + XWPFFooter footer = policy.createFooter(XWPFHeaderFooterPolicy.DEFAULT, pars2); // Ensure the headers and footer were set correctly.... assertNotNull(policy.getDefaultHeader()); diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java index cca2022a7..317ea8bf0 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java @@ -22,7 +22,9 @@ import java.lang.reflect.Field; import java.util.Arrays; import junit.framework.TestCase; + import org.apache.poi.hwpf.HWPFDocFixture; +import org.apache.poi.hwpf.model.types.DOPAbstractType; public final class TestDocumentProperties extends TestCase @@ -33,7 +35,7 @@ public final class TestDocumentProperties public void testReadWrite() throws Exception { - int size = _documentProperties.getSize(); + int size = DOPAbstractType.getSize(); byte[] buf = new byte[size]; _documentProperties.serialize(buf, 0); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestDataValidation.java b/src/testcases/org/apache/poi/hssf/usermodel/TestDataValidation.java index 1d71ca5c6..b3bfc534e 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestDataValidation.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestDataValidation.java @@ -45,6 +45,9 @@ import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.usermodel.DataValidation.ErrorStyle; +import org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType; import org.apache.poi.ss.util.CellRangeAddressList; /** @@ -149,11 +152,11 @@ public final class TestDataValidation extends BaseTestDataValidation { int dvRow = 0; Sheet sheet = wb.getSheetAt(0); DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper(); - DataValidationConstraint dc = dataValidationHelper.createIntegerConstraint(OP.EQUAL, "42", null); + DataValidationConstraint dc = dataValidationHelper.createIntegerConstraint(OperatorType.EQUAL, "42", null); DataValidation dv = dataValidationHelper.createValidation(dc,new CellRangeAddressList(dvRow, dvRow, 0, 0)); dv.setEmptyCellAllowed(false); - dv.setErrorStyle(ES.STOP); + dv.setErrorStyle(ErrorStyle.STOP); dv.setShowPromptBox(true); dv.createErrorBox("Xxx", "Yyy"); dv.setSuppressDropDownArrow(true); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java index c9ce13fca..7fdb4bd75 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java @@ -31,6 +31,7 @@ import org.apache.poi.hssf.record.LabelSSTRecord; import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.Region; import org.apache.poi.util.TempFile; @@ -395,7 +396,7 @@ public final class TestWorkbook extends TestCase { HSSFCell c = s.getRow(0).getCell(0); int a = c.getCellType(); - assertEquals(a, c.CELL_TYPE_NUMERIC); + assertEquals(a, Cell.CELL_TYPE_NUMERIC); } /** diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestEqualEval.java b/src/testcases/org/apache/poi/ss/formula/eval/TestEqualEval.java index 7eaa3e913..e10de014c 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/TestEqualEval.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/TestEqualEval.java @@ -43,7 +43,7 @@ public final class TestEqualEval extends TestCase { EvalFactory.createAreaEval("B1:B1", values), BoolEval.FALSE, }; - ValueEval result = evaluate(EI.Equal, args, 10, 10); + ValueEval result = evaluate(EvalInstances.Equal, args, 10, 10); if (result instanceof ErrorEval) { if (result == ErrorEval.VALUE_INVALID) { throw new AssertionFailedError("Identified bug in evaluation of 1x1 area"); @@ -61,7 +61,7 @@ public final class TestEqualEval extends TestCase { new StringEval(""), BlankEval.instance, }; - ValueEval result = evaluate(EI.Equal, args, 10, 10); + ValueEval result = evaluate(EvalInstances.Equal, args, 10, 10); assertEquals(BoolEval.class, result.getClass()); BoolEval be = (BoolEval) result; if (!be.getBooleanValue()) { @@ -74,14 +74,14 @@ public final class TestEqualEval extends TestCase { * Test for bug 46613 (observable at svn r737248) */ public void testStringInsensitive_bug46613() { - if (!evalStringCmp("abc", "aBc", EI.Equal)) { + if (!evalStringCmp("abc", "aBc", EvalInstances.Equal)) { throw new AssertionFailedError("Identified bug 46613"); } - assertTrue(evalStringCmp("abc", "aBc", EI.Equal)); - assertTrue(evalStringCmp("ABC", "azz", EI.LessThan)); - assertTrue(evalStringCmp("abc", "AZZ", EI.LessThan)); - assertTrue(evalStringCmp("ABC", "aaa", EI.GreaterThan)); - assertTrue(evalStringCmp("abc", "AAA", EI.GreaterThan)); + assertTrue(evalStringCmp("abc", "aBc", EvalInstances.Equal)); + assertTrue(evalStringCmp("ABC", "azz", EvalInstances.LessThan)); + assertTrue(evalStringCmp("abc", "AZZ", EvalInstances.LessThan)); + assertTrue(evalStringCmp("ABC", "aaa", EvalInstances.GreaterThan)); + assertTrue(evalStringCmp("abc", "AAA", EvalInstances.GreaterThan)); } private static boolean evalStringCmp(String a, String b, Function cmpOp) { @@ -107,17 +107,17 @@ public final class TestEqualEval extends TestCase { confirmCompares(BoolEval.FALSE, BoolEval.FALSE, 0); } private static void confirmCompares(ValueEval a, ValueEval b, int expRes) { - confirm(a, b, expRes>0, EI.GreaterThan); - confirm(a, b, expRes>=0, EI.GreaterEqual); - confirm(a, b, expRes==0, EI.Equal); - confirm(a, b, expRes<=0, EI.LessEqual); - confirm(a, b, expRes<0, EI.LessThan); + confirm(a, b, expRes>0, EvalInstances.GreaterThan); + confirm(a, b, expRes>=0, EvalInstances.GreaterEqual); + confirm(a, b, expRes==0, EvalInstances.Equal); + confirm(a, b, expRes<=0, EvalInstances.LessEqual); + confirm(a, b, expRes<0, EvalInstances.LessThan); - confirm(b, a, expRes<0, EI.GreaterThan); - confirm(b, a, expRes<=0, EI.GreaterEqual); - confirm(b, a, expRes==0, EI.Equal); - confirm(b, a, expRes>=0, EI.LessEqual); - confirm(b, a, expRes>0, EI.LessThan); + confirm(b, a, expRes<0, EvalInstances.GreaterThan); + confirm(b, a, expRes<=0, EvalInstances.GreaterEqual); + confirm(b, a, expRes==0, EvalInstances.Equal); + confirm(b, a, expRes>=0, EvalInstances.LessEqual); + confirm(b, a, expRes>0, EvalInstances.LessThan); } private static void confirm(ValueEval a, ValueEval b, boolean expectedResult, Function cmpOp) { ValueEval[] args = { a, b, }; @@ -142,7 +142,7 @@ public final class TestEqualEval extends TestCase { throw new AssertionFailedError("Identified bug 47198: unary minus should convert -0.0 to 0.0"); } ValueEval[] args = { zero, mZero, }; - BoolEval result = (BoolEval) evaluate(EI.Equal, args, 0, 0); + BoolEval result = (BoolEval) evaluate(EvalInstances.Equal, args, 0, 0); if (!result.getBooleanValue()) { throw new AssertionFailedError("Identified bug 47198: -0.0 != 0.0"); } @@ -157,7 +157,7 @@ public final class TestEqualEval extends TestCase { assertEquals("1.0055", b.getStringValue()); ValueEval[] args = { a, b, }; - BoolEval result = (BoolEval) evaluate(EI.Equal, args, 0, 0); + BoolEval result = (BoolEval) evaluate(EvalInstances.Equal, args, 0, 0); if (!result.getBooleanValue()) { throw new AssertionFailedError("Identified bug 47598: 1+1.0028-0.9973 != 1.0055"); } diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestFormulaBugs.java b/src/testcases/org/apache/poi/ss/formula/eval/TestFormulaBugs.java index 824c8aba5..31ad51246 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/TestFormulaBugs.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/TestFormulaBugs.java @@ -124,49 +124,54 @@ public final class TestFormulaBugs extends TestCase { /** * Bug 42448 - Can't parse SUMPRODUCT(A!C7:A!C67, B8:B68) / B69

+ * @throws IOException */ - public void test42448() { + public void test42448() throws IOException { HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet sheet1 = wb.createSheet("Sheet1"); - - HSSFRow row = sheet1.createRow(0); - HSSFCell cell = row.createCell(0); - - // it's important to create the referenced sheet first - HSSFSheet sheet2 = wb.createSheet("A"); // note name 'A' - // TODO - POI crashes if the formula is added before this sheet - // RuntimeException("Zero length string is an invalid sheet name") - // Excel doesn't crash but the formula doesn't work until it is - // re-entered - - String inputFormula = "SUMPRODUCT(A!C7:A!C67, B8:B68) / B69"; // as per bug report try { - cell.setCellFormula(inputFormula); - } catch (StringIndexOutOfBoundsException e) { - throw new AssertionFailedError("Identified bug 42448"); + HSSFSheet sheet1 = wb.createSheet("Sheet1"); + + HSSFRow row = sheet1.createRow(0); + HSSFCell cell = row.createCell(0); + + // it's important to create the referenced sheet first + HSSFSheet sheet2 = wb.createSheet("A"); // note name 'A' + // TODO - POI crashes if the formula is added before this sheet + // RuntimeException("Zero length string is an invalid sheet name") + // Excel doesn't crash but the formula doesn't work until it is + // re-entered + + String inputFormula = "SUMPRODUCT(A!C7:A!C67, B8:B68) / B69"; // as per bug report + try { + cell.setCellFormula(inputFormula); + } catch (StringIndexOutOfBoundsException e) { + throw new AssertionFailedError("Identified bug 42448"); + } + + assertEquals("SUMPRODUCT(A!C7:A!C67,B8:B68)/B69", cell.getCellFormula()); + + // might as well evaluate the sucker... + + addCell(sheet2, 5, 2, 3.0); // A!C6 + addCell(sheet2, 6, 2, 4.0); // A!C7 + addCell(sheet2, 66, 2, 5.0); // A!C67 + addCell(sheet2, 67, 2, 6.0); // A!C68 + + addCell(sheet1, 6, 1, 7.0); // B7 + addCell(sheet1, 7, 1, 8.0); // B8 + addCell(sheet1, 67, 1, 9.0); // B68 + addCell(sheet1, 68, 1, 10.0); // B69 + + double expectedResult = (4.0 * 8.0 + 5.0 * 9.0) / 10.0; + + HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); + CellValue cv = fe.evaluate(cell); + + assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType()); + assertEquals(expectedResult, cv.getNumberValue(), 0.0); + } finally { + wb.close(); } - - assertEquals("SUMPRODUCT(A!C7:A!C67,B8:B68)/B69", cell.getCellFormula()); - - // might as well evaluate the sucker... - - addCell(sheet2, 5, 2, 3.0); // A!C6 - addCell(sheet2, 6, 2, 4.0); // A!C7 - addCell(sheet2, 66, 2, 5.0); // A!C67 - addCell(sheet2, 67, 2, 6.0); // A!C68 - - addCell(sheet1, 6, 1, 7.0); // B7 - addCell(sheet1, 7, 1, 8.0); // B8 - addCell(sheet1, 67, 1, 9.0); // B68 - addCell(sheet1, 68, 1, 10.0); // B69 - - double expectedResult = (4.0 * 8.0 + 5.0 * 9.0) / 10.0; - - HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); - CellValue cv = fe.evaluate(cell); - - assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType()); - assertEquals(expectedResult, cv.getNumberValue(), 0.0); } private static void addCell(HSSFSheet sheet, int rowIx, int colIx, diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestMinusZeroResult.java b/src/testcases/org/apache/poi/ss/formula/eval/TestMinusZeroResult.java index 656c47dfd..1ee9b45a8 100644 --- a/src/testcases/org/apache/poi/ss/formula/eval/TestMinusZeroResult.java +++ b/src/testcases/org/apache/poi/ss/formula/eval/TestMinusZeroResult.java @@ -40,24 +40,21 @@ import org.apache.poi.util.HexDump; public final class TestMinusZeroResult extends TestCase { private static final double MINUS_ZERO = -0.0; - // convenient access to namepace - private static final EvalInstances EI = null; - public void testSimpleOperators() { // unary plus is a no-op checkEval(MINUS_ZERO, UnaryPlusEval.instance, MINUS_ZERO); // most simple operators convert -0.0 to +0.0 - checkEval(0.0, EI.UnaryMinus, 0.0); - checkEval(0.0, EI.Percent, MINUS_ZERO); - checkEval(0.0, EI.Multiply, MINUS_ZERO, 1.0); - checkEval(0.0, EI.Divide, MINUS_ZERO, 1.0); - checkEval(0.0, EI.Power, MINUS_ZERO, 1.0); + checkEval(0.0, EvalInstances.UnaryMinus, 0.0); + checkEval(0.0, EvalInstances.Percent, MINUS_ZERO); + checkEval(0.0, EvalInstances.Multiply, MINUS_ZERO, 1.0); + checkEval(0.0, EvalInstances.Divide, MINUS_ZERO, 1.0); + checkEval(0.0, EvalInstances.Power, MINUS_ZERO, 1.0); // but SubtractEval does not convert -0.0, so '-' and '+' work like java - checkEval(MINUS_ZERO, EI.Subtract, MINUS_ZERO, 0.0); // this is the main point of bug 47198 - checkEval(0.0, EI.Add, MINUS_ZERO, 0.0); + checkEval(MINUS_ZERO, EvalInstances.Subtract, MINUS_ZERO, 0.0); // this is the main point of bug 47198 + checkEval(0.0, EvalInstances.Add, MINUS_ZERO, 0.0); } /** @@ -65,9 +62,9 @@ public final class TestMinusZeroResult extends TestCase { * gets to the comparison operator) */ public void testComparisonOperators() { - checkEval(false, EI.Equal, 0.0, MINUS_ZERO); - checkEval(true, EI.GreaterThan, 0.0, MINUS_ZERO); - checkEval(true, EI.LessThan, MINUS_ZERO, 0.0); + checkEval(false, EvalInstances.Equal, 0.0, MINUS_ZERO); + checkEval(true, EvalInstances.GreaterThan, 0.0, MINUS_ZERO); + checkEval(true, EvalInstances.LessThan, MINUS_ZERO, 0.0); } public void testTextRendering() { @@ -81,7 +78,7 @@ public final class TestMinusZeroResult extends TestCase { */ private static void confirmTextRendering(String expRendering, double d) { ValueEval[] args = { StringEval.EMPTY_INSTANCE, new NumberEval(d), }; - StringEval se = (StringEval) EI.Concat.evaluate(args, -1, (short)-1); + StringEval se = (StringEval) EvalInstances.Concat.evaluate(args, -1, (short)-1); String result = se.getStringValue(); assertEquals(expRendering, result); } diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestIndirect.java b/src/testcases/org/apache/poi/ss/formula/functions/TestIndirect.java index 3a35ed942..2c4de2474 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestIndirect.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestIndirect.java @@ -118,31 +118,31 @@ public final class TestIndirect extends TestCase { // simple error propagation: // arg0 is evaluated to text first - confirm(feA, c, "INDIRECT(#DIV/0!)", EE.DIV_ZERO); - confirm(feA, c, "INDIRECT(#DIV/0!)", EE.DIV_ZERO); - confirm(feA, c, "INDIRECT(#NAME?, \"x\")", EE.NAME_INVALID); - confirm(feA, c, "INDIRECT(#NUM!, #N/A)", EE.NUM_ERROR); + confirm(feA, c, "INDIRECT(#DIV/0!)", ErrorEval.DIV_ZERO); + confirm(feA, c, "INDIRECT(#DIV/0!)", ErrorEval.DIV_ZERO); + confirm(feA, c, "INDIRECT(#NAME?, \"x\")", ErrorEval.NAME_INVALID); + confirm(feA, c, "INDIRECT(#NUM!, #N/A)", ErrorEval.NUM_ERROR); // arg1 is evaluated to boolean before arg0 is decoded - confirm(feA, c, "INDIRECT(\"garbage\", #N/A)", EE.NA); - confirm(feA, c, "INDIRECT(\"garbage\", \"\")", EE.VALUE_INVALID); // empty string is not valid boolean - confirm(feA, c, "INDIRECT(\"garbage\", \"flase\")", EE.VALUE_INVALID); // must be "TRUE" or "FALSE" + confirm(feA, c, "INDIRECT(\"garbage\", #N/A)", ErrorEval.NA); + confirm(feA, c, "INDIRECT(\"garbage\", \"\")", ErrorEval.VALUE_INVALID); // empty string is not valid boolean + confirm(feA, c, "INDIRECT(\"garbage\", \"flase\")", ErrorEval.VALUE_INVALID); // must be "TRUE" or "FALSE" // spaces around sheet name (with or without quotes makes no difference) - confirm(feA, c, "INDIRECT(\"'Sheet1 '!D3\")", EE.REF_INVALID); - confirm(feA, c, "INDIRECT(\" Sheet1!D3\")", EE.REF_INVALID); - confirm(feA, c, "INDIRECT(\"'Sheet1' !D3\")", EE.REF_INVALID); + confirm(feA, c, "INDIRECT(\"'Sheet1 '!D3\")", ErrorEval.REF_INVALID); + confirm(feA, c, "INDIRECT(\" Sheet1!D3\")", ErrorEval.REF_INVALID); + confirm(feA, c, "INDIRECT(\"'Sheet1' !D3\")", ErrorEval.REF_INVALID); - confirm(feA, c, "SUM(INDIRECT(\"'John's sales'!A1:C1\"))", EE.REF_INVALID); // bad quote escaping - confirm(feA, c, "INDIRECT(\"[Book1]Sheet1!A1\")", EE.REF_INVALID); // unknown external workbook - confirm(feA, c, "INDIRECT(\"Sheet3!A1\")", EE.REF_INVALID); // unknown sheet + confirm(feA, c, "SUM(INDIRECT(\"'John's sales'!A1:C1\"))", ErrorEval.REF_INVALID); // bad quote escaping + confirm(feA, c, "INDIRECT(\"[Book1]Sheet1!A1\")", ErrorEval.REF_INVALID); // unknown external workbook + confirm(feA, c, "INDIRECT(\"Sheet3!A1\")", ErrorEval.REF_INVALID); // unknown sheet if (false) { // TODO - support evaluation of defined names - confirm(feA, c, "INDIRECT(\"Sheet1!IW1\")", EE.REF_INVALID); // bad column - confirm(feA, c, "INDIRECT(\"Sheet1!A65537\")", EE.REF_INVALID); // bad row + confirm(feA, c, "INDIRECT(\"Sheet1!IW1\")", ErrorEval.REF_INVALID); // bad column + confirm(feA, c, "INDIRECT(\"Sheet1!A65537\")", ErrorEval.REF_INVALID); // bad row } - confirm(feA, c, "INDIRECT(\"Sheet1!A 1\")", EE.REF_INVALID); // space in cell ref + confirm(feA, c, "INDIRECT(\"Sheet1!A 1\")", ErrorEval.REF_INVALID); // space in cell ref } public void testMultipleWorkbooks() { @@ -186,7 +186,7 @@ public final class TestIndirect extends TestCase { } int expCode = expectedResult.getErrorCode(); if (cv.getErrorValue() != expCode) { - throw new AssertionFailedError("Expected error '" + EE.getText(expCode) + throw new AssertionFailedError("Expected error '" + ErrorEval.getText(expCode) + "' but got '" + cv.formatAsString() + "'."); } } diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestRoundFuncs.java b/src/testcases/org/apache/poi/ss/formula/functions/TestRoundFuncs.java index 10166eee0..5d2398d2b 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestRoundFuncs.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestRoundFuncs.java @@ -35,7 +35,7 @@ public final class TestRoundFuncs extends TestCase { ValueEval strArg = new StringEval("abc"); ValueEval[] args = { strArg, new NumberEval(2), }; - ValueEval result = F.ROUNDDOWN.evaluate(args, -1, (short)-1); + ValueEval result = NumericFunction.ROUNDDOWN.evaluate(args, -1, (short)-1); assertEquals(ErrorEval.VALUE_INVALID, result); } @@ -43,7 +43,7 @@ public final class TestRoundFuncs extends TestCase { ValueEval strArg = new StringEval("abc"); ValueEval[] args = { strArg, new NumberEval(2), }; - ValueEval result = F.ROUNDUP.evaluate(args, -1, (short)-1); + ValueEval result = NumericFunction.ROUNDUP.evaluate(args, -1, (short)-1); assertEquals(ErrorEval.VALUE_INVALID, result); } diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestTrunc.java b/src/testcases/org/apache/poi/ss/formula/functions/TestTrunc.java index 55360b96c..91bb8e7d7 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestTrunc.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestTrunc.java @@ -33,7 +33,7 @@ public final class TestTrunc extends AbstractNumericTestCase { ValueEval strArg = new StringEval("abc"); ValueEval[] args = { strArg, new NumberEval(2) }; - ValueEval result = F.TRUNC.evaluate(args, -1, (short)-1); + ValueEval result = NumericFunction.TRUNC.evaluate(args, -1, (short)-1); assertEquals(ErrorEval.VALUE_INVALID, result); } @@ -53,7 +53,7 @@ public final class TestTrunc extends AbstractNumericTestCase { public void testTruncWithDecimalNumberOneArg() { ValueEval[] args = { new NumberEval(2.612777) }; - ValueEval result = F.TRUNC.evaluate(args, -1, (short)-1); + ValueEval result = NumericFunction.TRUNC.evaluate(args, -1, (short)-1); assertEquals("TRUNC", (new NumberEval(2d)).getNumberValue(), ((NumberEval)result).getNumberValue()); } diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java index 14f70295a..a93c330fd 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java @@ -178,7 +178,7 @@ public abstract class BaseTestCell extends TestCase { Font f = wb.createFont(); f.setFontHeightInPoints((short) 20); f.setColor(IndexedColors.RED.getIndex()); - f.setBoldweight(f.BOLDWEIGHT_BOLD); + f.setBoldweight(Font.BOLDWEIGHT_BOLD); f.setFontName("Arial Unicode MS"); cs.setFillBackgroundColor((short)3); cs.setFont(f); @@ -197,7 +197,7 @@ public abstract class BaseTestCell extends TestCase { r = s.getRow(0); c = r.getCell(0); - assertTrue("Formula Cell at 0,0", (c.getCellType()==c.CELL_TYPE_FORMULA)); + assertTrue("Formula Cell at 0,0", (c.getCellType()==Cell.CELL_TYPE_FORMULA)); cs = c.getCellStyle(); assertNotNull("Formula Cell Style", cs); diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataValidation.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataValidation.java index 40893c9dc..e73befca4 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataValidation.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataValidation.java @@ -20,6 +20,9 @@ package org.apache.poi.ss.usermodel; import junit.framework.TestCase; import org.apache.poi.ss.ITestDataProvider; +import org.apache.poi.ss.usermodel.DataValidation.ErrorStyle; +import org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType; +import org.apache.poi.ss.usermodel.DataValidationConstraint.ValidationType; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddressList; import org.apache.poi.util.POILogFactory; @@ -107,29 +110,29 @@ public abstract class BaseTestDataValidation extends TestCase { } private DataValidationConstraint createConstraint(DataValidationHelper dataValidationHelper,int operatorType, String firstFormula, String secondFormula, String[] explicitListValues) { - if (_validationType == VT.LIST) { + if (_validationType == ValidationType.LIST) { if (explicitListValues != null) { return dataValidationHelper.createExplicitListConstraint(explicitListValues); } return dataValidationHelper.createFormulaListConstraint(firstFormula); } - if (_validationType == VT.TIME) { + if (_validationType == ValidationType.TIME) { return dataValidationHelper.createTimeConstraint(operatorType, firstFormula, secondFormula); } - if (_validationType == VT.DATE) { + if (_validationType == ValidationType.DATE) { return dataValidationHelper.createDateConstraint(operatorType, firstFormula, secondFormula, null); } - if (_validationType == VT.FORMULA) { + if (_validationType == ValidationType.FORMULA) { return dataValidationHelper.createCustomConstraint(firstFormula); } - if( _validationType == VT.INTEGER) { + if( _validationType == ValidationType.INTEGER) { return dataValidationHelper.createIntegerConstraint(operatorType, firstFormula, secondFormula); } - if( _validationType == VT.DECIMAL) { + if( _validationType == ValidationType.DECIMAL) { return dataValidationHelper.createDecimalConstraint(operatorType, firstFormula, secondFormula); } - if( _validationType == VT.TEXT_LENGTH) { + if( _validationType == ValidationType.TEXT_LENGTH) { return dataValidationHelper.createTextLengthConstraint(operatorType, firstFormula, secondFormula); } return null; @@ -170,7 +173,7 @@ public abstract class BaseTestDataValidation extends TestCase { boolean allowEmpty, boolean suppressDropDown) { String promptDescr = (allowEmpty ? "empty ok" : "not empty") + ", " + (suppressDropDown ? "no drop-down" : "drop-down"); - addValidationInternal(VT.LIST, listFormula, null, ES.STOP, listValsDescr, promptDescr, + addValidationInternal(ValidationType.LIST, listFormula, null, ErrorStyle.STOP, listValsDescr, promptDescr, allowEmpty, false, true, suppressDropDown, explicitListValues); } } @@ -312,9 +315,9 @@ public abstract class BaseTestDataValidation extends TestCase { wf.createSheet("Custom"); wf.createHeaderRow(); - ValidationAdder va = wf.createValidationAdder(null, VT.FORMULA); - va.addValidation(OP.BETWEEN, "ISNUMBER($A2)", null, ES.STOP, "ISNUMBER(A2)", "Error box type = STOP", true, true, true); - va.addValidation(OP.BETWEEN, "IF(SUM(A2:A3)=5,TRUE,FALSE)", null, ES.WARNING, "IF(SUM(A2:A3)=5,TRUE,FALSE)", "Error box type = WARNING", false, false, true); + ValidationAdder va = wf.createValidationAdder(null, ValidationType.FORMULA); + va.addValidation(OperatorType.BETWEEN, "ISNUMBER($A2)", null, ErrorStyle.STOP, "ISNUMBER(A2)", "Error box type = STOP", true, true, true); + va.addValidation(OperatorType.BETWEEN, "IF(SUM(A2:A3)=5,TRUE,FALSE)", null, ErrorStyle.WARNING, "IF(SUM(A2:A3)=5,TRUE,FALSE)", "Error box type = WARNING", false, false, true); } private static void addSimpleNumericValidations(WorkbookFormatter wf) { @@ -325,29 +328,29 @@ public abstract class BaseTestDataValidation extends TestCase { wf.createDVTypeRow("Whole number"); wf.createHeaderRow(); - ValidationAdder va = wf.createValidationAdder(null, VT.INTEGER); - va.addValidation(OP.BETWEEN, "2", "6", ES.STOP, "Between 2 and 6 ", "Error box type = STOP", true, true, true); - va.addValidation(OP.NOT_BETWEEN, "2", "6", ES.INFO, "Not between 2 and 6 ", "Error box type = INFO", false, true, true); - va.addValidation(OP.EQUAL, "=3+2", null, ES.WARNING, "Equal to (3+2)", "Error box type = WARNING", false, false, true); - va.addValidation(OP.NOT_EQUAL, "3", null, ES.WARNING, "Not equal to 3", "-", false, false, false); - va.addValidation(OP.GREATER_THAN, "3", null, ES.WARNING, "Greater than 3", "-", true, false, false); - va.addValidation(OP.LESS_THAN, "3", null, ES.WARNING, "Less than 3", "-", true, true, false); - va.addValidation(OP.GREATER_OR_EQUAL, "4", null, ES.STOP, "Greater than or equal to 4", "Error box type = STOP", true, false, true); - va.addValidation(OP.LESS_OR_EQUAL, "4", null, ES.STOP, "Less than or equal to 4", "-", false, true, false); + ValidationAdder va = wf.createValidationAdder(null, ValidationType.INTEGER); + va.addValidation(OperatorType.BETWEEN, "2", "6", ErrorStyle.STOP, "Between 2 and 6 ", "Error box type = STOP", true, true, true); + va.addValidation(OperatorType.NOT_BETWEEN, "2", "6", ErrorStyle.INFO, "Not between 2 and 6 ", "Error box type = INFO", false, true, true); + va.addValidation(OperatorType.EQUAL, "=3+2", null, ErrorStyle.WARNING, "Equal to (3+2)", "Error box type = WARNING", false, false, true); + va.addValidation(OperatorType.NOT_EQUAL, "3", null, ErrorStyle.WARNING, "Not equal to 3", "-", false, false, false); + va.addValidation(OperatorType.GREATER_THAN, "3", null, ErrorStyle.WARNING, "Greater than 3", "-", true, false, false); + va.addValidation(OperatorType.LESS_THAN, "3", null, ErrorStyle.WARNING, "Less than 3", "-", true, true, false); + va.addValidation(OperatorType.GREATER_OR_EQUAL, "4", null, ErrorStyle.STOP, "Greater than or equal to 4", "Error box type = STOP", true, false, true); + va.addValidation(OperatorType.LESS_OR_EQUAL, "4", null, ErrorStyle.STOP, "Less than or equal to 4", "-", false, true, false); // "Decimal" validation type wf.createDVTypeRow("Decimal"); wf.createHeaderRow(); - va = wf.createValidationAdder(null, VT.DECIMAL); - va.addValidation(OP.BETWEEN, "2", "6", ES.STOP, "Between 2 and 6 ", "Error box type = STOP", true, true, true); - va.addValidation(OP.NOT_BETWEEN, "2", "6", ES.INFO, "Not between 2 and 6 ", "Error box type = INFO", false, true, true); - va.addValidation(OP.EQUAL, "3", null, ES.WARNING, "Equal to 3", "Error box type = WARNING", false, false, true); - va.addValidation(OP.NOT_EQUAL, "3", null, ES.WARNING, "Not equal to 3", "-", false, false, false); - va.addValidation(OP.GREATER_THAN, "=12/6", null, ES.WARNING, "Greater than (12/6)", "-", true, false, false); - va.addValidation(OP.LESS_THAN, "3", null, ES.WARNING, "Less than 3", "-", true, true, false); - va.addValidation(OP.GREATER_OR_EQUAL, "4", null, ES.STOP, "Greater than or equal to 4", "Error box type = STOP", true, false, true); - va.addValidation(OP.LESS_OR_EQUAL, "4", null, ES.STOP, "Less than or equal to 4", "-", false, true, false); + va = wf.createValidationAdder(null, ValidationType.DECIMAL); + va.addValidation(OperatorType.BETWEEN, "2", "6", ErrorStyle.STOP, "Between 2 and 6 ", "Error box type = STOP", true, true, true); + va.addValidation(OperatorType.NOT_BETWEEN, "2", "6", ErrorStyle.INFO, "Not between 2 and 6 ", "Error box type = INFO", false, true, true); + va.addValidation(OperatorType.EQUAL, "3", null, ErrorStyle.WARNING, "Equal to 3", "Error box type = WARNING", false, false, true); + va.addValidation(OperatorType.NOT_EQUAL, "3", null, ErrorStyle.WARNING, "Not equal to 3", "-", false, false, false); + va.addValidation(OperatorType.GREATER_THAN, "=12/6", null, ErrorStyle.WARNING, "Greater than (12/6)", "-", true, false, false); + va.addValidation(OperatorType.LESS_THAN, "3", null, ErrorStyle.WARNING, "Less than 3", "-", true, true, false); + va.addValidation(OperatorType.GREATER_OR_EQUAL, "4", null, ErrorStyle.STOP, "Greater than or equal to 4", "Error box type = STOP", true, false, true); + va.addValidation(OperatorType.LESS_OR_EQUAL, "4", null, ErrorStyle.STOP, "Less than or equal to 4", "-", false, true, false); } private static void addListValidations(WorkbookFormatter wf, Workbook wb) { @@ -366,7 +369,7 @@ public abstract class BaseTestDataValidation extends TestCase { wf.createDVDescriptionRow("Disadvantage - sum of item's length should be less than 255 characters"); wf.createHeaderRow(); - ValidationAdder va = wf.createValidationAdder(null, VT.LIST); + ValidationAdder va = wf.createValidationAdder(null, ValidationType.LIST); String listValsDescr = "POIFS,HSSF,HWPF,HPSF"; String[] listVals = listValsDescr.split(","); va.addListValidation(listVals, null, listValsDescr, false, false); @@ -379,7 +382,7 @@ public abstract class BaseTestDataValidation extends TestCase { wf.createDVTypeRow("Reference lists - list items are taken from others cells"); wf.createDVDescriptionRow("Advantage - no restriction regarding the sum of item's length"); wf.createHeaderRow(); - va = wf.createValidationAdder(null, VT.LIST); + va = wf.createValidationAdder(null, ValidationType.LIST); String strFormula = "$A$30:$A$39"; va.addListValidation(null, strFormula, strFormula, false, false); @@ -422,44 +425,44 @@ public abstract class BaseTestDataValidation extends TestCase { wf.createDVTypeRow("Date ( cells are already formated as date - m/d/yyyy)"); wf.createHeaderRow(); - ValidationAdder va = wf.createValidationAdder(cellStyle_date, VT.DATE); - va.addValidation(OP.BETWEEN, "2004/01/02", "2004/01/06", ES.STOP, "Between 1/2/2004 and 1/6/2004 ", "Error box type = STOP", true, true, true); - va.addValidation(OP.NOT_BETWEEN, "2004/01/01", "2004/01/06", ES.INFO, "Not between 1/2/2004 and 1/6/2004 ", "Error box type = INFO", false, true, true); - va.addValidation(OP.EQUAL, "2004/03/02", null, ES.WARNING, "Equal to 3/2/2004", "Error box type = WARNING", false, false, true); - va.addValidation(OP.NOT_EQUAL, "2004/03/02", null, ES.WARNING, "Not equal to 3/2/2004", "-", false, false, false); - va.addValidation(OP.GREATER_THAN,"=DATEVALUE(\"4-Jul-2001\")", null, ES.WARNING, "Greater than DATEVALUE('4-Jul-2001')", "-", true, false, false); - va.addValidation(OP.LESS_THAN, "2004/03/02", null, ES.WARNING, "Less than 3/2/2004", "-", true, true, false); - va.addValidation(OP.GREATER_OR_EQUAL, "2004/03/02", null, ES.STOP, "Greater than or equal to 3/2/2004", "Error box type = STOP", true, false, true); - va.addValidation(OP.LESS_OR_EQUAL, "2004/03/04", null, ES.STOP, "Less than or equal to 3/4/2004", "-", false, true, false); + ValidationAdder va = wf.createValidationAdder(cellStyle_date, ValidationType.DATE); + va.addValidation(OperatorType.BETWEEN, "2004/01/02", "2004/01/06", ErrorStyle.STOP, "Between 1/2/2004 and 1/6/2004 ", "Error box type = STOP", true, true, true); + va.addValidation(OperatorType.NOT_BETWEEN, "2004/01/01", "2004/01/06", ErrorStyle.INFO, "Not between 1/2/2004 and 1/6/2004 ", "Error box type = INFO", false, true, true); + va.addValidation(OperatorType.EQUAL, "2004/03/02", null, ErrorStyle.WARNING, "Equal to 3/2/2004", "Error box type = WARNING", false, false, true); + va.addValidation(OperatorType.NOT_EQUAL, "2004/03/02", null, ErrorStyle.WARNING, "Not equal to 3/2/2004", "-", false, false, false); + va.addValidation(OperatorType.GREATER_THAN,"=DATEVALUE(\"4-Jul-2001\")", null, ErrorStyle.WARNING, "Greater than DATEVALUE('4-Jul-2001')", "-", true, false, false); + va.addValidation(OperatorType.LESS_THAN, "2004/03/02", null, ErrorStyle.WARNING, "Less than 3/2/2004", "-", true, true, false); + va.addValidation(OperatorType.GREATER_OR_EQUAL, "2004/03/02", null, ErrorStyle.STOP, "Greater than or equal to 3/2/2004", "Error box type = STOP", true, false, true); + va.addValidation(OperatorType.LESS_OR_EQUAL, "2004/03/04", null, ErrorStyle.STOP, "Less than or equal to 3/4/2004", "-", false, true, false); // "Time" validation type wf.createDVTypeRow("Time ( cells are already formated as time - h:mm)"); wf.createHeaderRow(); - va = wf.createValidationAdder(cellStyle_time, VT.TIME); - va.addValidation(OP.BETWEEN, "12:00", "16:00", ES.STOP, "Between 12:00 and 16:00 ", "Error box type = STOP", true, true, true); - va.addValidation(OP.NOT_BETWEEN, "12:00", "16:00", ES.INFO, "Not between 12:00 and 16:00 ", "Error box type = INFO", false, true, true); - va.addValidation(OP.EQUAL, "13:35", null, ES.WARNING, "Equal to 13:35", "Error box type = WARNING", false, false, true); - va.addValidation(OP.NOT_EQUAL, "13:35", null, ES.WARNING, "Not equal to 13:35", "-", false, false, false); - va.addValidation(OP.GREATER_THAN,"12:00", null, ES.WARNING, "Greater than 12:00", "-", true, false, false); - va.addValidation(OP.LESS_THAN, "=1/2", null, ES.WARNING, "Less than (1/2) -> 12:00", "-", true, true, false); - va.addValidation(OP.GREATER_OR_EQUAL, "14:00", null, ES.STOP, "Greater than or equal to 14:00", "Error box type = STOP", true, false, true); - va.addValidation(OP.LESS_OR_EQUAL,"14:00", null, ES.STOP, "Less than or equal to 14:00", "-", false, true, false); + va = wf.createValidationAdder(cellStyle_time, ValidationType.TIME); + va.addValidation(OperatorType.BETWEEN, "12:00", "16:00", ErrorStyle.STOP, "Between 12:00 and 16:00 ", "Error box type = STOP", true, true, true); + va.addValidation(OperatorType.NOT_BETWEEN, "12:00", "16:00", ErrorStyle.INFO, "Not between 12:00 and 16:00 ", "Error box type = INFO", false, true, true); + va.addValidation(OperatorType.EQUAL, "13:35", null, ErrorStyle.WARNING, "Equal to 13:35", "Error box type = WARNING", false, false, true); + va.addValidation(OperatorType.NOT_EQUAL, "13:35", null, ErrorStyle.WARNING, "Not equal to 13:35", "-", false, false, false); + va.addValidation(OperatorType.GREATER_THAN,"12:00", null, ErrorStyle.WARNING, "Greater than 12:00", "-", true, false, false); + va.addValidation(OperatorType.LESS_THAN, "=1/2", null, ErrorStyle.WARNING, "Less than (1/2) -> 12:00", "-", true, true, false); + va.addValidation(OperatorType.GREATER_OR_EQUAL, "14:00", null, ErrorStyle.STOP, "Greater than or equal to 14:00", "Error box type = STOP", true, false, true); + va.addValidation(OperatorType.LESS_OR_EQUAL,"14:00", null, ErrorStyle.STOP, "Less than or equal to 14:00", "-", false, true, false); } private static void addTextLengthValidations(WorkbookFormatter wf) { wf.createSheet("Text lengths"); wf.createHeaderRow(); - ValidationAdder va = wf.createValidationAdder(null, VT.TEXT_LENGTH); - va.addValidation(OP.BETWEEN, "2", "6", ES.STOP, "Between 2 and 6 ", "Error box type = STOP", true, true, true); - va.addValidation(OP.NOT_BETWEEN, "2", "6", ES.INFO, "Not between 2 and 6 ", "Error box type = INFO", false, true, true); - va.addValidation(OP.EQUAL, "3", null, ES.WARNING, "Equal to 3", "Error box type = WARNING", false, false, true); - va.addValidation(OP.NOT_EQUAL, "3", null, ES.WARNING, "Not equal to 3", "-", false, false, false); - va.addValidation(OP.GREATER_THAN, "3", null, ES.WARNING, "Greater than 3", "-", true, false, false); - va.addValidation(OP.LESS_THAN, "3", null, ES.WARNING, "Less than 3", "-", true, true, false); - va.addValidation(OP.GREATER_OR_EQUAL, "4", null, ES.STOP, "Greater than or equal to 4", "Error box type = STOP", true, false, true); - va.addValidation(OP.LESS_OR_EQUAL, "4", null, ES.STOP, "Less than or equal to 4", "-", false, true, false); + ValidationAdder va = wf.createValidationAdder(null, ValidationType.TEXT_LENGTH); + va.addValidation(OperatorType.BETWEEN, "2", "6", ErrorStyle.STOP, "Between 2 and 6 ", "Error box type = STOP", true, true, true); + va.addValidation(OperatorType.NOT_BETWEEN, "2", "6", ErrorStyle.INFO, "Not between 2 and 6 ", "Error box type = INFO", false, true, true); + va.addValidation(OperatorType.EQUAL, "3", null, ErrorStyle.WARNING, "Equal to 3", "Error box type = WARNING", false, false, true); + va.addValidation(OperatorType.NOT_EQUAL, "3", null, ErrorStyle.WARNING, "Not equal to 3", "-", false, false, false); + va.addValidation(OperatorType.GREATER_THAN, "3", null, ErrorStyle.WARNING, "Greater than 3", "-", true, false, false); + va.addValidation(OperatorType.LESS_THAN, "3", null, ErrorStyle.WARNING, "Less than 3", "-", true, true, false); + va.addValidation(OperatorType.GREATER_OR_EQUAL, "4", null, ErrorStyle.STOP, "Greater than or equal to 4", "Error box type = STOP", true, false, true); + va.addValidation(OperatorType.LESS_OR_EQUAL, "4", null, ErrorStyle.STOP, "Less than or equal to 4", "-", false, true, false); } public void testDataValidation() { diff --git a/src/testcases/org/apache/poi/util/DummyPOILogger.java b/src/testcases/org/apache/poi/util/DummyPOILogger.java index f72e37b51..976c7d918 100644 --- a/src/testcases/org/apache/poi/util/DummyPOILogger.java +++ b/src/testcases/org/apache/poi/util/DummyPOILogger.java @@ -24,10 +24,10 @@ import java.util.List; * tests can see what got logged */ public class DummyPOILogger extends POILogger { - public List logged = new ArrayList(); + public Listlogged = new ArrayList(); public void reset() { - logged = new ArrayList(); + logged = new ArrayList(); } public boolean check(int level) {