more generics compiler warnings fixes for poi.ss.formula

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@723104 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2008-12-03 22:34:26 +00:00
parent d289d148b3
commit bff86351a1
8 changed files with 43 additions and 44 deletions

View File

@ -58,7 +58,7 @@ abstract class CellCacheEntry implements ICacheEntry {
if (a == null) { if (a == null) {
return false; return false;
} }
Class cls = a.getClass(); Class<? extends ValueEval> cls = a.getClass();
if (cls != b.getClass()) { if (cls != b.getClass()) {
// value type is changing // value type is changing
return false; return false;

View File

@ -65,9 +65,9 @@ final class FormulaCellCache {
} }
public void applyOperation(IEntryOperation operation) { public void applyOperation(IEntryOperation operation) {
Iterator i = _formulaEntriesByCell.values().iterator(); Iterator<FormulaCellCacheEntry> i = _formulaEntriesByCell.values().iterator();
while (i.hasNext()) { while (i.hasNext()) {
operation.processEntry((FormulaCellCacheEntry) i.next()); operation.processEntry(i.next());
} }
} }
} }

View File

@ -26,12 +26,11 @@ import org.apache.poi.ss.formula.FormulaUsedBlankCellSet.BookSheetKey;
/** /**
* Stores the cached result of a formula evaluation, along with the set of sensititive input cells * Stores the cached result of a formula evaluation, along with the set of sensitive input cells
* *
* @author Josh Micich * @author Josh Micich
*/ */
final class FormulaCellCacheEntry extends CellCacheEntry { final class FormulaCellCacheEntry extends CellCacheEntry {
public static final FormulaCellCacheEntry[] EMPTY_ARRAY = { };
/** /**
* Cells 'used' in the current evaluation of the formula corresponding to this cache entry * Cells 'used' in the current evaluation of the formula corresponding to this cache entry
@ -43,7 +42,7 @@ final class FormulaCellCacheEntry extends CellCacheEntry {
private FormulaUsedBlankCellSet _usedBlankCellGroup; private FormulaUsedBlankCellSet _usedBlankCellGroup;
public FormulaCellCacheEntry() { public FormulaCellCacheEntry() {
// leave fields un-set
} }
public boolean isInputSensitive() { public boolean isInputSensitive() {

View File

@ -27,18 +27,19 @@ package org.apache.poi.ss.formula;
* @author Josh Micich * @author Josh Micich
*/ */
final class FormulaCellCacheEntrySet { final class FormulaCellCacheEntrySet {
private static final FormulaCellCacheEntry[] EMPTY_ARRAY = { };
private int _size; private int _size;
private FormulaCellCacheEntry[] _arr; private FormulaCellCacheEntry[] _arr;
public FormulaCellCacheEntrySet() { public FormulaCellCacheEntrySet() {
_arr = FormulaCellCacheEntry.EMPTY_ARRAY; _arr = EMPTY_ARRAY;
} }
public FormulaCellCacheEntry[] toArray() { public FormulaCellCacheEntry[] toArray() {
int nItems = _size; int nItems = _size;
if (nItems < 1) { if (nItems < 1) {
return FormulaCellCacheEntry.EMPTY_ARRAY; return EMPTY_ARRAY;
} }
FormulaCellCacheEntry[] result = new FormulaCellCacheEntry[nItems]; FormulaCellCacheEntry[] result = new FormulaCellCacheEntry[nItems];
int j=0; int j=0;
@ -152,5 +153,4 @@ final class FormulaCellCacheEntrySet {
} }
return false; return false;
} }
} }

View File

@ -126,9 +126,9 @@ public final class FormulaParser {
} }
private final String formulaString; private final String _formulaString;
private final int formulaLength; private final int _formulaLength;
private int pointer; private int _pointer;
private ParseNode _rootNode; private ParseNode _rootNode;
@ -140,7 +140,7 @@ public final class FormulaParser {
*/ */
private char look; private char look;
private FormulaParsingWorkbook book; private FormulaParsingWorkbook _book;
@ -148,7 +148,7 @@ public final class FormulaParser {
* Create the formula parser, with the string that is to be * Create the formula parser, with the string that is to be
* parsed against the supplied workbook. * parsed against the supplied workbook.
* A later call the parse() method to return ptg list in * A later call the parse() method to return ptg list in
* rpn order, then call the getRPNPtg() to retrive the * rpn order, then call the getRPNPtg() to retrieve the
* parse results. * parse results.
* This class is recommended only for single threaded use. * This class is recommended only for single threaded use.
* *
@ -157,10 +157,10 @@ public final class FormulaParser {
* usermodel.HSSFFormulaEvaluator * usermodel.HSSFFormulaEvaluator
*/ */
private FormulaParser(String formula, FormulaParsingWorkbook book){ private FormulaParser(String formula, FormulaParsingWorkbook book){
formulaString = formula; _formulaString = formula;
pointer=0; _pointer=0;
this.book = book; _book = book;
formulaLength = formulaString.length(); _formulaLength = _formulaString.length();
} }
public static Ptg[] parse(String formula, FormulaParsingWorkbook book) { public static Ptg[] parse(String formula, FormulaParsingWorkbook book) {
@ -176,17 +176,17 @@ public final class FormulaParser {
/** Read New Character From Input Stream */ /** Read New Character From Input Stream */
private void GetChar() { private void GetChar() {
// Check to see if we've walked off the end of the string. // Check to see if we've walked off the end of the string.
if (pointer > formulaLength) { if (_pointer > _formulaLength) {
throw new RuntimeException("too far"); throw new RuntimeException("too far");
} }
if (pointer < formulaLength) { if (_pointer < _formulaLength) {
look=formulaString.charAt(pointer); look=_formulaString.charAt(_pointer);
} else { } else {
// Just return if so and reset 'look' to something to keep // Just return if so and reset 'look' to something to keep
// SkipWhitespace from spinning // SkipWhitespace from spinning
look = (char)0; look = (char)0;
} }
pointer++; _pointer++;
//System.out.println("Got char: "+ look); //System.out.println("Got char: "+ look);
} }
@ -194,12 +194,12 @@ public final class FormulaParser {
private RuntimeException expected(String s) { private RuntimeException expected(String s) {
String msg; String msg;
if (look == '=' && formulaString.substring(0, pointer-1).trim().length() < 1) { if (look == '=' && _formulaString.substring(0, _pointer-1).trim().length() < 1) {
msg = "The specified formula '" + formulaString msg = "The specified formula '" + _formulaString
+ "' starts with an equals sign which is not allowed."; + "' starts with an equals sign which is not allowed.";
} else { } else {
msg = "Parse error near char " + (pointer-1) + " '" + look + "'" msg = "Parse error near char " + (_pointer-1) + " '" + look + "'"
+ " in specified formula '" + formulaString + "'. Expected " + " in specified formula '" + _formulaString + "'. Expected "
+ s; + s;
} }
return new FormulaParseException(msg); return new FormulaParseException(msg);
@ -413,7 +413,7 @@ public final class FormulaParser {
new FormulaParseException("Name '" + name new FormulaParseException("Name '" + name
+ "' does not look like a cell reference or named range"); + "' does not look like a cell reference or named range");
} }
EvaluationName evalName = book.getName(name); EvaluationName evalName = _book.getName(name);
if (evalName == null) { if (evalName == null) {
throw new FormulaParseException("Specified named range '" throw new FormulaParseException("Specified named range '"
+ name + "' does not exist in the current workbook."); + name + "' does not exist in the current workbook.");
@ -458,9 +458,9 @@ public final class FormulaParser {
int pos = name.lastIndexOf(']'); // safe because sheet names never have ']' int pos = name.lastIndexOf(']'); // safe because sheet names never have ']'
String wbName = name.substring(1, pos); String wbName = name.substring(1, pos);
String sheetName = name.substring(pos+1); String sheetName = name.substring(pos+1);
return book.getExternalSheetIndex(wbName, sheetName); return _book.getExternalSheetIndex(wbName, sheetName);
} }
return book.getExternalSheetIndex(name); return _book.getExternalSheetIndex(name);
} }
/** /**
@ -516,10 +516,10 @@ public final class FormulaParser {
// user defined function // user defined function
// in the token tree, the name is more or less the first argument // in the token tree, the name is more or less the first argument
EvaluationName hName = book.getName(name); EvaluationName hName = _book.getName(name);
if (hName == null) { if (hName == null) {
nameToken = book.getNameXPtg(name); nameToken = _book.getNameXPtg(name);
if (nameToken == null) { if (nameToken == null) {
throw new FormulaParseException("Name '" + name throw new FormulaParseException("Name '" + name
+ "' is completely unknown in the current workbook"); + "' is completely unknown in the current workbook");
@ -1092,13 +1092,13 @@ end;
* *
*/ */
private void parse() { private void parse() {
pointer=0; _pointer=0;
GetChar(); GetChar();
_rootNode = unionExpression(); _rootNode = unionExpression();
if(pointer <= formulaLength) { if(_pointer <= _formulaLength) {
String msg = "Unused input [" + formulaString.substring(pointer-1) String msg = "Unused input [" + _formulaString.substring(_pointer-1)
+ "] after attempting to parse the formula [" + formulaString + "]"; + "] after attempting to parse the formula [" + _formulaString + "]";
throw new FormulaParseException(msg); throw new FormulaParseException(msg);
} }
} }

View File

@ -115,7 +115,7 @@ public class FormulaRenderer {
return result; return result;
} }
private static String[] getOperands(Stack stack, int nOperands) { private static String[] getOperands(Stack<String> stack, int nOperands) {
String[] operands = new String[nOperands]; String[] operands = new String[nOperands];
for (int j = nOperands-1; j >= 0; j--) { // reverse iteration because args were pushed in-order for (int j = nOperands-1; j >= 0; j--) { // reverse iteration because args were pushed in-order
@ -124,7 +124,7 @@ public class FormulaRenderer {
+ ") operands but got (" + (nOperands - j - 1) + ")"; + ") operands but got (" + (nOperands - j - 1) + ")";
throw new IllegalStateException(msg); throw new IllegalStateException(msg);
} }
operands[j] = (String) stack.pop(); operands[j] = stack.pop();
} }
return operands; return operands;
} }

View File

@ -24,7 +24,6 @@ import org.apache.poi.hssf.record.formula.AddPtg;
import org.apache.poi.hssf.record.formula.ConcatPtg; import org.apache.poi.hssf.record.formula.ConcatPtg;
import org.apache.poi.hssf.record.formula.DividePtg; import org.apache.poi.hssf.record.formula.DividePtg;
import org.apache.poi.hssf.record.formula.EqualPtg; import org.apache.poi.hssf.record.formula.EqualPtg;
import org.apache.poi.hssf.record.formula.ExpPtg;
import org.apache.poi.hssf.record.formula.FuncPtg; import org.apache.poi.hssf.record.formula.FuncPtg;
import org.apache.poi.hssf.record.formula.FuncVarPtg; import org.apache.poi.hssf.record.formula.FuncVarPtg;
import org.apache.poi.hssf.record.formula.GreaterEqualPtg; import org.apache.poi.hssf.record.formula.GreaterEqualPtg;
@ -107,7 +106,7 @@ final class OperationEvaluatorFactory {
} }
OperationEval result; OperationEval result;
Class ptgClass = ptg.getClass(); Class<? extends OperationPtg> ptgClass = ptg.getClass();
result = _instancesByPtgClass.get(ptgClass); result = _instancesByPtgClass.get(ptgClass);
if (result != null) { if (result != null) {
@ -123,11 +122,6 @@ final class OperationEvaluatorFactory {
if (ptgClass == ConcatPtg.class) { if (ptgClass == ConcatPtg.class) {
return new ConcatEval((ConcatPtg)ptg); return new ConcatEval((ConcatPtg)ptg);
} }
if(ptgClass == ExpPtg.class) {
// ExpPtg is used for array formulas and shared formulas.
// it is currently unsupported, and may not even get implemented here
throw new RuntimeException("ExpPtg currently not supported");
}
throw new RuntimeException("Unexpected operation ptg class (" + ptgClass.getName() + ")"); throw new RuntimeException("Unexpected operation ptg class (" + ptgClass.getName() + ")");
} }
} }

View File

@ -30,6 +30,7 @@ import org.apache.poi.hssf.record.formula.ControlPtg;
import org.apache.poi.hssf.record.formula.DeletedArea3DPtg; import org.apache.poi.hssf.record.formula.DeletedArea3DPtg;
import org.apache.poi.hssf.record.formula.DeletedRef3DPtg; import org.apache.poi.hssf.record.formula.DeletedRef3DPtg;
import org.apache.poi.hssf.record.formula.ErrPtg; import org.apache.poi.hssf.record.formula.ErrPtg;
import org.apache.poi.hssf.record.formula.ExpPtg;
import org.apache.poi.hssf.record.formula.FuncVarPtg; import org.apache.poi.hssf.record.formula.FuncVarPtg;
import org.apache.poi.hssf.record.formula.IntPtg; import org.apache.poi.hssf.record.formula.IntPtg;
import org.apache.poi.hssf.record.formula.MemErrPtg; import org.apache.poi.hssf.record.formula.MemErrPtg;
@ -456,6 +457,11 @@ public final class WorkbookEvaluator {
// In any case, formulas are re-parsed before execution, so UnknownPtg should not get here // In any case, formulas are re-parsed before execution, so UnknownPtg should not get here
throw new RuntimeException("UnknownPtg not allowed"); throw new RuntimeException("UnknownPtg not allowed");
} }
if (ptg instanceof ExpPtg) {
// ExpPtg is used for array formulas and shared formulas.
// it is currently unsupported, and may not even get implemented here
throw new RuntimeException("ExpPtg currently not supported");
}
throw new RuntimeException("Unexpected ptg class (" + ptg.getClass().getName() + ")"); throw new RuntimeException("Unexpected ptg class (" + ptg.getClass().getName() + ")");
} }