removed dependencies on HSSF, prepare to move common formula stuff to org.apache.poi.ss.formula

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1037228 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2010-11-20 14:49:47 +00:00
parent 8cbc24070b
commit b6304a6474
16 changed files with 54 additions and 55 deletions

View File

@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
import org.apache.poi.ss.usermodel.ErrorConstants;
import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
@ -49,7 +49,7 @@ public final class AreaErrPtg extends OperandPtg {
}
public String toFormulaString() {
return HSSFErrorConstants.getText(HSSFErrorConstants.ERROR_REF);
return ErrorConstants.getText(ErrorConstants.ERROR_REF);
}
public byte getDefaultOperandClass() {

View File

@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
import org.apache.poi.ss.usermodel.ErrorConstants;
import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
import org.apache.poi.ss.formula.WorkbookDependentFormula;
import org.apache.poi.util.LittleEndianInput;
@ -49,7 +49,7 @@ public final class DeletedArea3DPtg extends OperandPtg implements WorkbookDepend
}
public String toFormulaString(FormulaRenderingWorkbook book) {
return ExternSheetNameResolver.prependSheetName(book, field_1_index_extern_sheet,
HSSFErrorConstants.getText(HSSFErrorConstants.ERROR_REF));
ErrorConstants.getText(ErrorConstants.ERROR_REF));
}
public String toFormulaString() {
throw new RuntimeException("3D references need a workbook to determine formula text");

View File

@ -18,7 +18,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
import org.apache.poi.ss.usermodel.ErrorConstants;
import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
import org.apache.poi.ss.formula.WorkbookDependentFormula;
import org.apache.poi.util.LittleEndianInput;
@ -49,7 +49,7 @@ public final class DeletedRef3DPtg extends OperandPtg implements WorkbookDepende
public String toFormulaString(FormulaRenderingWorkbook book) {
return ExternSheetNameResolver.prependSheetName(book, field_1_index_extern_sheet,
HSSFErrorConstants.getText(HSSFErrorConstants.ERROR_REF));
ErrorConstants.getText(ErrorConstants.ERROR_REF));
}
public String toFormulaString() {
throw new RuntimeException("3D references need a workbook to determine formula text");

View File

@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
import org.apache.poi.ss.usermodel.ErrorConstants;
import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
@ -27,7 +27,7 @@ import org.apache.poi.util.LittleEndianOutput;
public final class ErrPtg extends ScalarConstantPtg {
// convenient access to namespace
private static final HSSFErrorConstants EC = null;
private static final ErrorConstants EC = null;
/** <b>#NULL!</b> - Intersection of two cell ranges is empty */
public static final ErrPtg NULL_INTERSECTION = new ErrPtg(EC.ERROR_NULL);
@ -52,7 +52,7 @@ public final class ErrPtg extends ScalarConstantPtg {
/** Creates new ErrPtg */
private ErrPtg(int errorCode) {
if(!HSSFErrorConstants.isValidCode(errorCode)) {
if(!ErrorConstants.isValidCode(errorCode)) {
throw new IllegalArgumentException("Invalid error code (" + errorCode + ")");
}
field_1_error_code = errorCode;
@ -68,7 +68,7 @@ public final class ErrPtg extends ScalarConstantPtg {
}
public String toFormulaString() {
return HSSFErrorConstants.getText(field_1_error_code);
return ErrorConstants.getText(field_1_error_code);
}
public int getSize() {
@ -81,13 +81,13 @@ public final class ErrPtg extends ScalarConstantPtg {
public static ErrPtg valueOf(int code) {
switch(code) {
case HSSFErrorConstants.ERROR_DIV_0: return DIV_ZERO;
case HSSFErrorConstants.ERROR_NA: return N_A;
case HSSFErrorConstants.ERROR_NAME: return NAME_INVALID;
case HSSFErrorConstants.ERROR_NULL: return NULL_INTERSECTION;
case HSSFErrorConstants.ERROR_NUM: return NUM_ERROR;
case HSSFErrorConstants.ERROR_REF: return REF_INVALID;
case HSSFErrorConstants.ERROR_VALUE: return VALUE_INVALID;
case ErrorConstants.ERROR_DIV_0: return DIV_ZERO;
case ErrorConstants.ERROR_NA: return N_A;
case ErrorConstants.ERROR_NAME: return NAME_INVALID;
case ErrorConstants.ERROR_NULL: return NULL_INTERSECTION;
case ErrorConstants.ERROR_NUM: return NUM_ERROR;
case ErrorConstants.ERROR_REF: return REF_INVALID;
case ErrorConstants.ERROR_VALUE: return VALUE_INVALID;
}
throw new RuntimeException("Unexpected error code (" + code + ")");
}

View File

@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
import org.apache.poi.ss.usermodel.ErrorConstants;
import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
@ -53,7 +53,7 @@ public final class RefErrorPtg extends OperandPtg {
}
public String toFormulaString() {
return HSSFErrorConstants.getText(HSSFErrorConstants.ERROR_REF);
return ErrorConstants.getText(ErrorConstants.ERROR_REF);
}
public byte getDefaultOperandClass() {

View File

@ -23,7 +23,7 @@ import java.util.TimeZone;
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.EvaluationException;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.DateUtil;
/**
@ -317,7 +317,7 @@ final class YearFracCalculator {
private static SimpleDate createDate(int dayCount) {
GregorianCalendar calendar = new GregorianCalendar(UTC_TIME_ZONE);
HSSFDateUtil.setCalendar(calendar, dayCount, 0, false);
DateUtil.setCalendar(calendar, dayCount, 0, false);
return new SimpleDate(calendar);
}

View File

@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula.eval;
import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
import org.apache.poi.ss.usermodel.ErrorConstants;
/**
* @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
@ -26,7 +26,7 @@ import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
public final class ErrorEval implements ValueEval {
// convenient access to namespace
private static final HSSFErrorConstants EC = null;
private static final ErrorConstants EC = null;
/** <b>#NULL!</b> - Intersection of two cell ranges is empty */
public static final ErrorEval NULL_INTERSECTION = new ErrorEval(EC.ERROR_NULL);
@ -58,13 +58,13 @@ public final class ErrorEval implements ValueEval {
*/
public static ErrorEval valueOf(int errorCode) {
switch(errorCode) {
case HSSFErrorConstants.ERROR_NULL: return NULL_INTERSECTION;
case HSSFErrorConstants.ERROR_DIV_0: return DIV_ZERO;
case HSSFErrorConstants.ERROR_VALUE: return VALUE_INVALID;
case HSSFErrorConstants.ERROR_REF: return REF_INVALID;
case HSSFErrorConstants.ERROR_NAME: return NAME_INVALID;
case HSSFErrorConstants.ERROR_NUM: return NUM_ERROR;
case HSSFErrorConstants.ERROR_NA: return NA;
case ErrorConstants.ERROR_NULL: return NULL_INTERSECTION;
case ErrorConstants.ERROR_DIV_0: return DIV_ZERO;
case ErrorConstants.ERROR_VALUE: return VALUE_INVALID;
case ErrorConstants.ERROR_REF: return REF_INVALID;
case ErrorConstants.ERROR_NAME: return NAME_INVALID;
case ErrorConstants.ERROR_NUM: return NUM_ERROR;
case ErrorConstants.ERROR_NA: return NA;
// non-std errors (conditions modeled as errors by POI)
case CIRCULAR_REF_ERROR_CODE: return CIRCULAR_REF_ERROR;
}
@ -77,8 +77,8 @@ public final class ErrorEval implements ValueEval {
* @return the String representation of the specified Excel error code.
*/
public static String getText(int errorCode) {
if(HSSFErrorConstants.isValidCode(errorCode)) {
return HSSFErrorConstants.getText(errorCode);
if(ErrorConstants.isValidCode(errorCode)) {
return ErrorConstants.getText(errorCode);
}
// It is desirable to make these (arbitrary) strings look clearly different from any other
// value expression that might appear in a formula. In addition these error strings should

View File

@ -149,7 +149,7 @@ public final class OperandResolver {
cells this method could not detect it.
Logic to detect evaluation cycles of all kinds has been coded in EvaluationCycleDetector
(and HSSFFormulaEvaluator).
(and FormulaEvaluator).
*/
}

View File

@ -23,7 +23,7 @@ package org.apache.poi.hssf.record.formula.eval;
* RefEval is the super interface for Ref2D and Ref3DEval. Basically a RefEval
* impl should contain reference to the original ReferencePtg or Ref3DPtg as
* well as the final "value" resulting from the evaluation of the cell
* reference. Thus if the HSSFCell has type CELL_TYPE_NUMERIC, the contained
* reference. Thus if the Cell has type CELL_TYPE_NUMERIC, the contained
* value object should be of type NumberEval; if cell type is CELL_TYPE_STRING,
* contained value object should be of type StringEval
*/

View File

@ -26,7 +26,7 @@ import org.apache.poi.hssf.record.formula.eval.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.OperandResolver;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.DateUtil;
/**
* Implementation of Excel functions DAY, MONTH and YEAR
@ -73,7 +73,7 @@ public final class CalendarFieldFunction extends Fixed1ArgFunction {
}
throw new IllegalStateException("bad date field " + _dateFieldId);
}
Date d = HSSFDateUtil.getJavaDate(serialDay, false); // TODO fix 1900/1904 problem
Date d = DateUtil.getJavaDate(serialDay, false); // TODO fix 1900/1904 problem
Calendar c = new GregorianCalendar();
c.setTime(d);

View File

@ -24,7 +24,7 @@ import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.DateUtil;
/**
@ -77,7 +77,7 @@ public final class DateFunc extends Fixed3ArgFunction {
c.set(year, month, day, 0, 0, 0);
c.set(Calendar.MILLISECOND, 0);
return HSSFDateUtil.getExcelDate(c.getTime(), false); // TODO - fix 1900/1904 problem
return DateUtil.getExcelDate(c.getTime(), false); // TODO - fix 1900/1904 problem
}
private static int getYear(double d) {

View File

@ -22,7 +22,7 @@ import org.apache.poi.hssf.record.formula.eval.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.OperandResolver;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
import org.apache.poi.ss.usermodel.ErrorConstants;
/**
* Implementation for the ERROR.TYPE() Excel function.
@ -45,7 +45,7 @@ import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
* </table>
*
* Note - the results of ERROR.TYPE() are different to the constants defined in
* <tt>HSSFErrorConstants</tt>.
* <tt>ErrorConstants</tt>.
* </p>
*
* @author Josh Micich
@ -65,13 +65,13 @@ public final class Errortype extends Fixed1ArgFunction {
private int translateErrorCodeToErrorTypeValue(int errorCode) {
switch (errorCode) {
case HSSFErrorConstants.ERROR_NULL: return 1;
case HSSFErrorConstants.ERROR_DIV_0: return 2;
case HSSFErrorConstants.ERROR_VALUE: return 3;
case HSSFErrorConstants.ERROR_REF: return 4;
case HSSFErrorConstants.ERROR_NAME: return 5;
case HSSFErrorConstants.ERROR_NUM: return 6;
case HSSFErrorConstants.ERROR_NA : return 7;
case ErrorConstants.ERROR_NULL: return 1;
case ErrorConstants.ERROR_DIV_0: return 2;
case ErrorConstants.ERROR_VALUE: return 3;
case ErrorConstants.ERROR_REF: return 4;
case ErrorConstants.ERROR_NAME: return 5;
case ErrorConstants.ERROR_NUM: return 6;
case ErrorConstants.ERROR_NA : return 7;
}
throw new IllegalArgumentException("Invalid error code (" + errorCode + ")");
}

View File

@ -21,7 +21,7 @@ import java.util.Date;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.DateUtil;
/**
* Implementation of Excel NOW() Function
@ -32,6 +32,6 @@ public final class Now extends Fixed0ArgFunction {
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex) {
Date now = new Date(System.currentTimeMillis());
return new NumberEval(HSSFDateUtil.getExcelDate(now));
return new NumberEval(DateUtil.getExcelDate(now));
}
}

View File

@ -22,7 +22,7 @@ import java.util.GregorianCalendar;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.DateUtil;
/**
* Implementation of Excel TODAY() Function<br/>
@ -36,6 +36,6 @@ public final class Today extends Fixed0ArgFunction {
Calendar now = new GregorianCalendar();
now.set(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DATE),0,0,0);
now.set(Calendar.MILLISECOND, 0);
return new NumberEval(HSSFDateUtil.getExcelDate(now.getTime()));
return new NumberEval(DateUtil.getExcelDate(now.getTime()));
}
}

View File

@ -20,7 +20,6 @@ import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
@ -50,7 +49,7 @@ public class TestRandBetween extends TestCase {
Row row = sheet.createRow(0);
bottomValueCell = row.createCell(0);
topValueCell = row.createCell(1);
formulaCell = row.createCell(2, HSSFCell.CELL_TYPE_FORMULA);
formulaCell = row.createCell(2, Cell.CELL_TYPE_FORMULA);
}
@Override

View File

@ -23,7 +23,7 @@ import java.util.GregorianCalendar;
import junit.framework.TestCase;
import org.apache.poi.hssf.record.formula.eval.EvaluationException;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.DateUtil;
/**
* Specific test cases for YearFracCalculator
@ -62,6 +62,6 @@ public final class TestYearFracCalculator extends TestCase {
c.set(year, month-1, day, 0, 0, 0);
c.set(Calendar.MILLISECOND, 0);
return HSSFDateUtil.getExcelDate(c.getTime());
return DateUtil.getExcelDate(c.getTime());
}
}