Fix Eclipse warnings, unnecessary casts, use generics, static access...

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1648156 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2014-12-28 09:06:12 +00:00
parent 54fd49b39f
commit 5173eca9ea
44 changed files with 377 additions and 316 deletions

View File

@ -19,6 +19,8 @@ package org.apache.poi.hssf.usermodel.examples;
import org.apache.poi.hssf.usermodel.*; import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor; 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.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -57,14 +59,14 @@ public class BigExample {
f.setColor(HSSFColor.RED.index); f.setColor(HSSFColor.RED.index);
// make it bold // make it bold
//arial is the default font //arial is the default font
f.setBoldweight(f.BOLDWEIGHT_BOLD); f.setBoldweight(Font.BOLDWEIGHT_BOLD);
//set font 2 to 10 point type //set font 2 to 10 point type
f2.setFontHeightInPoints((short) 10); f2.setFontHeightInPoints((short) 10);
//make it the color at palette index 0xf (white) //make it the color at palette index 0xf (white)
f2.setColor(HSSFColor.WHITE.index); f2.setColor(HSSFColor.WHITE.index);
//make it bold //make it bold
f2.setBoldweight(f2.BOLDWEIGHT_BOLD); f2.setBoldweight(Font.BOLDWEIGHT_BOLD);
//set cell stlye //set cell stlye
cs.setFont(f); cs.setFont(f);
@ -72,7 +74,7 @@ public class BigExample {
cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0)")); cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0)"));
//set a thin border //set a thin border
cs2.setBorderBottom(cs2.BORDER_THIN); cs2.setBorderBottom(CellStyle.BORDER_THIN);
//fill w fg fill color //fill w fg fill color
cs2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); cs2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
// set foreground fill to red // set foreground fill to red
@ -141,7 +143,7 @@ public class BigExample {
// define the third style to be the default // define the third style to be the default
// except with a thick black border at the bottom // except with a thick black border at the bottom
cs3.setBorderBottom(cs3.BORDER_THICK); cs3.setBorderBottom(CellStyle.BORDER_THICK);
//create 50 cells //create 50 cells
for (int cellnum =0; cellnum < 50; cellnum++) { for (int cellnum =0; cellnum < 50; cellnum++) {

View File

@ -47,11 +47,11 @@ public class EventExample
// the BOFRecord can represent either the beginning of a sheet or the workbook // the BOFRecord can represent either the beginning of a sheet or the workbook
case BOFRecord.sid: case BOFRecord.sid:
BOFRecord bof = (BOFRecord) record; BOFRecord bof = (BOFRecord) record;
if (bof.getType() == bof.TYPE_WORKBOOK) if (bof.getType() == BOFRecord.TYPE_WORKBOOK)
{ {
System.out.println("Encountered workbook"); System.out.println("Encountered workbook");
// assigned to the class level member // 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"); System.out.println("Encountered sheet reference");
} }

View File

@ -164,7 +164,7 @@ public class OfficeDrawing {
HSSFPicture picture = patriarch.createPicture(anchor, loadPicture( "src/resources/logos/logoKarmokar4s.png", wb )); HSSFPicture picture = patriarch.createPicture(anchor, loadPicture( "src/resources/logos/logoKarmokar4s.png", wb ));
//Reset the image to the original size. //Reset the image to the original size.
picture.resize(); picture.resize();
picture.setLineStyle( picture.LINESTYLE_DASHDOTGEL ); picture.setLineStyle( HSSFShape.LINESTYLE_DASHDOTGEL );
} }

View File

@ -40,7 +40,7 @@ public class EscherChildAnchorRecord
private int field_4_dy2; private int field_4_dy2;
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) { public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
int bytesRemaining = readHeader( data, offset ); /*int bytesRemaining =*/ readHeader( data, offset );
int pos = offset + 8; int pos = offset + 8;
int size = 0; int size = 0;
field_1_dx1 = LittleEndian.getInt( data, pos + size );size+=4; field_1_dx1 = LittleEndian.getInt( data, pos + size );size+=4;

View File

@ -37,7 +37,7 @@ public class EscherDgRecord
private int field_2_lastMSOSPID; private int field_2_lastMSOSPID;
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) { public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
int bytesRemaining = readHeader( data, offset ); /*int bytesRemaining =*/ readHeader( data, offset );
int pos = offset + 8; int pos = offset + 8;
int size = 0; int size = 0;
field_1_numShapes = LittleEndian.getInt( data, pos + size ); size += 4; field_1_numShapes = LittleEndian.getInt( data, pos + size ); size += 4;

View File

@ -49,7 +49,7 @@ public class EscherSpRecord
private int field_2_flags; private int field_2_flags;
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) { public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
int bytesRemaining = readHeader( data, offset ); /*int bytesRemaining =*/ readHeader( data, offset );
int pos = offset + 8; int pos = offset + 8;
int size = 0; int size = 0;
field_1_shapeId = LittleEndian.getInt( data, pos + size ); size += 4; field_1_shapeId = LittleEndian.getInt( data, pos + size ); size += 4;

View File

@ -131,7 +131,7 @@ public class CustomProperties extends HashMap<Object,CustomProperty>
final String name = customProperty.getName(); final String name = customProperty.getName();
/* Check whether a property with this name is in the map already. */ /* 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) if (oldId != null)
customProperty.setID(oldId.longValue()); customProperty.setID(oldId.longValue());
else else
@ -159,7 +159,7 @@ public class CustomProperties extends HashMap<Object,CustomProperty>
*/ */
public Object remove(final String name) public Object remove(final String name)
{ {
final Long id = (Long) dictionaryNameToID.get(name); final Long id = dictionaryNameToID.get(name);
if (id == null) if (id == null)
return null; return null;
dictionaryIDToName.remove(id); dictionaryIDToName.remove(id);
@ -267,8 +267,8 @@ public class CustomProperties extends HashMap<Object,CustomProperty>
*/ */
public Object get(final String name) public Object get(final String name)
{ {
final Long id = (Long) dictionaryNameToID.get(name); final Long id = dictionaryNameToID.get(name);
final CustomProperty cp = (CustomProperty) super.get(id); final CustomProperty cp = super.get(id);
return cp != null ? cp.getValue() : null; return cp != null ? cp.getValue() : null;
} }
@ -351,10 +351,10 @@ public class CustomProperties extends HashMap<Object,CustomProperty>
*/ */
public boolean containsKey(Object key) { public boolean containsKey(Object key) {
if(key instanceof Long) { if(key instanceof Long) {
return super.containsKey((Long)key); return super.containsKey(key);
} }
if(key instanceof String) { if(key instanceof String) {
return super.containsKey((Long)dictionaryNameToID.get(key)); return super.containsKey(dictionaryNameToID.get(key));
} }
return false; return false;
} }
@ -364,7 +364,7 @@ public class CustomProperties extends HashMap<Object,CustomProperty>
*/ */
public boolean containsValue(Object value) { public boolean containsValue(Object value) {
if(value instanceof CustomProperty) { if(value instanceof CustomProperty) {
return super.containsValue((CustomProperty)value); return super.containsValue(value);
} else { } else {
for(CustomProperty cp : super.values()) { for(CustomProperty cp : super.values()) {
if(cp.getValue() == value) { if(cp.getValue() == value) {

View File

@ -569,7 +569,7 @@ public class DocumentSummaryInformation extends SpecialPropertySet
if (getSectionCount() >= 2) if (getSectionCount() >= 2)
{ {
cps = new CustomProperties(); cps = new CustomProperties();
final Section section = (Section) getSections().get(1); final Section section = getSections().get(1);
final Map<Long,String> dictionary = section.getDictionary(); final Map<Long,String> dictionary = section.getDictionary();
final Property[] properties = section.getProperties(); final Property[] properties = section.getProperties();
int propertyCount = 0; int propertyCount = 0;

View File

@ -576,7 +576,7 @@ public class MutableSection extends Section
*/ */
public Property[] getProperties() public Property[] getProperties()
{ {
properties = (Property[]) preprops.toArray(new Property[0]); properties = preprops.toArray(new Property[0]);
return properties; return properties;
} }

View File

@ -448,7 +448,7 @@ public class Section
{ {
String s = null; String s = null;
if (dictionary != null) if (dictionary != null)
s = (String) dictionary.get(Long.valueOf(pid)); s = dictionary.get(Long.valueOf(pid));
if (s == null) if (s == null)
s = SectionIDMap.getPIDString(getFormatID().getBytes(), pid); s = SectionIDMap.getPIDString(getFormatID().getBytes(), pid);
if (s == null) if (s == null)

View File

@ -352,9 +352,9 @@ public class Variant
* <p>Maps the numbers denoting the variant types to their corresponding * <p>Maps the numbers denoting the variant types to their corresponding
* variant type names.</p> * variant type names.</p>
*/ */
private static Map numberToName; private static Map<Long,String> numberToName;
private static Map numberToLength; private static Map<Long,Integer> numberToLength;
/** /**
* <p>Denotes a variant type with a length that is unknown to HPSF yet.</p> * <p>Denotes a variant type with a length that is unknown to HPSF yet.</p>
@ -391,7 +391,7 @@ public class Variant
static static
{ {
/* Initialize the number-to-name map: */ /* Initialize the number-to-name map: */
Map tm1 = new HashMap(); Map<Long,String> tm1 = new HashMap<Long,String>();
tm1.put(Long.valueOf(0), "VT_EMPTY"); tm1.put(Long.valueOf(0), "VT_EMPTY");
tm1.put(Long.valueOf(1), "VT_NULL"); tm1.put(Long.valueOf(1), "VT_NULL");
tm1.put(Long.valueOf(2), "VT_I2"); 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(70), "VT_BLOB_OBJECT");
tm1.put(Long.valueOf(71), "VT_CF"); tm1.put(Long.valueOf(71), "VT_CF");
tm1.put(Long.valueOf(72), "VT_CLSID"); tm1.put(Long.valueOf(72), "VT_CLSID");
Map tm2 = new HashMap(tm1.size(), 1.0F); Map<Long,String> tm2 = new HashMap<Long,String>(tm1.size(), 1.0F);
tm2.putAll(tm1); tm2.putAll(tm1);
numberToName = Collections.unmodifiableMap(tm2); numberToName = Collections.unmodifiableMap(tm2);
/* Initialize the number-to-length map: */ /* Initialize the number-to-length map: */
tm1.clear(); Map<Long,Integer> tm3 = new HashMap<Long,Integer>();
tm1.put(Long.valueOf(0), LENGTH_0); tm3.put(Long.valueOf(0), LENGTH_0);
tm1.put(Long.valueOf(1), LENGTH_UNKNOWN); tm3.put(Long.valueOf(1), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(2), LENGTH_2); tm3.put(Long.valueOf(2), LENGTH_2);
tm1.put(Long.valueOf(3), LENGTH_4); tm3.put(Long.valueOf(3), LENGTH_4);
tm1.put(Long.valueOf(4), LENGTH_4); tm3.put(Long.valueOf(4), LENGTH_4);
tm1.put(Long.valueOf(5), LENGTH_8); tm3.put(Long.valueOf(5), LENGTH_8);
tm1.put(Long.valueOf(6), LENGTH_UNKNOWN); tm3.put(Long.valueOf(6), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(7), LENGTH_UNKNOWN); tm3.put(Long.valueOf(7), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(8), LENGTH_UNKNOWN); tm3.put(Long.valueOf(8), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(9), LENGTH_UNKNOWN); tm3.put(Long.valueOf(9), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(10), LENGTH_UNKNOWN); tm3.put(Long.valueOf(10), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(11), LENGTH_UNKNOWN); tm3.put(Long.valueOf(11), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(12), LENGTH_UNKNOWN); tm3.put(Long.valueOf(12), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(13), LENGTH_UNKNOWN); tm3.put(Long.valueOf(13), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(14), LENGTH_UNKNOWN); tm3.put(Long.valueOf(14), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(16), LENGTH_UNKNOWN); tm3.put(Long.valueOf(16), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(17), LENGTH_UNKNOWN); tm3.put(Long.valueOf(17), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(18), LENGTH_UNKNOWN); tm3.put(Long.valueOf(18), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(19), LENGTH_UNKNOWN); tm3.put(Long.valueOf(19), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(20), LENGTH_UNKNOWN); tm3.put(Long.valueOf(20), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(21), LENGTH_UNKNOWN); tm3.put(Long.valueOf(21), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(22), LENGTH_UNKNOWN); tm3.put(Long.valueOf(22), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(23), LENGTH_UNKNOWN); tm3.put(Long.valueOf(23), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(24), LENGTH_UNKNOWN); tm3.put(Long.valueOf(24), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(25), LENGTH_UNKNOWN); tm3.put(Long.valueOf(25), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(26), LENGTH_UNKNOWN); tm3.put(Long.valueOf(26), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(27), LENGTH_UNKNOWN); tm3.put(Long.valueOf(27), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(28), LENGTH_UNKNOWN); tm3.put(Long.valueOf(28), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(29), LENGTH_UNKNOWN); tm3.put(Long.valueOf(29), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(30), LENGTH_VARIABLE); tm3.put(Long.valueOf(30), LENGTH_VARIABLE);
tm1.put(Long.valueOf(31), LENGTH_UNKNOWN); tm3.put(Long.valueOf(31), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(64), LENGTH_8); tm3.put(Long.valueOf(64), LENGTH_8);
tm1.put(Long.valueOf(65), LENGTH_UNKNOWN); tm3.put(Long.valueOf(65), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(66), LENGTH_UNKNOWN); tm3.put(Long.valueOf(66), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(67), LENGTH_UNKNOWN); tm3.put(Long.valueOf(67), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(68), LENGTH_UNKNOWN); tm3.put(Long.valueOf(68), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(69), LENGTH_UNKNOWN); tm3.put(Long.valueOf(69), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(70), LENGTH_UNKNOWN); tm3.put(Long.valueOf(70), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(71), LENGTH_UNKNOWN); tm3.put(Long.valueOf(71), LENGTH_UNKNOWN);
tm1.put(Long.valueOf(72), LENGTH_UNKNOWN); tm3.put(Long.valueOf(72), LENGTH_UNKNOWN);
tm2 = new HashMap(tm1.size(), 1.0F); Map<Long,Integer> tm4 = new HashMap<Long,Integer>(tm1.size(), 1.0F);
tm2.putAll(tm1); tm4.putAll(tm3);
numberToLength = Collections.unmodifiableMap(tm2); numberToLength = Collections.unmodifiableMap(tm4);
} }
@ -494,7 +494,7 @@ public class Variant
*/ */
public static String getVariantName(final long variantType) 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"; return name != null ? name : "unknown variant type";
} }
@ -510,7 +510,7 @@ public class Variant
public static int getVariantLength(final long variantType) public static int getVariantLength(final long variantType)
{ {
final Long key = Long.valueOf((int) variantType); final Long key = Long.valueOf((int) variantType);
final Long length = (Long) numberToLength.get(key); final Integer length = numberToLength.get(key);
if (length == null) if (length == null)
return -2; return -2;
return length.intValue(); return length.intValue();

View File

@ -17,6 +17,7 @@
package org.apache.poi.hpsf.extractor; package org.apache.poi.hpsf.extractor;
import java.io.Closeable;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
@ -39,6 +40,8 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
* textual form. * textual form.
*/ */
public class HPSFPropertiesExtractor extends POITextExtractor { public class HPSFPropertiesExtractor extends POITextExtractor {
private Closeable toClose;
public HPSFPropertiesExtractor(POITextExtractor mainExtractor) { public HPSFPropertiesExtractor(POITextExtractor mainExtractor) {
super(mainExtractor); super(mainExtractor);
} }
@ -50,6 +53,7 @@ public class HPSFPropertiesExtractor extends POITextExtractor {
} }
public HPSFPropertiesExtractor(NPOIFSFileSystem fs) { public HPSFPropertiesExtractor(NPOIFSFileSystem fs) {
super(new HPSFPropertiesOnlyDocument(fs)); super(new HPSFPropertiesOnlyDocument(fs));
this.toClose = fs;
} }
public String getDocumentSummaryInformationText() { public String getDocumentSummaryInformationText() {
@ -119,6 +123,19 @@ public class HPSFPropertiesExtractor extends POITextExtractor {
throw new IllegalStateException("You already have the Metadata Text Extractor, not recursing!"); 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 { private static abstract class HelperPropertySet extends SpecialPropertySet {
public HelperPropertySet() { public HelperPropertySet() {
super(null); super(null);
@ -135,7 +152,11 @@ public class HPSFPropertiesExtractor extends POITextExtractor {
for (String file : args) { for (String file : args) {
HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor( HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(
new NPOIFSFileSystem(new File(file))); new NPOIFSFileSystem(new File(file)));
System.out.println(ext.getText()); try {
System.out.println(ext.getText());
} finally {
ext.close();
}
} }
} }
} }

View File

@ -34,7 +34,7 @@ import java.util.Map;
* @author Rainer Klute <a * @author Rainer Klute <a
* href="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a> * href="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a>
*/ */
public class PropertyIDMap extends HashMap { public class PropertyIDMap extends HashMap<Long,String> {
/* /*
* The following definitions are for property IDs in the first * 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. * @param map The instance to be created is backed by this map.
*/ */
public PropertyIDMap(final Map map) public PropertyIDMap(final Map<Long,String> map)
{ {
super(map); super(map);
} }

View File

@ -17,13 +17,12 @@
package org.apache.poi.hssf.dev; 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.FileInputStream;
import java.io.FileOutputStream; 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 * Utility to test that POI produces readable output
* after re-saving xls files. * after re-saving xls files.
@ -40,22 +39,28 @@ public class ReSave {
System.out.print("reading " + arg + "..."); System.out.print("reading " + arg + "...");
FileInputStream is = new FileInputStream(arg); FileInputStream is = new FileInputStream(arg);
HSSFWorkbook wb = new HSSFWorkbook(is); HSSFWorkbook wb = new HSSFWorkbook(is);
is.close(); try {
System.out.println("done"); System.out.println("done");
for(int i = 0; i < wb.getNumberOfSheets(); i++){ for(int i = 0; i < wb.getNumberOfSheets(); i++){
HSSFSheet sheet = wb.getSheetAt(i); HSSFSheet sheet = wb.getSheetAt(i);
if(initDrawing) { if(initDrawing) {
HSSFPatriarch dg = sheet.getDrawingPatriarch(); /*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");
} }
} }
} }

View File

@ -30,7 +30,7 @@ import java.util.ArrayList;
public class DrawingManager2 public class DrawingManager2
{ {
EscherDggRecord dgg; EscherDggRecord dgg;
List drawingGroups = new ArrayList( ); List<EscherDgRecord> drawingGroups = new ArrayList<EscherDgRecord>();
public DrawingManager2( EscherDggRecord dgg ) public DrawingManager2( EscherDggRecord dgg )
@ -120,7 +120,7 @@ public class DrawingManager2
EscherDgRecord getDrawingGroup(int drawingGroupId) EscherDgRecord getDrawingGroup(int drawingGroupId)
{ {
return (EscherDgRecord) drawingGroups.get(drawingGroupId-1); return drawingGroups.get(drawingGroupId-1);
} }
boolean drawingGroupExists( short dgId ) boolean drawingGroupExists( short dgId )

View File

@ -53,7 +53,7 @@ public final class RecordStream {
throw new RuntimeException("Attempt to read past end of record stream"); throw new RuntimeException("Attempt to read past end of record stream");
} }
_countRead ++; _countRead ++;
return (Record) _list.get(_nextIndex++); return _list.get(_nextIndex++);
} }
/** /**
@ -73,7 +73,7 @@ public final class RecordStream {
if(!hasNext()) { if(!hasNext()) {
return -1; return -1;
} }
return ((Record)_list.get(_nextIndex)).getSid(); return _list.get(_nextIndex).getSid();
} }
public int getCountRead() { public int getCountRead() {

View File

@ -212,7 +212,7 @@ public final class TextObjectRecord extends ContinuableRecord {
for (int i = 0; i < nRuns; i++) { for (int i = 0; i < nRuns; i++) {
out.writeShort(str.getIndexOfFormattingRun(i)); out.writeShort(str.getIndexOfFormattingRun(i));
int fontIndex = str.getFontOfFormattingRun(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.writeInt(0); // skip reserved
} }
out.writeShort(str.length()); out.writeShort(str.length());

View File

@ -32,16 +32,16 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate {
/** /**
* List of {@link ColumnInfoRecord}s assumed to be in order * List of {@link ColumnInfoRecord}s assumed to be in order
*/ */
private final List records; private final List<ColumnInfoRecord> records;
private static final class CIRComparator implements Comparator { private static final class CIRComparator implements Comparator<ColumnInfoRecord> {
public static final Comparator instance = new CIRComparator(); public static final Comparator<ColumnInfoRecord> instance = new CIRComparator();
private CIRComparator() { private CIRComparator() {
// enforce singleton // enforce singleton
} }
public int compare(Object a, Object b) { public int compare(ColumnInfoRecord a, ColumnInfoRecord b) {
return compareColInfos((ColumnInfoRecord)a, (ColumnInfoRecord)b); return compareColInfos(a, b);
} }
public static int compareColInfos(ColumnInfoRecord a, ColumnInfoRecord b) { public static int compareColInfos(ColumnInfoRecord a, ColumnInfoRecord b) {
return a.getFirstColumn()-b.getFirstColumn(); return a.getFirstColumn()-b.getFirstColumn();
@ -52,7 +52,7 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate {
* Creates an empty aggregate * Creates an empty aggregate
*/ */
public ColumnInfoRecordsAggregate() { public ColumnInfoRecordsAggregate() {
records = new ArrayList(); records = new ArrayList<ColumnInfoRecord>();
} }
public ColumnInfoRecordsAggregate(RecordStream rs) { public ColumnInfoRecordsAggregate(RecordStream rs) {
this(); this();
@ -81,8 +81,8 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate {
public Object clone() { public Object clone() {
ColumnInfoRecordsAggregate rec = new ColumnInfoRecordsAggregate(); ColumnInfoRecordsAggregate rec = new ColumnInfoRecordsAggregate();
for (int k = 0; k < records.size(); k++) { for (int k = 0; k < records.size(); k++) {
ColumnInfoRecord ci = ( ColumnInfoRecord ) records.get(k); ColumnInfoRecord ci = records.get(k);
rec.records.add(ci.clone()); rec.records.add((ColumnInfoRecord) ci.clone());
} }
return rec; return rec;
} }
@ -114,7 +114,7 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate {
} }
ColumnInfoRecord cirPrev = null; ColumnInfoRecord cirPrev = null;
for(int i=0; i<nItems; i++) { for(int i=0; i<nItems; i++) {
ColumnInfoRecord cir = (ColumnInfoRecord)records.get(i); ColumnInfoRecord cir = records.get(i);
rv.visitRecord(cir); rv.visitRecord(cir);
if (cirPrev != null && CIRComparator.compareColInfos(cirPrev, cir) > 0) { if (cirPrev != null && CIRComparator.compareColInfos(cirPrev, cir) > 0) {
// Excel probably wouldn't mind, but there is much logic in this class // 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) { private int findStartOfColumnOutlineGroup(int pIdx) {
// Find the start of the group. // Find the start of the group.
ColumnInfoRecord columnInfo = (ColumnInfoRecord) records.get(pIdx); ColumnInfoRecord columnInfo = records.get(pIdx);
int level = columnInfo.getOutlineLevel(); int level = columnInfo.getOutlineLevel();
int idx = pIdx; int idx = pIdx;
while (idx != 0) { while (idx != 0) {
ColumnInfoRecord prevColumnInfo = (ColumnInfoRecord) records.get(idx - 1); ColumnInfoRecord prevColumnInfo = records.get(idx - 1);
if (!prevColumnInfo.isAdjacentBefore(columnInfo)) { if (!prevColumnInfo.isAdjacentBefore(columnInfo)) {
break; break;
} }
@ -147,11 +147,11 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate {
private int findEndOfColumnOutlineGroup(int colInfoIndex) { private int findEndOfColumnOutlineGroup(int colInfoIndex) {
// Find the end of the group. // Find the end of the group.
ColumnInfoRecord columnInfo = (ColumnInfoRecord) records.get(colInfoIndex); ColumnInfoRecord columnInfo = records.get(colInfoIndex);
int level = columnInfo.getOutlineLevel(); int level = columnInfo.getOutlineLevel();
int idx = colInfoIndex; int idx = colInfoIndex;
while (idx < records.size() - 1) { while (idx < records.size() - 1) {
ColumnInfoRecord nextColumnInfo = (ColumnInfoRecord) records.get(idx + 1); ColumnInfoRecord nextColumnInfo = records.get(idx + 1);
if (!columnInfo.isAdjacentBefore(nextColumnInfo)) { if (!columnInfo.isAdjacentBefore(nextColumnInfo)) {
break; break;
} }
@ -165,7 +165,7 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate {
} }
private ColumnInfoRecord getColInfo(int idx) { 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; int k = 0;
for (k = 0; k < records.size(); k++) { for (k = 0; k < records.size(); k++) {
ColumnInfoRecord tci = (ColumnInfoRecord) records.get(k); ColumnInfoRecord tci = records.get(k);
if (tci.containsColumn(targetColumnIx)) { if (tci.containsColumn(targetColumnIx)) {
ci = tci; ci = tci;
break; break;

View File

@ -33,18 +33,18 @@ import org.apache.poi.ss.formula.FormulaShifter;
*/ */
public final class ConditionalFormattingTable extends RecordAggregate { public final class ConditionalFormattingTable extends RecordAggregate {
private final List _cfHeaders; private final List<CFRecordsAggregate> _cfHeaders;
/** /**
* Creates an empty ConditionalFormattingTable * Creates an empty ConditionalFormattingTable
*/ */
public ConditionalFormattingTable() { public ConditionalFormattingTable() {
_cfHeaders = new ArrayList(); _cfHeaders = new ArrayList<CFRecordsAggregate>();
} }
public ConditionalFormattingTable(RecordStream rs) { public ConditionalFormattingTable(RecordStream rs) {
List temp = new ArrayList(); List<CFRecordsAggregate> temp = new ArrayList<CFRecordsAggregate>();
while (rs.peekNextClass() == CFHeaderRecord.class) { while (rs.peekNextClass() == CFHeaderRecord.class) {
temp.add(CFRecordsAggregate.createCFAggregate(rs)); temp.add(CFRecordsAggregate.createCFAggregate(rs));
} }
@ -53,7 +53,7 @@ public final class ConditionalFormattingTable extends RecordAggregate {
public void visitContainedRecords(RecordVisitor rv) { public void visitContainedRecords(RecordVisitor rv) {
for (int i = 0; i < _cfHeaders.size(); i++) { for (int i = 0; i < _cfHeaders.size(); i++) {
CFRecordsAggregate subAgg = (CFRecordsAggregate) _cfHeaders.get(i); CFRecordsAggregate subAgg = _cfHeaders.get(i);
subAgg.visitContainedRecords(rv); subAgg.visitContainedRecords(rv);
} }
} }
@ -72,7 +72,7 @@ public final class ConditionalFormattingTable extends RecordAggregate {
public CFRecordsAggregate get(int index) { public CFRecordsAggregate get(int index) {
checkIndex(index); checkIndex(index);
return (CFRecordsAggregate) _cfHeaders.get(index); return _cfHeaders.get(index);
} }
public void remove(int index) { public void remove(int index) {
@ -89,7 +89,7 @@ public final class ConditionalFormattingTable extends RecordAggregate {
public void updateFormulasAfterCellShift(FormulaShifter shifter, int externSheetIndex) { public void updateFormulasAfterCellShift(FormulaShifter shifter, int externSheetIndex) {
for (int i = 0; i < _cfHeaders.size(); i++) { 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); boolean shouldKeep = subAgg.updateFormulasAfterCellShift(shifter, externSheetIndex);
if (!shouldKeep) { if (!shouldKeep) {
_cfHeaders.remove(i); _cfHeaders.remove(i);

View File

@ -23,7 +23,6 @@ import java.util.List;
import org.apache.poi.hssf.model.RecordStream; import org.apache.poi.hssf.model.RecordStream;
import org.apache.poi.hssf.record.DVALRecord; import org.apache.poi.hssf.record.DVALRecord;
import org.apache.poi.hssf.record.DVRecord; import org.apache.poi.hssf.record.DVRecord;
import org.apache.poi.hssf.record.Record;
/** /**
* Manages the DVALRecord and DVRecords for a single sheet<br/> * Manages the DVALRecord and DVRecords for a single sheet<br/>
@ -37,20 +36,20 @@ public final class DataValidityTable extends RecordAggregate {
* The list of data validations for the current sheet. * The list of data validations for the current sheet.
* Note - this may be empty (contrary to OOO documentation) * Note - this may be empty (contrary to OOO documentation)
*/ */
private final List _validationList; private final List<DVRecord> _validationList;
public DataValidityTable(RecordStream rs) { public DataValidityTable(RecordStream rs) {
_headerRec = (DVALRecord) rs.getNext(); _headerRec = (DVALRecord) rs.getNext();
List temp = new ArrayList(); List<DVRecord> temp = new ArrayList<DVRecord>();
while (rs.peekNextClass() == DVRecord.class) { while (rs.peekNextClass() == DVRecord.class) {
temp.add(rs.getNext()); temp.add((DVRecord) rs.getNext());
} }
_validationList = temp; _validationList = temp;
} }
public DataValidityTable() { public DataValidityTable() {
_headerRec = new DVALRecord(); _headerRec = new DVALRecord();
_validationList = new ArrayList(); _validationList = new ArrayList<DVRecord>();
} }
public void visitContainedRecords(RecordVisitor rv) { public void visitContainedRecords(RecordVisitor rv) {
@ -59,7 +58,7 @@ public final class DataValidityTable extends RecordAggregate {
} }
rv.visitRecord(_headerRec); rv.visitRecord(_headerRec);
for (int i = 0; i < _validationList.size(); i++) { for (int i = 0; i < _validationList.size(); i++) {
rv.visitRecord((Record) _validationList.get(i)); rv.visitRecord(_validationList.get(i));
} }
} }

View File

@ -162,7 +162,7 @@ public class DVConstraint implements DataValidationConstraint {
// formula2 and value2 are mutually exclusive // formula2 and value2 are mutually exclusive
String formula2 = getFormulaFromTextExpression(expr2); String formula2 = getFormulaFromTextExpression(expr2);
Double value2 = formula2 == null ? convertTime(expr2) : null; 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 // formula2 and value2 are mutually exclusive
String formula2 = getFormulaFromTextExpression(expr2); String formula2 = getFormulaFromTextExpression(expr2);
Double value2 = formula2 == null ? convertDate(expr2, df) : null; 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) { if (formula == null) {
throw new IllegalArgumentException("formula must be supplied"); 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) /* (non-Javadoc)
@ -284,14 +284,14 @@ public class DVConstraint implements DataValidationConstraint {
* @return <code>true</code> if this constraint is a 'list' validation * @return <code>true</code> if this constraint is a 'list' validation
*/ */
public boolean isListValidationType() { public boolean isListValidationType() {
return _validationType == VT.LIST; return _validationType == ValidationType.LIST;
} }
/** /**
* Convenience method * Convenience method
* @return <code>true</code> if this constraint is a 'list' validation with explicit values * @return <code>true</code> if this constraint is a 'list' validation with explicit values
*/ */
public boolean isExplicitList() { public boolean isExplicitList() {
return _validationType == VT.LIST && _explicitListValues != null; return _validationType == ValidationType.LIST && _explicitListValues != null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.apache.poi.hssf.usermodel.DataValidationConstraint#getOperator() * @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[]) * @see org.apache.poi.hssf.usermodel.DataValidationConstraint#setExplicitListValues(java.lang.String[])
*/ */
public void setExplicitListValues(String[] explicitListValues) { public void setExplicitListValues(String[] explicitListValues) {
if (_validationType != VT.LIST) { if (_validationType != ValidationType.LIST) {
throw new RuntimeException("Cannot setExplicitListValues on non-list constraint"); throw new RuntimeException("Cannot setExplicitListValues on non-list constraint");
} }
_formula1 = null; _formula1 = null;

View File

@ -33,13 +33,20 @@ public class ErrorConstant {
// convenient access to name space // convenient access to name space
private static final ErrorConstants EC = null; private static final ErrorConstants EC = null;
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); private static final ErrorConstant NULL = new ErrorConstant(EC.ERROR_NULL);
private static final ErrorConstant VALUE = new ErrorConstant(EC.ERROR_VALUE); @SuppressWarnings("static-access")
private static final ErrorConstant REF = new ErrorConstant(EC.ERROR_REF); private static final ErrorConstant DIV_0 = new ErrorConstant(EC.ERROR_DIV_0);
private static final ErrorConstant NAME = new ErrorConstant(EC.ERROR_NAME); @SuppressWarnings("static-access")
private static final ErrorConstant NUM = new ErrorConstant(EC.ERROR_NUM); private static final ErrorConstant VALUE = new ErrorConstant(EC.ERROR_VALUE);
private static final ErrorConstant NA = new ErrorConstant(EC.ERROR_NA); @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; private final int _errorCode;

View File

@ -29,18 +29,25 @@ public final class ErrorEval implements ValueEval {
private static final ErrorConstants EC = null; private static final ErrorConstants EC = null;
/** <b>#NULL!</b> - Intersection of two cell ranges is empty */ /** <b>#NULL!</b> - Intersection of two cell ranges is empty */
@SuppressWarnings("static-access")
public static final ErrorEval NULL_INTERSECTION = new ErrorEval(EC.ERROR_NULL); public static final ErrorEval NULL_INTERSECTION = new ErrorEval(EC.ERROR_NULL);
/** <b>#DIV/0!</b> - Division by zero */ /** <b>#DIV/0!</b> - Division by zero */
@SuppressWarnings("static-access")
public static final ErrorEval DIV_ZERO = new ErrorEval(EC.ERROR_DIV_0); public static final ErrorEval DIV_ZERO = new ErrorEval(EC.ERROR_DIV_0);
/** <b>#VALUE!</b> - Wrong type of operand */ /** <b>#VALUE!</b> - Wrong type of operand */
@SuppressWarnings("static-access")
public static final ErrorEval VALUE_INVALID = new ErrorEval(EC.ERROR_VALUE); public static final ErrorEval VALUE_INVALID = new ErrorEval(EC.ERROR_VALUE);
/** <b>#REF!</b> - Illegal or deleted cell reference */ /** <b>#REF!</b> - Illegal or deleted cell reference */
@SuppressWarnings("static-access")
public static final ErrorEval REF_INVALID = new ErrorEval(EC.ERROR_REF); public static final ErrorEval REF_INVALID = new ErrorEval(EC.ERROR_REF);
/** <b>#NAME?</b> - Wrong function or range name */ /** <b>#NAME?</b> - Wrong function or range name */
@SuppressWarnings("static-access")
public static final ErrorEval NAME_INVALID = new ErrorEval(EC.ERROR_NAME); public static final ErrorEval NAME_INVALID = new ErrorEval(EC.ERROR_NAME);
/** <b>#NUM!</b> - Value range overflow */ /** <b>#NUM!</b> - Value range overflow */
@SuppressWarnings("static-access")
public static final ErrorEval NUM_ERROR = new ErrorEval(EC.ERROR_NUM); public static final ErrorEval NUM_ERROR = new ErrorEval(EC.ERROR_NUM);
/** <b>#N/A</b> - Argument or function not available */ /** <b>#N/A</b> - Argument or function not available */
@SuppressWarnings("static-access")
public static final ErrorEval NA = new ErrorEval(EC.ERROR_NA); public static final ErrorEval NA = new ErrorEval(EC.ERROR_NA);

View File

@ -30,18 +30,25 @@ public final class ErrPtg extends ScalarConstantPtg {
private static final ErrorConstants EC = null; private static final ErrorConstants EC = null;
/** <b>#NULL!</b> - Intersection of two cell ranges is empty */ /** <b>#NULL!</b> - Intersection of two cell ranges is empty */
@SuppressWarnings("static-access")
public static final ErrPtg NULL_INTERSECTION = new ErrPtg(EC.ERROR_NULL); public static final ErrPtg NULL_INTERSECTION = new ErrPtg(EC.ERROR_NULL);
/** <b>#DIV/0!</b> - Division by zero */ /** <b>#DIV/0!</b> - Division by zero */
@SuppressWarnings("static-access")
public static final ErrPtg DIV_ZERO = new ErrPtg(EC.ERROR_DIV_0); public static final ErrPtg DIV_ZERO = new ErrPtg(EC.ERROR_DIV_0);
/** <b>#VALUE!</b> - Wrong type of operand */ /** <b>#VALUE!</b> - Wrong type of operand */
@SuppressWarnings("static-access")
public static final ErrPtg VALUE_INVALID = new ErrPtg(EC.ERROR_VALUE); public static final ErrPtg VALUE_INVALID = new ErrPtg(EC.ERROR_VALUE);
/** <b>#REF!</b> - Illegal or deleted cell reference */ /** <b>#REF!</b> - Illegal or deleted cell reference */
@SuppressWarnings("static-access")
public static final ErrPtg REF_INVALID = new ErrPtg(EC.ERROR_REF); public static final ErrPtg REF_INVALID = new ErrPtg(EC.ERROR_REF);
/** <b>#NAME?</b> - Wrong function or range name */ /** <b>#NAME?</b> - Wrong function or range name */
@SuppressWarnings("static-access")
public static final ErrPtg NAME_INVALID = new ErrPtg(EC.ERROR_NAME); public static final ErrPtg NAME_INVALID = new ErrPtg(EC.ERROR_NAME);
/** <b>#NUM!</b> - Value range overflow */ /** <b>#NUM!</b> - Value range overflow */
@SuppressWarnings("static-access")
public static final ErrPtg NUM_ERROR = new ErrPtg(EC.ERROR_NUM); public static final ErrPtg NUM_ERROR = new ErrPtg(EC.ERROR_NUM);
/** <b>#N/A</b> - Argument or function not available */ /** <b>#N/A</b> - Argument or function not available */
@SuppressWarnings("static-access")
public static final ErrPtg N_A = new ErrPtg(EC.ERROR_NA); public static final ErrPtg N_A = new ErrPtg(EC.ERROR_NA);

View File

@ -17,11 +17,12 @@
package org.apache.poi.ss.util; package org.apache.poi.ss.util;
import org.apache.poi.ss.SpreadsheetVersion;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.apache.poi.ss.SpreadsheetVersion;
public class AreaReference { public class AreaReference {
/** The character (!) that separates sheet names from cell references */ /** The character (!) that separates sheet names from cell references */
@ -199,14 +200,14 @@ public class AreaReference {
* returns an array of contiguous area references. * returns an array of contiguous area references.
*/ */
public static AreaReference[] generateContiguous(String reference) { public static AreaReference[] generateContiguous(String reference) {
ArrayList refs = new ArrayList(); List<AreaReference> refs = new ArrayList<AreaReference>();
StringTokenizer st = new StringTokenizer(reference, ","); StringTokenizer st = new StringTokenizer(reference, ",");
while(st.hasMoreTokens()) { while(st.hasMoreTokens()) {
refs.add( refs.add(
new AreaReference(st.nextToken()) 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()); int maxCol = Math.max(_firstCell.getCol(), _lastCell.getCol());
String sheetName = _firstCell.getSheetName(); String sheetName = _firstCell.getSheetName();
ArrayList refs = new ArrayList(); List<CellReference> refs = new ArrayList<CellReference>();
for(int row=minRow; row<=maxRow; row++) { for(int row=minRow; row<=maxRow; row++) {
for(int col=minCol; col<=maxCol; col++) { for(int col=minCol; col<=maxCol; col++) {
CellReference ref = new CellReference(sheetName, row, col, _firstCell.isRowAbsolute(), _firstCell.isColAbsolute()); CellReference ref = new CellReference(sheetName, row, col, _firstCell.isRowAbsolute(), _firstCell.isColAbsolute());
refs.add(ref); refs.add(ref);
} }
} }
return (CellReference[])refs.toArray(new CellReference[refs.size()]); return refs.toArray(new CellReference[refs.size()]);
} }
/** /**

View File

@ -42,10 +42,10 @@ public class CellRangeAddressList {
/** /**
* List of <tt>CellRangeAddress</tt>es. Each structure represents a cell range * List of <tt>CellRangeAddress</tt>es. Each structure represents a cell range
*/ */
protected final List _list; protected final List<CellRangeAddress> _list;
public CellRangeAddressList() { public CellRangeAddressList() {
_list = new ArrayList(); _list = new ArrayList<CellRangeAddress>();
} }
/** /**
* Convenience constructor for creating a <tt>CellRangeAddressList</tt> with a single * Convenience constructor for creating a <tt>CellRangeAddressList</tt> with a single
@ -101,14 +101,14 @@ public class CellRangeAddressList {
throw new RuntimeException("Range index (" + rangeIndex throw new RuntimeException("Range index (" + rangeIndex
+ ") is outside allowable range (0.." + (_list.size()-1) + ")"); + ") is outside allowable range (0.." + (_list.size()-1) + ")");
} }
return (CellRangeAddress) _list.remove(rangeIndex); return _list.remove(rangeIndex);
} }
/** /**
* @return <tt>CellRangeAddress</tt> at the given index * @return <tt>CellRangeAddress</tt> at the given index
*/ */
public CellRangeAddress getCellRangeAddress(int index) { public CellRangeAddress getCellRangeAddress(int index) {
return (CellRangeAddress) _list.get(index); return _list.get(index);
} }
public int getSize() { public int getSize() {
@ -131,7 +131,7 @@ public class CellRangeAddressList {
int nItems = _list.size(); int nItems = _list.size();
out.writeShort(nItems); out.writeShort(nItems);
for (int k = 0; k < nItems; k++) { for (int k = 0; k < nItems; k++) {
CellRangeAddress region = (CellRangeAddress) _list.get(k); CellRangeAddress region = _list.get(k);
region.serialize(out); region.serialize(out);
} }
} }
@ -142,7 +142,7 @@ public class CellRangeAddressList {
int nItems = _list.size(); int nItems = _list.size();
for (int k = 0; k < nItems; k++) { for (int k = 0; k < nItems; k++) {
CellRangeAddress region = (CellRangeAddress) _list.get(k); CellRangeAddress region = _list.get(k);
result.addCellRangeAddress(region.copy()); result.addCellRangeAddress(region.copy());
} }
return result; return result;

View File

@ -88,6 +88,7 @@ import java.util.*;
* @author Marc Johnson (mjohnson at apache dot org) * @author Marc Johnson (mjohnson at apache dot org)
*/ */
//for performance //for performance
@SuppressWarnings("rawtypes")
public class BinaryTree extends AbstractMap { public class BinaryTree extends AbstractMap {
final Node[] _root; final Node[] _root;
int _size = 0; int _size = 0;

View File

@ -23,6 +23,7 @@ import java.awt.*;
import java.awt.font.TextLayout; import java.awt.font.TextLayout;
import java.text.AttributedCharacterIterator; import java.text.AttributedCharacterIterator;
import java.text.AttributedString; import java.text.AttributedString;
import java.text.CharacterIterator;
/** /**
* a renderable text fragment * a renderable text fragment
@ -76,7 +77,7 @@ class TextFragment {
AttributedCharacterIterator it = _str.getIterator(); AttributedCharacterIterator it = _str.getIterator();
StringBuffer buf = new StringBuffer(); 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); buf.append(c);
} }
return buf.toString(); return buf.toString();

View File

@ -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.Cell;
import org.apache.poi.ss.usermodel.CellValue; import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.FormulaEvaluator; import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Workbook;
/** /**
* Evaluates formula cells.<p/> * Evaluates formula cells.<p/>
@ -239,7 +238,7 @@ public class XSSFFormulaEvaluator implements FormulaEvaluator, WorkbookEvaluator
* cells, and calling evaluateFormulaCell on each one. * cells, and calling evaluateFormulaCell on each one.
*/ */
public static void evaluateAllFormulaCells(XSSFWorkbook wb) { public static void evaluateAllFormulaCells(XSSFWorkbook wb) {
HSSFFormulaEvaluator.evaluateAllFormulaCells((Workbook)wb); HSSFFormulaEvaluator.evaluateAllFormulaCells(wb);
} }
/** /**
* Loops over all cells in all sheets of the supplied * Loops over all cells in all sheets of the supplied

View File

@ -312,7 +312,7 @@ public class XWPFHeaderFooterPolicy {
private XmlOptions commit(XWPFHeaderFooter wrapper) { private XmlOptions commit(XWPFHeaderFooter wrapper) {
XmlOptions xmlOptions = new XmlOptions(wrapper.DEFAULT_XML_OPTIONS); XmlOptions xmlOptions = new XmlOptions(POIXMLDocumentPart.DEFAULT_XML_OPTIONS);
Map<String, String> map = new HashMap<String, String>(); Map<String, String> map = new HashMap<String, String>();
map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m"); map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m");
map.put("urn:schemas-microsoft-com:office:office", "o"); map.put("urn:schemas-microsoft-com:office:office", "o");

View File

@ -109,7 +109,7 @@ public final class TestColumnHelper extends TestCase {
assertEquals(9, cols1.sizeOfColArray()); assertEquals(9, cols1.sizeOfColArray());
assertEquals(20, cols1.getColArray(8).getMin()); assertEquals(20, cols1.getColArray(8).getMin());
assertEquals(30, cols1.getColArray(8).getMax()); assertEquals(30, cols1.getColArray(8).getMax());
helper.sortColumns(cols1); ColumnHelper.sortColumns(cols1);
assertEquals(9, cols1.sizeOfColArray()); assertEquals(9, cols1.sizeOfColArray());
assertEquals(25, cols1.getColArray(8).getMin()); assertEquals(25, cols1.getColArray(8).getMin());
assertEquals(27, cols1.getColArray(8).getMax()); assertEquals(27, cols1.getColArray(8).getMax());

View File

@ -93,10 +93,10 @@ public final class TestXWPFHeader extends TestCase {
pars2[1] = p3; pars2[1] = p3;
// Set headers // Set headers
XWPFHeader headerD = policy.createHeader(policy.DEFAULT, pars); XWPFHeader headerD = policy.createHeader(XWPFHeaderFooterPolicy.DEFAULT, pars);
XWPFHeader headerF = policy.createHeader(policy.FIRST); XWPFHeader headerF = policy.createHeader(XWPFHeaderFooterPolicy.FIRST);
// Set a default footer and capture the returned XWPFFooter object. // 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.... // Ensure the headers and footer were set correctly....
assertNotNull(policy.getDefaultHeader()); assertNotNull(policy.getDefaultHeader());

View File

@ -22,7 +22,9 @@ import java.lang.reflect.Field;
import java.util.Arrays; import java.util.Arrays;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hwpf.HWPFDocFixture; import org.apache.poi.hwpf.HWPFDocFixture;
import org.apache.poi.hwpf.model.types.DOPAbstractType;
public final class TestDocumentProperties public final class TestDocumentProperties
extends TestCase extends TestCase
@ -33,7 +35,7 @@ public final class TestDocumentProperties
public void testReadWrite() public void testReadWrite()
throws Exception throws Exception
{ {
int size = _documentProperties.getSize(); int size = DOPAbstractType.getSize();
byte[] buf = new byte[size]; byte[] buf = new byte[size];
_documentProperties.serialize(buf, 0); _documentProperties.serialize(buf, 0);

View File

@ -45,6 +45,9 @@ import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress; 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; import org.apache.poi.ss.util.CellRangeAddressList;
/** /**
@ -149,11 +152,11 @@ public final class TestDataValidation extends BaseTestDataValidation {
int dvRow = 0; int dvRow = 0;
Sheet sheet = wb.getSheetAt(0); Sheet sheet = wb.getSheetAt(0);
DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper(); 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)); DataValidation dv = dataValidationHelper.createValidation(dc,new CellRangeAddressList(dvRow, dvRow, 0, 0));
dv.setEmptyCellAllowed(false); dv.setEmptyCellAllowed(false);
dv.setErrorStyle(ES.STOP); dv.setErrorStyle(ErrorStyle.STOP);
dv.setShowPromptBox(true); dv.setShowPromptBox(true);
dv.createErrorBox("Xxx", "Yyy"); dv.createErrorBox("Xxx", "Yyy");
dv.setSuppressDropDownArrow(true); dv.setSuppressDropDownArrow(true);

View File

@ -31,6 +31,7 @@ import org.apache.poi.hssf.record.LabelSSTRecord;
import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor; import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; 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.CellRangeAddress;
import org.apache.poi.ss.util.Region; import org.apache.poi.ss.util.Region;
import org.apache.poi.util.TempFile; import org.apache.poi.util.TempFile;
@ -395,7 +396,7 @@ public final class TestWorkbook extends TestCase {
HSSFCell c = s.getRow(0).getCell(0); HSSFCell c = s.getRow(0).getCell(0);
int a = c.getCellType(); int a = c.getCellType();
assertEquals(a, c.CELL_TYPE_NUMERIC); assertEquals(a, Cell.CELL_TYPE_NUMERIC);
} }
/** /**

View File

@ -43,7 +43,7 @@ public final class TestEqualEval extends TestCase {
EvalFactory.createAreaEval("B1:B1", values), EvalFactory.createAreaEval("B1:B1", values),
BoolEval.FALSE, BoolEval.FALSE,
}; };
ValueEval result = evaluate(EI.Equal, args, 10, 10); ValueEval result = evaluate(EvalInstances.Equal, args, 10, 10);
if (result instanceof ErrorEval) { if (result instanceof ErrorEval) {
if (result == ErrorEval.VALUE_INVALID) { if (result == ErrorEval.VALUE_INVALID) {
throw new AssertionFailedError("Identified bug in evaluation of 1x1 area"); throw new AssertionFailedError("Identified bug in evaluation of 1x1 area");
@ -61,7 +61,7 @@ public final class TestEqualEval extends TestCase {
new StringEval(""), new StringEval(""),
BlankEval.instance, BlankEval.instance,
}; };
ValueEval result = evaluate(EI.Equal, args, 10, 10); ValueEval result = evaluate(EvalInstances.Equal, args, 10, 10);
assertEquals(BoolEval.class, result.getClass()); assertEquals(BoolEval.class, result.getClass());
BoolEval be = (BoolEval) result; BoolEval be = (BoolEval) result;
if (!be.getBooleanValue()) { if (!be.getBooleanValue()) {
@ -74,14 +74,14 @@ public final class TestEqualEval extends TestCase {
* Test for bug 46613 (observable at svn r737248) * Test for bug 46613 (observable at svn r737248)
*/ */
public void testStringInsensitive_bug46613() { public void testStringInsensitive_bug46613() {
if (!evalStringCmp("abc", "aBc", EI.Equal)) { if (!evalStringCmp("abc", "aBc", EvalInstances.Equal)) {
throw new AssertionFailedError("Identified bug 46613"); throw new AssertionFailedError("Identified bug 46613");
} }
assertTrue(evalStringCmp("abc", "aBc", EI.Equal)); assertTrue(evalStringCmp("abc", "aBc", EvalInstances.Equal));
assertTrue(evalStringCmp("ABC", "azz", EI.LessThan)); assertTrue(evalStringCmp("ABC", "azz", EvalInstances.LessThan));
assertTrue(evalStringCmp("abc", "AZZ", EI.LessThan)); assertTrue(evalStringCmp("abc", "AZZ", EvalInstances.LessThan));
assertTrue(evalStringCmp("ABC", "aaa", EI.GreaterThan)); assertTrue(evalStringCmp("ABC", "aaa", EvalInstances.GreaterThan));
assertTrue(evalStringCmp("abc", "AAA", EI.GreaterThan)); assertTrue(evalStringCmp("abc", "AAA", EvalInstances.GreaterThan));
} }
private static boolean evalStringCmp(String a, String b, Function cmpOp) { 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); confirmCompares(BoolEval.FALSE, BoolEval.FALSE, 0);
} }
private static void confirmCompares(ValueEval a, ValueEval b, int expRes) { private static void confirmCompares(ValueEval a, ValueEval b, int expRes) {
confirm(a, b, expRes>0, EI.GreaterThan); confirm(a, b, expRes>0, EvalInstances.GreaterThan);
confirm(a, b, expRes>=0, EI.GreaterEqual); confirm(a, b, expRes>=0, EvalInstances.GreaterEqual);
confirm(a, b, expRes==0, EI.Equal); confirm(a, b, expRes==0, EvalInstances.Equal);
confirm(a, b, expRes<=0, EI.LessEqual); confirm(a, b, expRes<=0, EvalInstances.LessEqual);
confirm(a, b, expRes<0, EI.LessThan); confirm(a, b, expRes<0, EvalInstances.LessThan);
confirm(b, a, expRes<0, EI.GreaterThan); confirm(b, a, expRes<0, EvalInstances.GreaterThan);
confirm(b, a, expRes<=0, EI.GreaterEqual); confirm(b, a, expRes<=0, EvalInstances.GreaterEqual);
confirm(b, a, expRes==0, EI.Equal); confirm(b, a, expRes==0, EvalInstances.Equal);
confirm(b, a, expRes>=0, EI.LessEqual); confirm(b, a, expRes>=0, EvalInstances.LessEqual);
confirm(b, a, expRes>0, EI.LessThan); confirm(b, a, expRes>0, EvalInstances.LessThan);
} }
private static void confirm(ValueEval a, ValueEval b, boolean expectedResult, Function cmpOp) { private static void confirm(ValueEval a, ValueEval b, boolean expectedResult, Function cmpOp) {
ValueEval[] args = { a, b, }; 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"); throw new AssertionFailedError("Identified bug 47198: unary minus should convert -0.0 to 0.0");
} }
ValueEval[] args = { zero, mZero, }; 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()) { if (!result.getBooleanValue()) {
throw new AssertionFailedError("Identified bug 47198: -0.0 != 0.0"); 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()); assertEquals("1.0055", b.getStringValue());
ValueEval[] args = { a, b, }; 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()) { if (!result.getBooleanValue()) {
throw new AssertionFailedError("Identified bug 47598: 1+1.0028-0.9973 != 1.0055"); throw new AssertionFailedError("Identified bug 47598: 1+1.0028-0.9973 != 1.0055");
} }

View File

@ -124,49 +124,54 @@ public final class TestFormulaBugs extends TestCase {
/** /**
* Bug 42448 - Can't parse SUMPRODUCT(A!C7:A!C67, B8:B68) / B69 <p/> * Bug 42448 - Can't parse SUMPRODUCT(A!C7:A!C67, B8:B68) / B69 <p/>
* @throws IOException
*/ */
public void test42448() { public void test42448() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook(); 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 { try {
cell.setCellFormula(inputFormula); HSSFSheet sheet1 = wb.createSheet("Sheet1");
} catch (StringIndexOutOfBoundsException e) {
throw new AssertionFailedError("Identified bug 42448"); 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, private static void addCell(HSSFSheet sheet, int rowIx, int colIx,

View File

@ -40,24 +40,21 @@ import org.apache.poi.util.HexDump;
public final class TestMinusZeroResult extends TestCase { public final class TestMinusZeroResult extends TestCase {
private static final double MINUS_ZERO = -0.0; private static final double MINUS_ZERO = -0.0;
// convenient access to namepace
private static final EvalInstances EI = null;
public void testSimpleOperators() { public void testSimpleOperators() {
// unary plus is a no-op // unary plus is a no-op
checkEval(MINUS_ZERO, UnaryPlusEval.instance, MINUS_ZERO); checkEval(MINUS_ZERO, UnaryPlusEval.instance, MINUS_ZERO);
// most simple operators convert -0.0 to +0.0 // most simple operators convert -0.0 to +0.0
checkEval(0.0, EI.UnaryMinus, 0.0); checkEval(0.0, EvalInstances.UnaryMinus, 0.0);
checkEval(0.0, EI.Percent, MINUS_ZERO); checkEval(0.0, EvalInstances.Percent, MINUS_ZERO);
checkEval(0.0, EI.Multiply, MINUS_ZERO, 1.0); checkEval(0.0, EvalInstances.Multiply, MINUS_ZERO, 1.0);
checkEval(0.0, EI.Divide, MINUS_ZERO, 1.0); checkEval(0.0, EvalInstances.Divide, MINUS_ZERO, 1.0);
checkEval(0.0, EI.Power, 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 // 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(MINUS_ZERO, EvalInstances.Subtract, MINUS_ZERO, 0.0); // this is the main point of bug 47198
checkEval(0.0, EI.Add, MINUS_ZERO, 0.0); checkEval(0.0, EvalInstances.Add, MINUS_ZERO, 0.0);
} }
/** /**
@ -65,9 +62,9 @@ public final class TestMinusZeroResult extends TestCase {
* gets to the comparison operator) * gets to the comparison operator)
*/ */
public void testComparisonOperators() { public void testComparisonOperators() {
checkEval(false, EI.Equal, 0.0, MINUS_ZERO); checkEval(false, EvalInstances.Equal, 0.0, MINUS_ZERO);
checkEval(true, EI.GreaterThan, 0.0, MINUS_ZERO); checkEval(true, EvalInstances.GreaterThan, 0.0, MINUS_ZERO);
checkEval(true, EI.LessThan, MINUS_ZERO, 0.0); checkEval(true, EvalInstances.LessThan, MINUS_ZERO, 0.0);
} }
public void testTextRendering() { public void testTextRendering() {
@ -81,7 +78,7 @@ public final class TestMinusZeroResult extends TestCase {
*/ */
private static void confirmTextRendering(String expRendering, double d) { private static void confirmTextRendering(String expRendering, double d) {
ValueEval[] args = { StringEval.EMPTY_INSTANCE, new NumberEval(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(); String result = se.getStringValue();
assertEquals(expRendering, result); assertEquals(expRendering, result);
} }

View File

@ -118,31 +118,31 @@ public final class TestIndirect extends TestCase {
// simple error propagation: // simple error propagation:
// arg0 is evaluated to text first // arg0 is evaluated to text first
confirm(feA, c, "INDIRECT(#DIV/0!)", EE.DIV_ZERO); confirm(feA, c, "INDIRECT(#DIV/0!)", ErrorEval.DIV_ZERO);
confirm(feA, c, "INDIRECT(#DIV/0!)", EE.DIV_ZERO); confirm(feA, c, "INDIRECT(#DIV/0!)", ErrorEval.DIV_ZERO);
confirm(feA, c, "INDIRECT(#NAME?, \"x\")", EE.NAME_INVALID); confirm(feA, c, "INDIRECT(#NAME?, \"x\")", ErrorEval.NAME_INVALID);
confirm(feA, c, "INDIRECT(#NUM!, #N/A)", EE.NUM_ERROR); confirm(feA, c, "INDIRECT(#NUM!, #N/A)", ErrorEval.NUM_ERROR);
// arg1 is evaluated to boolean before arg0 is decoded // arg1 is evaluated to boolean before arg0 is decoded
confirm(feA, c, "INDIRECT(\"garbage\", #N/A)", EE.NA); confirm(feA, c, "INDIRECT(\"garbage\", #N/A)", ErrorEval.NA);
confirm(feA, c, "INDIRECT(\"garbage\", \"\")", EE.VALUE_INVALID); // empty string is not valid boolean confirm(feA, c, "INDIRECT(\"garbage\", \"\")", ErrorEval.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\", \"flase\")", ErrorEval.VALUE_INVALID); // must be "TRUE" or "FALSE"
// spaces around sheet name (with or without quotes makes no difference) // 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\")", ErrorEval.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\")", EE.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, "SUM(INDIRECT(\"'John's sales'!A1:C1\"))", ErrorEval.REF_INVALID); // bad quote escaping
confirm(feA, c, "INDIRECT(\"[Book1]Sheet1!A1\")", EE.REF_INVALID); // unknown external workbook confirm(feA, c, "INDIRECT(\"[Book1]Sheet1!A1\")", ErrorEval.REF_INVALID); // unknown external workbook
confirm(feA, c, "INDIRECT(\"Sheet3!A1\")", EE.REF_INVALID); // unknown sheet confirm(feA, c, "INDIRECT(\"Sheet3!A1\")", ErrorEval.REF_INVALID); // unknown sheet
if (false) { // TODO - support evaluation of defined names if (false) { // TODO - support evaluation of defined names
confirm(feA, c, "INDIRECT(\"Sheet1!IW1\")", EE.REF_INVALID); // bad column confirm(feA, c, "INDIRECT(\"Sheet1!IW1\")", ErrorEval.REF_INVALID); // bad column
confirm(feA, c, "INDIRECT(\"Sheet1!A65537\")", EE.REF_INVALID); // bad row 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() { public void testMultipleWorkbooks() {
@ -186,7 +186,7 @@ public final class TestIndirect extends TestCase {
} }
int expCode = expectedResult.getErrorCode(); int expCode = expectedResult.getErrorCode();
if (cv.getErrorValue() != expCode) { if (cv.getErrorValue() != expCode) {
throw new AssertionFailedError("Expected error '" + EE.getText(expCode) throw new AssertionFailedError("Expected error '" + ErrorEval.getText(expCode)
+ "' but got '" + cv.formatAsString() + "'."); + "' but got '" + cv.formatAsString() + "'.");
} }
} }

View File

@ -35,7 +35,7 @@ public final class TestRoundFuncs extends TestCase {
ValueEval strArg = new StringEval("abc"); ValueEval strArg = new StringEval("abc");
ValueEval[] args = { strArg, new NumberEval(2), }; 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); assertEquals(ErrorEval.VALUE_INVALID, result);
} }
@ -43,7 +43,7 @@ public final class TestRoundFuncs extends TestCase {
ValueEval strArg = new StringEval("abc"); ValueEval strArg = new StringEval("abc");
ValueEval[] args = { strArg, new NumberEval(2), }; 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); assertEquals(ErrorEval.VALUE_INVALID, result);
} }

View File

@ -33,7 +33,7 @@ public final class TestTrunc extends AbstractNumericTestCase {
ValueEval strArg = new StringEval("abc"); ValueEval strArg = new StringEval("abc");
ValueEval[] args = { strArg, new NumberEval(2) }; 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); assertEquals(ErrorEval.VALUE_INVALID, result);
} }
@ -53,7 +53,7 @@ public final class TestTrunc extends AbstractNumericTestCase {
public void testTruncWithDecimalNumberOneArg() { public void testTruncWithDecimalNumberOneArg() {
ValueEval[] args = { new NumberEval(2.612777) }; 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()); assertEquals("TRUNC", (new NumberEval(2d)).getNumberValue(), ((NumberEval)result).getNumberValue());
} }

View File

@ -178,7 +178,7 @@ public abstract class BaseTestCell extends TestCase {
Font f = wb.createFont(); Font f = wb.createFont();
f.setFontHeightInPoints((short) 20); f.setFontHeightInPoints((short) 20);
f.setColor(IndexedColors.RED.getIndex()); f.setColor(IndexedColors.RED.getIndex());
f.setBoldweight(f.BOLDWEIGHT_BOLD); f.setBoldweight(Font.BOLDWEIGHT_BOLD);
f.setFontName("Arial Unicode MS"); f.setFontName("Arial Unicode MS");
cs.setFillBackgroundColor((short)3); cs.setFillBackgroundColor((short)3);
cs.setFont(f); cs.setFont(f);
@ -197,7 +197,7 @@ public abstract class BaseTestCell extends TestCase {
r = s.getRow(0); r = s.getRow(0);
c = r.getCell(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(); cs = c.getCellStyle();
assertNotNull("Formula Cell Style", cs); assertNotNull("Formula Cell Style", cs);

View File

@ -20,6 +20,9 @@ package org.apache.poi.ss.usermodel;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.ss.ITestDataProvider; 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.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList; import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.util.POILogFactory; 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, private DataValidationConstraint createConstraint(DataValidationHelper dataValidationHelper,int operatorType, String firstFormula,
String secondFormula, String[] explicitListValues) { String secondFormula, String[] explicitListValues) {
if (_validationType == VT.LIST) { if (_validationType == ValidationType.LIST) {
if (explicitListValues != null) { if (explicitListValues != null) {
return dataValidationHelper.createExplicitListConstraint(explicitListValues); return dataValidationHelper.createExplicitListConstraint(explicitListValues);
} }
return dataValidationHelper.createFormulaListConstraint(firstFormula); return dataValidationHelper.createFormulaListConstraint(firstFormula);
} }
if (_validationType == VT.TIME) { if (_validationType == ValidationType.TIME) {
return dataValidationHelper.createTimeConstraint(operatorType, firstFormula, secondFormula); return dataValidationHelper.createTimeConstraint(operatorType, firstFormula, secondFormula);
} }
if (_validationType == VT.DATE) { if (_validationType == ValidationType.DATE) {
return dataValidationHelper.createDateConstraint(operatorType, firstFormula, secondFormula, null); return dataValidationHelper.createDateConstraint(operatorType, firstFormula, secondFormula, null);
} }
if (_validationType == VT.FORMULA) { if (_validationType == ValidationType.FORMULA) {
return dataValidationHelper.createCustomConstraint(firstFormula); return dataValidationHelper.createCustomConstraint(firstFormula);
} }
if( _validationType == VT.INTEGER) { if( _validationType == ValidationType.INTEGER) {
return dataValidationHelper.createIntegerConstraint(operatorType, firstFormula, secondFormula); return dataValidationHelper.createIntegerConstraint(operatorType, firstFormula, secondFormula);
} }
if( _validationType == VT.DECIMAL) { if( _validationType == ValidationType.DECIMAL) {
return dataValidationHelper.createDecimalConstraint(operatorType, firstFormula, secondFormula); return dataValidationHelper.createDecimalConstraint(operatorType, firstFormula, secondFormula);
} }
if( _validationType == VT.TEXT_LENGTH) { if( _validationType == ValidationType.TEXT_LENGTH) {
return dataValidationHelper.createTextLengthConstraint(operatorType, firstFormula, secondFormula); return dataValidationHelper.createTextLengthConstraint(operatorType, firstFormula, secondFormula);
} }
return null; return null;
@ -170,7 +173,7 @@ public abstract class BaseTestDataValidation extends TestCase {
boolean allowEmpty, boolean suppressDropDown) { boolean allowEmpty, boolean suppressDropDown) {
String promptDescr = (allowEmpty ? "empty ok" : "not empty") String promptDescr = (allowEmpty ? "empty ok" : "not empty")
+ ", " + (suppressDropDown ? "no drop-down" : "drop-down"); + ", " + (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); allowEmpty, false, true, suppressDropDown, explicitListValues);
} }
} }
@ -312,9 +315,9 @@ public abstract class BaseTestDataValidation extends TestCase {
wf.createSheet("Custom"); wf.createSheet("Custom");
wf.createHeaderRow(); wf.createHeaderRow();
ValidationAdder va = wf.createValidationAdder(null, VT.FORMULA); ValidationAdder va = wf.createValidationAdder(null, ValidationType.FORMULA);
va.addValidation(OP.BETWEEN, "ISNUMBER($A2)", null, ES.STOP, "ISNUMBER(A2)", "Error box type = STOP", true, true, true); va.addValidation(OperatorType.BETWEEN, "ISNUMBER($A2)", null, ErrorStyle.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); 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) { private static void addSimpleNumericValidations(WorkbookFormatter wf) {
@ -325,29 +328,29 @@ public abstract class BaseTestDataValidation extends TestCase {
wf.createDVTypeRow("Whole number"); wf.createDVTypeRow("Whole number");
wf.createHeaderRow(); wf.createHeaderRow();
ValidationAdder va = wf.createValidationAdder(null, VT.INTEGER); ValidationAdder va = wf.createValidationAdder(null, ValidationType.INTEGER);
va.addValidation(OP.BETWEEN, "2", "6", ES.STOP, "Between 2 and 6 ", "Error box type = STOP", true, true, true); va.addValidation(OperatorType.BETWEEN, "2", "6", ErrorStyle.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(OperatorType.NOT_BETWEEN, "2", "6", ErrorStyle.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(OperatorType.EQUAL, "=3+2", null, ErrorStyle.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(OperatorType.NOT_EQUAL, "3", null, ErrorStyle.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(OperatorType.GREATER_THAN, "3", null, ErrorStyle.WARNING, "Greater than 3", "-", true, false, false);
va.addValidation(OP.LESS_THAN, "3", null, ES.WARNING, "Less than 3", "-", true, true, false); va.addValidation(OperatorType.LESS_THAN, "3", null, ErrorStyle.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(OperatorType.GREATER_OR_EQUAL, "4", null, ErrorStyle.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.addValidation(OperatorType.LESS_OR_EQUAL, "4", null, ErrorStyle.STOP, "Less than or equal to 4", "-", false, true, false);
// "Decimal" validation type // "Decimal" validation type
wf.createDVTypeRow("Decimal"); wf.createDVTypeRow("Decimal");
wf.createHeaderRow(); wf.createHeaderRow();
va = wf.createValidationAdder(null, VT.DECIMAL); va = wf.createValidationAdder(null, ValidationType.DECIMAL);
va.addValidation(OP.BETWEEN, "2", "6", ES.STOP, "Between 2 and 6 ", "Error box type = STOP", true, true, true); va.addValidation(OperatorType.BETWEEN, "2", "6", ErrorStyle.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(OperatorType.NOT_BETWEEN, "2", "6", ErrorStyle.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(OperatorType.EQUAL, "3", null, ErrorStyle.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(OperatorType.NOT_EQUAL, "3", null, ErrorStyle.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(OperatorType.GREATER_THAN, "=12/6", null, ErrorStyle.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(OperatorType.LESS_THAN, "3", null, ErrorStyle.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(OperatorType.GREATER_OR_EQUAL, "4", null, ErrorStyle.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.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) { 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.createDVDescriptionRow("Disadvantage - sum of item's length should be less than 255 characters");
wf.createHeaderRow(); wf.createHeaderRow();
ValidationAdder va = wf.createValidationAdder(null, VT.LIST); ValidationAdder va = wf.createValidationAdder(null, ValidationType.LIST);
String listValsDescr = "POIFS,HSSF,HWPF,HPSF"; String listValsDescr = "POIFS,HSSF,HWPF,HPSF";
String[] listVals = listValsDescr.split(","); String[] listVals = listValsDescr.split(",");
va.addListValidation(listVals, null, listValsDescr, false, false); 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.createDVTypeRow("Reference lists - list items are taken from others cells");
wf.createDVDescriptionRow("Advantage - no restriction regarding the sum of item's length"); wf.createDVDescriptionRow("Advantage - no restriction regarding the sum of item's length");
wf.createHeaderRow(); wf.createHeaderRow();
va = wf.createValidationAdder(null, VT.LIST); va = wf.createValidationAdder(null, ValidationType.LIST);
String strFormula = "$A$30:$A$39"; String strFormula = "$A$30:$A$39";
va.addListValidation(null, strFormula, strFormula, false, false); 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.createDVTypeRow("Date ( cells are already formated as date - m/d/yyyy)");
wf.createHeaderRow(); wf.createHeaderRow();
ValidationAdder va = wf.createValidationAdder(cellStyle_date, VT.DATE); ValidationAdder va = wf.createValidationAdder(cellStyle_date, ValidationType.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(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(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(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(OP.EQUAL, "2004/03/02", null, ES.WARNING, "Equal to 3/2/2004", "Error box type = WARNING", false, false, 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(OP.NOT_EQUAL, "2004/03/02", null, ES.WARNING, "Not equal to 3/2/2004", "-", false, false, false); va.addValidation(OperatorType.NOT_EQUAL, "2004/03/02", null, ErrorStyle.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(OperatorType.GREATER_THAN,"=DATEVALUE(\"4-Jul-2001\")", null, ErrorStyle.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(OperatorType.LESS_THAN, "2004/03/02", null, ErrorStyle.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(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(OP.LESS_OR_EQUAL, "2004/03/04", null, ES.STOP, "Less than or equal to 3/4/2004", "-", false, true, false); 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 // "Time" validation type
wf.createDVTypeRow("Time ( cells are already formated as time - h:mm)"); wf.createDVTypeRow("Time ( cells are already formated as time - h:mm)");
wf.createHeaderRow(); wf.createHeaderRow();
va = wf.createValidationAdder(cellStyle_time, VT.TIME); va = wf.createValidationAdder(cellStyle_time, ValidationType.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(OperatorType.BETWEEN, "12:00", "16:00", ErrorStyle.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(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(OP.EQUAL, "13:35", null, ES.WARNING, "Equal to 13:35", "Error box type = WARNING", false, false, true); va.addValidation(OperatorType.EQUAL, "13:35", null, ErrorStyle.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(OperatorType.NOT_EQUAL, "13:35", null, ErrorStyle.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(OperatorType.GREATER_THAN,"12:00", null, ErrorStyle.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(OperatorType.LESS_THAN, "=1/2", null, ErrorStyle.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(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(OP.LESS_OR_EQUAL,"14:00", null, ES.STOP, "Less than or equal to 14:00", "-", false, true, false); 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) { private static void addTextLengthValidations(WorkbookFormatter wf) {
wf.createSheet("Text lengths"); wf.createSheet("Text lengths");
wf.createHeaderRow(); wf.createHeaderRow();
ValidationAdder va = wf.createValidationAdder(null, VT.TEXT_LENGTH); ValidationAdder va = wf.createValidationAdder(null, ValidationType.TEXT_LENGTH);
va.addValidation(OP.BETWEEN, "2", "6", ES.STOP, "Between 2 and 6 ", "Error box type = STOP", true, true, true); va.addValidation(OperatorType.BETWEEN, "2", "6", ErrorStyle.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(OperatorType.NOT_BETWEEN, "2", "6", ErrorStyle.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(OperatorType.EQUAL, "3", null, ErrorStyle.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(OperatorType.NOT_EQUAL, "3", null, ErrorStyle.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(OperatorType.GREATER_THAN, "3", null, ErrorStyle.WARNING, "Greater than 3", "-", true, false, false);
va.addValidation(OP.LESS_THAN, "3", null, ES.WARNING, "Less than 3", "-", true, true, false); va.addValidation(OperatorType.LESS_THAN, "3", null, ErrorStyle.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(OperatorType.GREATER_OR_EQUAL, "4", null, ErrorStyle.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.addValidation(OperatorType.LESS_OR_EQUAL, "4", null, ErrorStyle.STOP, "Less than or equal to 4", "-", false, true, false);
} }
public void testDataValidation() { public void testDataValidation() {

View File

@ -24,10 +24,10 @@ import java.util.List;
* tests can see what got logged * tests can see what got logged
*/ */
public class DummyPOILogger extends POILogger { public class DummyPOILogger extends POILogger {
public List logged = new ArrayList(); public List<String>logged = new ArrayList<String>();
public void reset() { public void reset() {
logged = new ArrayList(); logged = new ArrayList<String>();
} }
public boolean check(int level) { public boolean check(int level) {