You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/05/22 20:56:49 UTC
svn commit: r1890120 [17/43] - in /poi/trunk/poi/src:
main/java/org/apache/poi/ main/java/org/apache/poi/ddf/
main/java/org/apache/poi/extractor/ main/java/org/apache/poi/hpsf/
main/java/org/apache/poi/hssf/ main/java/org/apache/poi/hssf/dev/
main/java...
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/ParityFunction.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/ParityFunction.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/ParityFunction.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/ParityFunction.java Sat May 22 20:56:44 2021
@@ -29,37 +29,37 @@ import org.apache.poi.ss.formula.Operati
*/
final class ParityFunction implements FreeRefFunction {
- public static final FreeRefFunction IS_EVEN = new ParityFunction(0);
- public static final FreeRefFunction IS_ODD = new ParityFunction(1);
- private final int _desiredParity;
-
- private ParityFunction(int desiredParity) {
- _desiredParity = desiredParity;
- }
-
- public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
- if (args.length != 1) {
- return ErrorEval.VALUE_INVALID;
- }
-
- int val;
- try {
- val = evaluateArgParity(args[0], ec.getRowIndex(), ec.getColumnIndex());
- } catch (EvaluationException e) {
- return e.getErrorEval();
- }
-
- return BoolEval.valueOf(val == _desiredParity);
- }
-
- private static int evaluateArgParity(ValueEval arg, int srcCellRow, int srcCellCol) throws EvaluationException {
- ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, (short)srcCellCol);
-
- double d = OperandResolver.coerceValueToDouble(ve);
- if (d < 0) {
- d = -d;
- }
- long v = (long) Math.floor(d);
- return Math.toIntExact(v & 0x0001);
- }
+ public static final FreeRefFunction IS_EVEN = new ParityFunction(0);
+ public static final FreeRefFunction IS_ODD = new ParityFunction(1);
+ private final int _desiredParity;
+
+ private ParityFunction(int desiredParity) {
+ _desiredParity = desiredParity;
+ }
+
+ public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
+ if (args.length != 1) {
+ return ErrorEval.VALUE_INVALID;
+ }
+
+ int val;
+ try {
+ val = evaluateArgParity(args[0], ec.getRowIndex(), ec.getColumnIndex());
+ } catch (EvaluationException e) {
+ return e.getErrorEval();
+ }
+
+ return BoolEval.valueOf(val == _desiredParity);
+ }
+
+ private static int evaluateArgParity(ValueEval arg, int srcCellRow, int srcCellCol) throws EvaluationException {
+ ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, (short)srcCellCol);
+
+ double d = OperandResolver.coerceValueToDouble(ve);
+ if (d < 0) {
+ d = -d;
+ }
+ long v = (long) Math.floor(d);
+ return Math.toIntExact(v & 0x0001);
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/RandBetween.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/RandBetween.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/RandBetween.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/RandBetween.java Sat May 22 20:56:44 2021
@@ -37,46 +37,46 @@ import org.apache.poi.ss.formula.Operati
*/
final class RandBetween implements FreeRefFunction{
- public static final FreeRefFunction instance = new RandBetween();
+ public static final FreeRefFunction instance = new RandBetween();
- private RandBetween() {
- //enforces singleton
- }
-
- /**
- * Evaluate for RANDBETWEEN(). Must be given two arguments. Bottom must be greater than top.
- * Bottom is rounded up and top value is rounded down. After rounding top has to be set greater
- * than top.
- *
- * @see org.apache.poi.ss.formula.functions.FreeRefFunction#evaluate(org.apache.poi.ss.formula.eval.ValueEval[], org.apache.poi.ss.formula.OperationEvaluationContext)
- */
- public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
-
- double bottom, top;
-
- if (args.length != 2) {
- return ErrorEval.VALUE_INVALID;
- }
-
- try {
- bottom = OperandResolver.coerceValueToDouble(OperandResolver.getSingleValue(args[0], ec.getRowIndex(), ec.getColumnIndex()));
- top = OperandResolver.coerceValueToDouble(OperandResolver.getSingleValue(args[1], ec.getRowIndex(), ec.getColumnIndex()));
- if(bottom > top) {
- return ErrorEval.NUM_ERROR;
- }
- } catch (EvaluationException e) {
- return ErrorEval.VALUE_INVALID;
- }
-
- bottom = Math.ceil(bottom);
- top = Math.floor(top);
-
- if(bottom > top) {
- top = bottom;
- }
+ private RandBetween() {
+ //enforces singleton
+ }
+
+ /**
+ * Evaluate for RANDBETWEEN(). Must be given two arguments. Bottom must be greater than top.
+ * Bottom is rounded up and top value is rounded down. After rounding top has to be set greater
+ * than top.
+ *
+ * @see org.apache.poi.ss.formula.functions.FreeRefFunction#evaluate(org.apache.poi.ss.formula.eval.ValueEval[], org.apache.poi.ss.formula.OperationEvaluationContext)
+ */
+ public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
+
+ double bottom, top;
+
+ if (args.length != 2) {
+ return ErrorEval.VALUE_INVALID;
+ }
+
+ try {
+ bottom = OperandResolver.coerceValueToDouble(OperandResolver.getSingleValue(args[0], ec.getRowIndex(), ec.getColumnIndex()));
+ top = OperandResolver.coerceValueToDouble(OperandResolver.getSingleValue(args[1], ec.getRowIndex(), ec.getColumnIndex()));
+ if(bottom > top) {
+ return ErrorEval.NUM_ERROR;
+ }
+ } catch (EvaluationException e) {
+ return ErrorEval.VALUE_INVALID;
+ }
+
+ bottom = Math.ceil(bottom);
+ top = Math.floor(top);
+
+ if(bottom > top) {
+ top = bottom;
+ }
- return new NumberEval((bottom + (long)(Math.random() * ((top - bottom) + 1))));
+ return new NumberEval((bottom + (long)(Math.random() * ((top - bottom) + 1))));
- }
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/WorkdayCalculator.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/WorkdayCalculator.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/WorkdayCalculator.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/WorkdayCalculator.java Sat May 22 20:56:44 2021
@@ -60,23 +60,23 @@ public class WorkdayCalculator {
* @param holidays an array of holidays.
* @return date past x workdays.
*/
- public Date calculateWorkdays(double start, int workdays, double[] holidays) {
- Date startDate = DateUtil.getJavaDate(start);
- int direction = workdays < 0 ? -1 : 1;
- Calendar endDate = LocaleUtil.getLocaleCalendar();
- endDate.setTime(startDate);
- double excelEndDate = DateUtil.getExcelDate(endDate.getTime());
- while (workdays != 0) {
- endDate.add(Calendar.DAY_OF_YEAR, direction);
- excelEndDate += direction;
- if (endDate.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY
- && endDate.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY
- && !isHoliday(excelEndDate, holidays)) {
- workdays -= direction;
- }
- }
- return endDate.getTime();
- }
+ public Date calculateWorkdays(double start, int workdays, double[] holidays) {
+ Date startDate = DateUtil.getJavaDate(start);
+ int direction = workdays < 0 ? -1 : 1;
+ Calendar endDate = LocaleUtil.getLocaleCalendar();
+ endDate.setTime(startDate);
+ double excelEndDate = DateUtil.getExcelDate(endDate.getTime());
+ while (workdays != 0) {
+ endDate.add(Calendar.DAY_OF_YEAR, direction);
+ excelEndDate += direction;
+ if (endDate.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY
+ && endDate.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY
+ && !isHoliday(excelEndDate, holidays)) {
+ workdays -= direction;
+ }
+ }
+ return endDate.getTime();
+ }
/**
* Calculates how many days of week past between a start and an end date.
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/YearFrac.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/YearFrac.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/YearFrac.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/YearFrac.java Sat May 22 20:56:44 2021
@@ -53,55 +53,55 @@ import org.apache.poi.ss.util.DateParser
*/
final class YearFrac implements FreeRefFunction {
- public static final FreeRefFunction instance = new YearFrac();
+ public static final FreeRefFunction instance = new YearFrac();
- private YearFrac() {
- // enforce singleton
- }
-
- @Override
- public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
- int srcCellRow = ec.getRowIndex();
- int srcCellCol = ec.getColumnIndex();
- double result;
- try {
- int basis = 0; // default
- switch(args.length) {
- case 3:
- basis = evaluateIntArg(args[2], srcCellRow, srcCellCol);
- // fall through
- case 2:
- break;
- default:
- return ErrorEval.VALUE_INVALID;
- }
- double startDateVal = evaluateDateArg(args[0], srcCellRow, srcCellCol);
- double endDateVal = evaluateDateArg(args[1], srcCellRow, srcCellCol);
- result = YearFracCalculator.calculate(startDateVal, endDateVal, basis);
- } catch (EvaluationException e) {
- return e.getErrorEval();
- }
-
- return new NumberEval(result);
- }
-
- private static double evaluateDateArg(ValueEval arg, int srcCellRow, int srcCellCol) throws EvaluationException {
- ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, (short) srcCellCol);
-
- if (ve instanceof StringEval) {
- String strVal = ((StringEval) ve).getStringValue();
- Double dVal = OperandResolver.parseDouble(strVal);
- if (dVal != null) {
- return dVal;
- }
- LocalDate date = DateParser.parseLocalDate(strVal);
- return DateUtil.getExcelDate(date, false);
- }
- return OperandResolver.coerceValueToDouble(ve);
- }
-
- private static int evaluateIntArg(ValueEval arg, int srcCellRow, int srcCellCol) throws EvaluationException {
- ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, (short) srcCellCol);
- return OperandResolver.coerceValueToInt(ve);
- }
+ private YearFrac() {
+ // enforce singleton
+ }
+
+ @Override
+ public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
+ int srcCellRow = ec.getRowIndex();
+ int srcCellCol = ec.getColumnIndex();
+ double result;
+ try {
+ int basis = 0; // default
+ switch(args.length) {
+ case 3:
+ basis = evaluateIntArg(args[2], srcCellRow, srcCellCol);
+ // fall through
+ case 2:
+ break;
+ default:
+ return ErrorEval.VALUE_INVALID;
+ }
+ double startDateVal = evaluateDateArg(args[0], srcCellRow, srcCellCol);
+ double endDateVal = evaluateDateArg(args[1], srcCellRow, srcCellCol);
+ result = YearFracCalculator.calculate(startDateVal, endDateVal, basis);
+ } catch (EvaluationException e) {
+ return e.getErrorEval();
+ }
+
+ return new NumberEval(result);
+ }
+
+ private static double evaluateDateArg(ValueEval arg, int srcCellRow, int srcCellCol) throws EvaluationException {
+ ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, (short) srcCellCol);
+
+ if (ve instanceof StringEval) {
+ String strVal = ((StringEval) ve).getStringValue();
+ Double dVal = OperandResolver.parseDouble(strVal);
+ if (dVal != null) {
+ return dVal;
+ }
+ LocalDate date = DateParser.parseLocalDate(strVal);
+ return DateUtil.getExcelDate(date, false);
+ }
+ return OperandResolver.coerceValueToDouble(ve);
+ }
+
+ private static int evaluateIntArg(ValueEval arg, int srcCellRow, int srcCellCol) throws EvaluationException {
+ ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, (short) srcCellCol);
+ return OperandResolver.coerceValueToInt(ve);
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/YearFracCalculator.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/YearFracCalculator.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/YearFracCalculator.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/YearFracCalculator.java Sat May 22 20:56:44 2021
@@ -33,304 +33,304 @@ import org.apache.poi.util.LocaleUtil;
*/
@Internal
final class YearFracCalculator {
- private static final int MS_PER_HOUR = 60 * 60 * 1000;
- private static final int MS_PER_DAY = 24 * MS_PER_HOUR;
- private static final int DAYS_PER_NORMAL_YEAR = 365;
- private static final int DAYS_PER_LEAP_YEAR = DAYS_PER_NORMAL_YEAR + 1;
-
- /** the length of normal long months i.e. 31 */
- private static final int LONG_MONTH_LEN = 31;
- /** the length of normal short months i.e. 30 */
- private static final int SHORT_MONTH_LEN = 30;
- private static final int SHORT_FEB_LEN = 28;
- private static final int LONG_FEB_LEN = SHORT_FEB_LEN + 1;
-
- private YearFracCalculator() {
- // no instances of this class
- }
-
-
- public static double calculate(double pStartDateVal, double pEndDateVal, int basis) throws EvaluationException {
-
- if (basis < 0 || basis >= 5) {
- // if basis is invalid the result is #NUM!
- throw new EvaluationException(ErrorEval.NUM_ERROR);
- }
-
- // common logic for all bases
-
- // truncate day values
- int startDateVal = (int) Math.floor(pStartDateVal);
- int endDateVal = (int) Math.floor(pEndDateVal);
- if (startDateVal == endDateVal) {
- // when dates are equal, result is zero
- return 0;
- }
- // swap start and end if out of order
- if (startDateVal > endDateVal) {
- int temp = startDateVal;
- startDateVal = endDateVal;
- endDateVal = temp;
- }
-
- switch (basis) {
- case 0: return basis0(startDateVal, endDateVal);
- case 1: return basis1(startDateVal, endDateVal);
- case 2: return basis2(startDateVal, endDateVal);
- case 3: return basis3(startDateVal, endDateVal);
- case 4: return basis4(startDateVal, endDateVal);
- }
- throw new IllegalStateException("cannot happen");
- }
-
-
- /**
- * @param startDateVal assumed to be less than or equal to endDateVal
- * @param endDateVal assumed to be greater than or equal to startDateVal
- */
- private static double basis0(int startDateVal, int endDateVal) {
- SimpleDate startDate = createDate(startDateVal);
- SimpleDate endDate = createDate(endDateVal);
- int date1day = startDate.day;
- int date2day = endDate.day;
-
- // basis zero has funny adjustments to the day-of-month fields when at end-of-month
- if (date1day == LONG_MONTH_LEN && date2day == LONG_MONTH_LEN) {
- date1day = SHORT_MONTH_LEN;
- date2day = SHORT_MONTH_LEN;
- } else if (date1day == LONG_MONTH_LEN) {
- date1day = SHORT_MONTH_LEN;
- } else if (date1day == SHORT_MONTH_LEN && date2day == LONG_MONTH_LEN) {
- date2day = SHORT_MONTH_LEN;
- // Note: If date2day==31, it STAYS 31 if date1day < 30.
- // Special fixes for February:
- } else if (startDate.month == 2 && isLastDayOfMonth(startDate)) {
- // Note - these assignments deliberately set Feb 30 date.
- date1day = SHORT_MONTH_LEN;
- if (endDate.month == 2 && isLastDayOfMonth(endDate)) {
- // only adjusted when first date is last day in Feb
- date2day = SHORT_MONTH_LEN;
- }
- }
- return calculateAdjusted(startDate, endDate, date1day, date2day);
- }
- /**
- * @param startDateVal assumed to be less than or equal to endDateVal
- * @param endDateVal assumed to be greater than or equal to startDateVal
- */
- private static double basis1(int startDateVal, int endDateVal) {
- assert(startDateVal <= endDateVal);
- SimpleDate startDate = createDate(startDateVal);
- SimpleDate endDate = createDate(endDateVal);
- double yearLength;
- if (isGreaterThanOneYear(startDate, endDate)) {
- yearLength = averageYearLength(startDate.year, endDate.year);
- assert(yearLength > 0);
- } else if (shouldCountFeb29(startDate, endDate)) {
- yearLength = DAYS_PER_LEAP_YEAR;
- } else {
- yearLength = DAYS_PER_NORMAL_YEAR;
- }
- return dateDiff(startDate.tsMilliseconds, endDate.tsMilliseconds) / yearLength;
- }
-
- /**
- * @param startDateVal assumed to be less than or equal to endDateVal
- * @param endDateVal assumed to be greater than or equal to startDateVal
- */
- private static double basis2(int startDateVal, int endDateVal) {
- return (endDateVal - startDateVal) / 360.0;
- }
- /**
- * @param startDateVal assumed to be less than or equal to endDateVal
- * @param endDateVal assumed to be greater than or equal to startDateVal
- */
- private static double basis3(double startDateVal, double endDateVal) {
- return (endDateVal - startDateVal) / 365.0;
- }
- /**
- * @param startDateVal assumed to be less than or equal to endDateVal
- * @param endDateVal assumed to be greater than or equal to startDateVal
- */
- private static double basis4(int startDateVal, int endDateVal) {
- SimpleDate startDate = createDate(startDateVal);
- SimpleDate endDate = createDate(endDateVal);
- int date1day = startDate.day;
- int date2day = endDate.day;
-
-
- // basis four has funny adjustments to the day-of-month fields when at end-of-month
- if (date1day == LONG_MONTH_LEN) {
- date1day = SHORT_MONTH_LEN;
- }
- if (date2day == LONG_MONTH_LEN) {
- date2day = SHORT_MONTH_LEN;
- }
- // Note - no adjustments for end of Feb
- return calculateAdjusted(startDate, endDate, date1day, date2day);
- }
-
-
- private static double calculateAdjusted(SimpleDate startDate, SimpleDate endDate, int date1day,
- int date2day) {
- double dayCount
- = (endDate.year - startDate.year) * 360.0
- + (endDate.month - startDate.month) * (double)SHORT_MONTH_LEN
- + (date2day - date1day) * 1.0;
- return dayCount / 360;
- }
-
- private static boolean isLastDayOfMonth(SimpleDate date) {
- if (date.day < SHORT_FEB_LEN) {
- return false;
- }
- return date.day == getLastDayOfMonth(date);
- }
-
- private static int getLastDayOfMonth(SimpleDate date) {
- switch (date.month) {
- case 1:
- case 3:
- case 5:
- case 7:
- case 8:
- case 10:
- case 12:
- return LONG_MONTH_LEN;
- case 4:
- case 6:
- case 9:
- case 11:
- return SHORT_MONTH_LEN;
- }
- if (isLeapYear(date.year)) {
- return LONG_FEB_LEN;
- }
- return SHORT_FEB_LEN;
- }
-
- /**
- * Assumes dates are no more than 1 year apart.
- * @return <code>true</code> if dates both within a leap year, or span a period including Feb 29
- */
- private static boolean shouldCountFeb29(SimpleDate start, SimpleDate end) {
- if (isLeapYear(start.year)) {
- if (start.year == end.year) {
- // note - dates may not actually span Feb-29, but it gets counted anyway in this case
- return true;
- }
-
- switch (start.month) {
- case SimpleDate.JANUARY:
- case SimpleDate.FEBRUARY:
- return true;
- }
- return false;
- }
-
- if (isLeapYear(end.year)) {
- switch (end.month) {
- case SimpleDate.JANUARY:
- return false;
- case SimpleDate.FEBRUARY:
- break;
- default:
- return true;
- }
- return end.day == LONG_FEB_LEN;
- }
- return false;
- }
-
- /**
- * @return the whole number of days between the two time-stamps. Both time-stamps are
- * assumed to represent 12:00 midnight on the respective day.
- */
- private static int dateDiff(long startDateMS, long endDateMS) {
- long msDiff = endDateMS - startDateMS;
-
- // some extra checks to make sure we don't hide some other bug with the rounding
- int remainderHours = (int) ((msDiff % MS_PER_DAY) / MS_PER_HOUR);
- switch (remainderHours) {
- case 0: // normal case
- break;
- case 1: // transition from normal time to daylight savings adjusted
- case 23: // transition from daylight savings adjusted to normal time
- // Unexpected since we are using UTC_TIME_ZONE
- default:
- throw new RuntimeException("Unexpected date diff between " + startDateMS + " and " + endDateMS);
-
- }
- return (int) (0.5 + ((double)msDiff / MS_PER_DAY));
- }
-
- private static double averageYearLength(int startYear, int endYear) {
- assert(startYear <= endYear);
- int dayCount = 0;
- for (int i=startYear; i<=endYear; i++) {
- dayCount += isLeapYear(i) ? DAYS_PER_LEAP_YEAR : DAYS_PER_NORMAL_YEAR;
- }
- double numberOfYears = endYear-startYear+1.;
- return dayCount / numberOfYears;
- }
-
- private static boolean isLeapYear(int i) {
- // leap years are always divisible by 4
- if (i % 4 != 0) {
- return false;
- }
- // each 4th century is a leap year
- if (i % 400 == 0) {
- return true;
- }
- // all other centuries are *not* leap years
- return i % 100 != 0;
- }
-
- private static boolean isGreaterThanOneYear(SimpleDate start, SimpleDate end) {
- assert(start.year <= end.year);
- if (start.year == end.year) {
- return false;
- }
- if (start.year + 1 != end.year) {
- return true;
- }
-
- if (start.month > end.month) {
- return false;
- }
- if (start.month < end.month) {
- return true;
- }
-
- return start.day < end.day;
- }
-
- private static SimpleDate createDate(int dayCount) {
- /* use UTC time-zone to avoid daylight savings issues */
- Calendar cal = LocaleUtil.getLocaleCalendar(LocaleUtil.TIMEZONE_UTC);
- DateUtil.setCalendar(cal, dayCount, 0, false, false);
- return new SimpleDate(cal);
- }
-
- private static final class SimpleDate {
-
- public static final int JANUARY = 1;
- public static final int FEBRUARY = 2;
-
- public final int year;
- /** 1-based month */
- public final int month;
- /** day of month */
- public final int day;
- /** milliseconds since 1970 */
- public final long tsMilliseconds;
-
- public SimpleDate(Calendar cal) {
- year = cal.get(Calendar.YEAR);
- month = cal.get(Calendar.MONTH) + 1;
- day = cal.get(Calendar.DAY_OF_MONTH);
- tsMilliseconds = cal.getTimeInMillis();
- }
- }
+ private static final int MS_PER_HOUR = 60 * 60 * 1000;
+ private static final int MS_PER_DAY = 24 * MS_PER_HOUR;
+ private static final int DAYS_PER_NORMAL_YEAR = 365;
+ private static final int DAYS_PER_LEAP_YEAR = DAYS_PER_NORMAL_YEAR + 1;
+
+ /** the length of normal long months i.e. 31 */
+ private static final int LONG_MONTH_LEN = 31;
+ /** the length of normal short months i.e. 30 */
+ private static final int SHORT_MONTH_LEN = 30;
+ private static final int SHORT_FEB_LEN = 28;
+ private static final int LONG_FEB_LEN = SHORT_FEB_LEN + 1;
+
+ private YearFracCalculator() {
+ // no instances of this class
+ }
+
+
+ public static double calculate(double pStartDateVal, double pEndDateVal, int basis) throws EvaluationException {
+
+ if (basis < 0 || basis >= 5) {
+ // if basis is invalid the result is #NUM!
+ throw new EvaluationException(ErrorEval.NUM_ERROR);
+ }
+
+ // common logic for all bases
+
+ // truncate day values
+ int startDateVal = (int) Math.floor(pStartDateVal);
+ int endDateVal = (int) Math.floor(pEndDateVal);
+ if (startDateVal == endDateVal) {
+ // when dates are equal, result is zero
+ return 0;
+ }
+ // swap start and end if out of order
+ if (startDateVal > endDateVal) {
+ int temp = startDateVal;
+ startDateVal = endDateVal;
+ endDateVal = temp;
+ }
+
+ switch (basis) {
+ case 0: return basis0(startDateVal, endDateVal);
+ case 1: return basis1(startDateVal, endDateVal);
+ case 2: return basis2(startDateVal, endDateVal);
+ case 3: return basis3(startDateVal, endDateVal);
+ case 4: return basis4(startDateVal, endDateVal);
+ }
+ throw new IllegalStateException("cannot happen");
+ }
+
+
+ /**
+ * @param startDateVal assumed to be less than or equal to endDateVal
+ * @param endDateVal assumed to be greater than or equal to startDateVal
+ */
+ private static double basis0(int startDateVal, int endDateVal) {
+ SimpleDate startDate = createDate(startDateVal);
+ SimpleDate endDate = createDate(endDateVal);
+ int date1day = startDate.day;
+ int date2day = endDate.day;
+
+ // basis zero has funny adjustments to the day-of-month fields when at end-of-month
+ if (date1day == LONG_MONTH_LEN && date2day == LONG_MONTH_LEN) {
+ date1day = SHORT_MONTH_LEN;
+ date2day = SHORT_MONTH_LEN;
+ } else if (date1day == LONG_MONTH_LEN) {
+ date1day = SHORT_MONTH_LEN;
+ } else if (date1day == SHORT_MONTH_LEN && date2day == LONG_MONTH_LEN) {
+ date2day = SHORT_MONTH_LEN;
+ // Note: If date2day==31, it STAYS 31 if date1day < 30.
+ // Special fixes for February:
+ } else if (startDate.month == 2 && isLastDayOfMonth(startDate)) {
+ // Note - these assignments deliberately set Feb 30 date.
+ date1day = SHORT_MONTH_LEN;
+ if (endDate.month == 2 && isLastDayOfMonth(endDate)) {
+ // only adjusted when first date is last day in Feb
+ date2day = SHORT_MONTH_LEN;
+ }
+ }
+ return calculateAdjusted(startDate, endDate, date1day, date2day);
+ }
+ /**
+ * @param startDateVal assumed to be less than or equal to endDateVal
+ * @param endDateVal assumed to be greater than or equal to startDateVal
+ */
+ private static double basis1(int startDateVal, int endDateVal) {
+ assert(startDateVal <= endDateVal);
+ SimpleDate startDate = createDate(startDateVal);
+ SimpleDate endDate = createDate(endDateVal);
+ double yearLength;
+ if (isGreaterThanOneYear(startDate, endDate)) {
+ yearLength = averageYearLength(startDate.year, endDate.year);
+ assert(yearLength > 0);
+ } else if (shouldCountFeb29(startDate, endDate)) {
+ yearLength = DAYS_PER_LEAP_YEAR;
+ } else {
+ yearLength = DAYS_PER_NORMAL_YEAR;
+ }
+ return dateDiff(startDate.tsMilliseconds, endDate.tsMilliseconds) / yearLength;
+ }
+
+ /**
+ * @param startDateVal assumed to be less than or equal to endDateVal
+ * @param endDateVal assumed to be greater than or equal to startDateVal
+ */
+ private static double basis2(int startDateVal, int endDateVal) {
+ return (endDateVal - startDateVal) / 360.0;
+ }
+ /**
+ * @param startDateVal assumed to be less than or equal to endDateVal
+ * @param endDateVal assumed to be greater than or equal to startDateVal
+ */
+ private static double basis3(double startDateVal, double endDateVal) {
+ return (endDateVal - startDateVal) / 365.0;
+ }
+ /**
+ * @param startDateVal assumed to be less than or equal to endDateVal
+ * @param endDateVal assumed to be greater than or equal to startDateVal
+ */
+ private static double basis4(int startDateVal, int endDateVal) {
+ SimpleDate startDate = createDate(startDateVal);
+ SimpleDate endDate = createDate(endDateVal);
+ int date1day = startDate.day;
+ int date2day = endDate.day;
+
+
+ // basis four has funny adjustments to the day-of-month fields when at end-of-month
+ if (date1day == LONG_MONTH_LEN) {
+ date1day = SHORT_MONTH_LEN;
+ }
+ if (date2day == LONG_MONTH_LEN) {
+ date2day = SHORT_MONTH_LEN;
+ }
+ // Note - no adjustments for end of Feb
+ return calculateAdjusted(startDate, endDate, date1day, date2day);
+ }
+
+
+ private static double calculateAdjusted(SimpleDate startDate, SimpleDate endDate, int date1day,
+ int date2day) {
+ double dayCount
+ = (endDate.year - startDate.year) * 360.0
+ + (endDate.month - startDate.month) * (double)SHORT_MONTH_LEN
+ + (date2day - date1day) * 1.0;
+ return dayCount / 360;
+ }
+
+ private static boolean isLastDayOfMonth(SimpleDate date) {
+ if (date.day < SHORT_FEB_LEN) {
+ return false;
+ }
+ return date.day == getLastDayOfMonth(date);
+ }
+
+ private static int getLastDayOfMonth(SimpleDate date) {
+ switch (date.month) {
+ case 1:
+ case 3:
+ case 5:
+ case 7:
+ case 8:
+ case 10:
+ case 12:
+ return LONG_MONTH_LEN;
+ case 4:
+ case 6:
+ case 9:
+ case 11:
+ return SHORT_MONTH_LEN;
+ }
+ if (isLeapYear(date.year)) {
+ return LONG_FEB_LEN;
+ }
+ return SHORT_FEB_LEN;
+ }
+
+ /**
+ * Assumes dates are no more than 1 year apart.
+ * @return <code>true</code> if dates both within a leap year, or span a period including Feb 29
+ */
+ private static boolean shouldCountFeb29(SimpleDate start, SimpleDate end) {
+ if (isLeapYear(start.year)) {
+ if (start.year == end.year) {
+ // note - dates may not actually span Feb-29, but it gets counted anyway in this case
+ return true;
+ }
+
+ switch (start.month) {
+ case SimpleDate.JANUARY:
+ case SimpleDate.FEBRUARY:
+ return true;
+ }
+ return false;
+ }
+
+ if (isLeapYear(end.year)) {
+ switch (end.month) {
+ case SimpleDate.JANUARY:
+ return false;
+ case SimpleDate.FEBRUARY:
+ break;
+ default:
+ return true;
+ }
+ return end.day == LONG_FEB_LEN;
+ }
+ return false;
+ }
+
+ /**
+ * @return the whole number of days between the two time-stamps. Both time-stamps are
+ * assumed to represent 12:00 midnight on the respective day.
+ */
+ private static int dateDiff(long startDateMS, long endDateMS) {
+ long msDiff = endDateMS - startDateMS;
+
+ // some extra checks to make sure we don't hide some other bug with the rounding
+ int remainderHours = (int) ((msDiff % MS_PER_DAY) / MS_PER_HOUR);
+ switch (remainderHours) {
+ case 0: // normal case
+ break;
+ case 1: // transition from normal time to daylight savings adjusted
+ case 23: // transition from daylight savings adjusted to normal time
+ // Unexpected since we are using UTC_TIME_ZONE
+ default:
+ throw new RuntimeException("Unexpected date diff between " + startDateMS + " and " + endDateMS);
+
+ }
+ return (int) (0.5 + ((double)msDiff / MS_PER_DAY));
+ }
+
+ private static double averageYearLength(int startYear, int endYear) {
+ assert(startYear <= endYear);
+ int dayCount = 0;
+ for (int i=startYear; i<=endYear; i++) {
+ dayCount += isLeapYear(i) ? DAYS_PER_LEAP_YEAR : DAYS_PER_NORMAL_YEAR;
+ }
+ double numberOfYears = endYear-startYear+1.;
+ return dayCount / numberOfYears;
+ }
+
+ private static boolean isLeapYear(int i) {
+ // leap years are always divisible by 4
+ if (i % 4 != 0) {
+ return false;
+ }
+ // each 4th century is a leap year
+ if (i % 400 == 0) {
+ return true;
+ }
+ // all other centuries are *not* leap years
+ return i % 100 != 0;
+ }
+
+ private static boolean isGreaterThanOneYear(SimpleDate start, SimpleDate end) {
+ assert(start.year <= end.year);
+ if (start.year == end.year) {
+ return false;
+ }
+ if (start.year + 1 != end.year) {
+ return true;
+ }
+
+ if (start.month > end.month) {
+ return false;
+ }
+ if (start.month < end.month) {
+ return true;
+ }
+
+ return start.day < end.day;
+ }
+
+ private static SimpleDate createDate(int dayCount) {
+ /* use UTC time-zone to avoid daylight savings issues */
+ Calendar cal = LocaleUtil.getLocaleCalendar(LocaleUtil.TIMEZONE_UTC);
+ DateUtil.setCalendar(cal, dayCount, 0, false, false);
+ return new SimpleDate(cal);
+ }
+
+ private static final class SimpleDate {
+
+ public static final int JANUARY = 1;
+ public static final int FEBRUARY = 2;
+
+ public final int year;
+ /** 1-based month */
+ public final int month;
+ /** day of month */
+ public final int day;
+ /** milliseconds since 1970 */
+ public final long tsMilliseconds;
+
+ public SimpleDate(Calendar cal) {
+ year = cal.get(Calendar.YEAR);
+ month = cal.get(Calendar.MONTH) + 1;
+ day = cal.get(Calendar.DAY_OF_MONTH);
+ tsMilliseconds = cal.getTimeInMillis();
+ }
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/constant/ConstantValueParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/constant/ConstantValueParser.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/constant/ConstantValueParser.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/constant/ConstantValueParser.java Sat May 22 20:56:44 2021
@@ -27,129 +27,129 @@ import org.apache.poi.util.StringUtil;
* EXTERNALNAME (5.39) records and Array tokens.
*/
public final class ConstantValueParser {
- // note - these (non-combinable) enum values are sparse.
- private static final int TYPE_EMPTY = 0;
- private static final int TYPE_NUMBER = 1;
- private static final int TYPE_STRING = 2;
- private static final int TYPE_BOOLEAN = 4;
- private static final int TYPE_ERROR_CODE = 16; // TODO - update OOO document to include this value
-
- private static final int TRUE_ENCODING = 1;
- private static final int FALSE_ENCODING = 0;
-
- // TODO - is this the best way to represent 'EMPTY'?
- private static final Object EMPTY_REPRESENTATION = null;
-
- private ConstantValueParser() {
- // no instances of this class
- }
-
- public static Object[] parse(LittleEndianInput in, int nValues) {
- Object[] result = new Object[nValues];
- for (int i = 0; i < result.length; i++) {
- result[i] = readAConstantValue(in);
- }
- return result;
- }
-
- private static Object readAConstantValue(LittleEndianInput in) {
- byte grbit = in.readByte();
- switch(grbit) {
- case TYPE_EMPTY:
- in.readLong(); // 8 byte 'not used' field
- return EMPTY_REPRESENTATION;
- case TYPE_NUMBER:
- return in.readDouble();
- case TYPE_STRING:
- return StringUtil.readUnicodeString(in);
- case TYPE_BOOLEAN:
- return readBoolean(in);
- case TYPE_ERROR_CODE:
- int errCode = in.readUShort();
- // next 6 bytes are unused
- in.readUShort();
- in.readInt();
- return ErrorConstant.valueOf(errCode);
- }
- throw new RuntimeException("Unknown grbit value (" + grbit + ")");
- }
-
- private static Object readBoolean(LittleEndianInput in) {
- byte val = (byte)in.readLong(); // 7 bytes 'not used'
- switch(val) {
- case FALSE_ENCODING:
- return Boolean.FALSE;
- case TRUE_ENCODING:
- return Boolean.TRUE;
- }
- // Don't tolerate unusual boolean encoded values (unless it becomes evident that they occur)
- throw new RuntimeException("unexpected boolean encoding (" + val + ")");
- }
-
- public static int getEncodedSize(Object[] values) {
- // start with one byte 'type' code for each value
- int result = values.length;
- for (Object value : values) {
- result += getEncodedSize(value);
- }
- return result;
- }
-
- /**
- * @return encoded size without the 'type' code byte
- */
- private static int getEncodedSize(Object object) {
- if(object == EMPTY_REPRESENTATION) {
- return 8;
- }
- Class<?> cls = object.getClass();
-
- if(cls == Boolean.class || cls == Double.class || cls == ErrorConstant.class) {
- return 8;
- }
- String strVal = (String)object;
- return StringUtil.getEncodedSize(strVal);
- }
-
- public static void encode(LittleEndianOutput out, Object[] values) {
- for (Object value : values) {
- encodeSingleValue(out, value);
- }
- }
-
- private static void encodeSingleValue(LittleEndianOutput out, Object value) {
- if (value == EMPTY_REPRESENTATION) {
- out.writeByte(TYPE_EMPTY);
- out.writeLong(0L);
- return;
- }
- if (value instanceof Boolean) {
- Boolean bVal = ((Boolean)value);
- out.writeByte(TYPE_BOOLEAN);
- long longVal = bVal ? 1L : 0L;
- out.writeLong(longVal);
- return;
- }
- if (value instanceof Double) {
- Double dVal = (Double) value;
- out.writeByte(TYPE_NUMBER);
- out.writeDouble(dVal);
- return;
- }
- if (value instanceof String) {
- String val = (String) value;
- out.writeByte(TYPE_STRING);
- StringUtil.writeUnicodeString(out, val);
- return;
- }
- if (value instanceof ErrorConstant) {
- ErrorConstant ecVal = (ErrorConstant) value;
- out.writeByte(TYPE_ERROR_CODE);
- long longVal = ecVal.getErrorCode();
- out.writeLong(longVal);
- return;
- }
+ // note - these (non-combinable) enum values are sparse.
+ private static final int TYPE_EMPTY = 0;
+ private static final int TYPE_NUMBER = 1;
+ private static final int TYPE_STRING = 2;
+ private static final int TYPE_BOOLEAN = 4;
+ private static final int TYPE_ERROR_CODE = 16; // TODO - update OOO document to include this value
+
+ private static final int TRUE_ENCODING = 1;
+ private static final int FALSE_ENCODING = 0;
+
+ // TODO - is this the best way to represent 'EMPTY'?
+ private static final Object EMPTY_REPRESENTATION = null;
+
+ private ConstantValueParser() {
+ // no instances of this class
+ }
+
+ public static Object[] parse(LittleEndianInput in, int nValues) {
+ Object[] result = new Object[nValues];
+ for (int i = 0; i < result.length; i++) {
+ result[i] = readAConstantValue(in);
+ }
+ return result;
+ }
+
+ private static Object readAConstantValue(LittleEndianInput in) {
+ byte grbit = in.readByte();
+ switch(grbit) {
+ case TYPE_EMPTY:
+ in.readLong(); // 8 byte 'not used' field
+ return EMPTY_REPRESENTATION;
+ case TYPE_NUMBER:
+ return in.readDouble();
+ case TYPE_STRING:
+ return StringUtil.readUnicodeString(in);
+ case TYPE_BOOLEAN:
+ return readBoolean(in);
+ case TYPE_ERROR_CODE:
+ int errCode = in.readUShort();
+ // next 6 bytes are unused
+ in.readUShort();
+ in.readInt();
+ return ErrorConstant.valueOf(errCode);
+ }
+ throw new RuntimeException("Unknown grbit value (" + grbit + ")");
+ }
+
+ private static Object readBoolean(LittleEndianInput in) {
+ byte val = (byte)in.readLong(); // 7 bytes 'not used'
+ switch(val) {
+ case FALSE_ENCODING:
+ return Boolean.FALSE;
+ case TRUE_ENCODING:
+ return Boolean.TRUE;
+ }
+ // Don't tolerate unusual boolean encoded values (unless it becomes evident that they occur)
+ throw new RuntimeException("unexpected boolean encoding (" + val + ")");
+ }
+
+ public static int getEncodedSize(Object[] values) {
+ // start with one byte 'type' code for each value
+ int result = values.length;
+ for (Object value : values) {
+ result += getEncodedSize(value);
+ }
+ return result;
+ }
+
+ /**
+ * @return encoded size without the 'type' code byte
+ */
+ private static int getEncodedSize(Object object) {
+ if(object == EMPTY_REPRESENTATION) {
+ return 8;
+ }
+ Class<?> cls = object.getClass();
+
+ if(cls == Boolean.class || cls == Double.class || cls == ErrorConstant.class) {
+ return 8;
+ }
+ String strVal = (String)object;
+ return StringUtil.getEncodedSize(strVal);
+ }
+
+ public static void encode(LittleEndianOutput out, Object[] values) {
+ for (Object value : values) {
+ encodeSingleValue(out, value);
+ }
+ }
+
+ private static void encodeSingleValue(LittleEndianOutput out, Object value) {
+ if (value == EMPTY_REPRESENTATION) {
+ out.writeByte(TYPE_EMPTY);
+ out.writeLong(0L);
+ return;
+ }
+ if (value instanceof Boolean) {
+ Boolean bVal = ((Boolean)value);
+ out.writeByte(TYPE_BOOLEAN);
+ long longVal = bVal ? 1L : 0L;
+ out.writeLong(longVal);
+ return;
+ }
+ if (value instanceof Double) {
+ Double dVal = (Double) value;
+ out.writeByte(TYPE_NUMBER);
+ out.writeDouble(dVal);
+ return;
+ }
+ if (value instanceof String) {
+ String val = (String) value;
+ out.writeByte(TYPE_STRING);
+ StringUtil.writeUnicodeString(out, val);
+ return;
+ }
+ if (value instanceof ErrorConstant) {
+ ErrorConstant ecVal = (ErrorConstant) value;
+ out.writeByte(TYPE_ERROR_CODE);
+ long longVal = ecVal.getErrorCode();
+ out.writeLong(longVal);
+ return;
+ }
- throw new IllegalStateException("Unexpected value type (" + value.getClass().getName() + "'");
- }
+ throw new IllegalStateException("Unexpected value type (" + value.getClass().getName() + "'");
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/constant/ErrorConstant.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/constant/ErrorConstant.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/constant/ErrorConstant.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/constant/ErrorConstant.java Sat May 22 20:56:44 2021
@@ -30,8 +30,8 @@ import static org.apache.logging.log4j.u
* {@code ErrorEval}.
*/
public final class ErrorConstant {
- private static final Logger LOG = LogManager.getLogger(ErrorConstant.class);
- private static final ErrorConstant NULL = new ErrorConstant(FormulaError.NULL.getCode());
+ private static final Logger LOG = LogManager.getLogger(ErrorConstant.class);
+ private static final ErrorConstant NULL = new ErrorConstant(FormulaError.NULL.getCode());
private static final ErrorConstant DIV_0 = new ErrorConstant(FormulaError.DIV0.getCode());
private static final ErrorConstant VALUE = new ErrorConstant(FormulaError.VALUE.getCode());
private static final ErrorConstant REF = new ErrorConstant(FormulaError.REF.getCode());
@@ -39,41 +39,41 @@ public final class ErrorConstant {
private static final ErrorConstant NUM = new ErrorConstant(FormulaError.NUM.getCode());
private static final ErrorConstant NA = new ErrorConstant(FormulaError.NA.getCode());
- private final int _errorCode;
+ private final int _errorCode;
- private ErrorConstant(int errorCode) {
- _errorCode = errorCode;
- }
-
- public int getErrorCode() {
- return _errorCode;
- }
-
- public String getText() {
- if(FormulaError.isValidCode(_errorCode)) {
- return FormulaError.forInt(_errorCode).getString();
- }
- return "unknown error code (" + _errorCode + ")";
- }
-
- public static ErrorConstant valueOf(int errorCode) {
- if (FormulaError.isValidCode(errorCode)) {
- switch (FormulaError.forInt(errorCode)) {
- case NULL: return NULL;
- case DIV0: return DIV_0;
- case VALUE: return VALUE;
- case REF: return REF;
- case NAME: return NAME;
- case NUM: return NUM;
- case NA: return NA;
- default: break;
- }
- }
- LOG.atWarn().log("Warning - unexpected error code ({})", box(errorCode));
- return new ErrorConstant(errorCode);
- }
-
- public String toString() {
- return getClass().getName() + " [" + getText() + "]";
- }
+ private ErrorConstant(int errorCode) {
+ _errorCode = errorCode;
+ }
+
+ public int getErrorCode() {
+ return _errorCode;
+ }
+
+ public String getText() {
+ if(FormulaError.isValidCode(_errorCode)) {
+ return FormulaError.forInt(_errorCode).getString();
+ }
+ return "unknown error code (" + _errorCode + ")";
+ }
+
+ public static ErrorConstant valueOf(int errorCode) {
+ if (FormulaError.isValidCode(errorCode)) {
+ switch (FormulaError.forInt(errorCode)) {
+ case NULL: return NULL;
+ case DIV0: return DIV_0;
+ case VALUE: return VALUE;
+ case REF: return REF;
+ case NAME: return NAME;
+ case NUM: return NUM;
+ case NA: return NA;
+ default: break;
+ }
+ }
+ LOG.atWarn().log("Warning - unexpected error code ({})", box(errorCode));
+ return new ErrorConstant(errorCode);
+ }
+
+ public String toString() {
+ return getClass().getName() + " [" + getText() + "]";
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/AreaEvalBase.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/AreaEvalBase.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/AreaEvalBase.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/AreaEvalBase.java Sat May 22 20:56:44 2021
@@ -23,141 +23,141 @@ import org.apache.poi.ss.formula.ptg.Are
public abstract class AreaEvalBase implements AreaEval {
private final int _firstSheet;
- private final int _firstColumn;
- private final int _firstRow;
+ private final int _firstColumn;
+ private final int _firstRow;
private final int _lastSheet;
- private final int _lastColumn;
- private final int _lastRow;
- private final int _nColumns;
- private final int _nRows;
-
- protected AreaEvalBase(SheetRange sheets, int firstRow, int firstColumn, int lastRow, int lastColumn) {
- _firstColumn = firstColumn;
- _firstRow = firstRow;
- _lastColumn = lastColumn;
- _lastRow = lastRow;
-
- _nColumns = _lastColumn - _firstColumn + 1;
- _nRows = _lastRow - _firstRow + 1;
-
- if (sheets != null) {
- _firstSheet = sheets.getFirstSheetIndex();
- _lastSheet = sheets.getLastSheetIndex();
- } else {
- _firstSheet = -1;
- _lastSheet = -1;
- }
- }
+ private final int _lastColumn;
+ private final int _lastRow;
+ private final int _nColumns;
+ private final int _nRows;
+
+ protected AreaEvalBase(SheetRange sheets, int firstRow, int firstColumn, int lastRow, int lastColumn) {
+ _firstColumn = firstColumn;
+ _firstRow = firstRow;
+ _lastColumn = lastColumn;
+ _lastRow = lastRow;
+
+ _nColumns = _lastColumn - _firstColumn + 1;
+ _nRows = _lastRow - _firstRow + 1;
+
+ if (sheets != null) {
+ _firstSheet = sheets.getFirstSheetIndex();
+ _lastSheet = sheets.getLastSheetIndex();
+ } else {
+ _firstSheet = -1;
+ _lastSheet = -1;
+ }
+ }
protected AreaEvalBase(int firstRow, int firstColumn, int lastRow, int lastColumn) {
this(null, firstRow, firstColumn, lastRow, lastColumn);
}
- protected AreaEvalBase(AreaI ptg) {
- this(ptg, null);
- }
+ protected AreaEvalBase(AreaI ptg) {
+ this(ptg, null);
+ }
protected AreaEvalBase(AreaI ptg, SheetRange sheets) {
- this(sheets, ptg.getFirstRow(), ptg.getFirstColumn(), ptg.getLastRow(), ptg.getLastColumn());
- }
+ this(sheets, ptg.getFirstRow(), ptg.getFirstColumn(), ptg.getLastRow(), ptg.getLastColumn());
+ }
+
+ @Override
+ public final int getFirstColumn() {
+ return _firstColumn;
+ }
+
+ @Override
+ public final int getFirstRow() {
+ return _firstRow;
+ }
+
+ @Override
+ public final int getLastColumn() {
+ return _lastColumn;
+ }
+
+ @Override
+ public final int getLastRow() {
+ return _lastRow;
+ }
- @Override
- public final int getFirstColumn() {
- return _firstColumn;
- }
-
- @Override
- public final int getFirstRow() {
- return _firstRow;
- }
-
- @Override
- public final int getLastColumn() {
- return _lastColumn;
- }
-
- @Override
- public final int getLastRow() {
- return _lastRow;
- }
-
- @Override
- public int getFirstSheetIndex() {
- return _firstSheet;
+ @Override
+ public int getFirstSheetIndex() {
+ return _firstSheet;
}
@Override
- public int getLastSheetIndex() {
+ public int getLastSheetIndex() {
return _lastSheet;
}
@Override
- public final ValueEval getAbsoluteValue(int row, int col) {
- int rowOffsetIx = row - _firstRow;
- int colOffsetIx = col - _firstColumn;
-
- if(rowOffsetIx < 0 || rowOffsetIx >= _nRows) {
- throw new IllegalArgumentException("Specified row index (" + row
- + ") is outside the allowed range (" + _firstRow + ".." + _lastRow + ")");
- }
- if(colOffsetIx < 0 || colOffsetIx >= _nColumns) {
- throw new IllegalArgumentException("Specified column index (" + col
- + ") is outside the allowed range (" + _firstColumn + ".." + col + ")");
- }
- return getRelativeValue(rowOffsetIx, colOffsetIx);
- }
-
- @Override
- public final boolean contains(int row, int col) {
- return _firstRow <= row && _lastRow >= row
- && _firstColumn <= col && _lastColumn >= col;
- }
-
- @Override
- public final boolean containsRow(int row) {
- return _firstRow <= row && _lastRow >= row;
- }
-
- @Override
- public final boolean containsColumn(int col) {
- return _firstColumn <= col && _lastColumn >= col;
- }
-
- @Override
- public final boolean isColumn() {
- return _firstColumn == _lastColumn;
- }
-
- @Override
- public final boolean isRow() {
- return _firstRow == _lastRow;
- }
- @Override
- public int getHeight() {
- return _lastRow-_firstRow+1;
- }
+ public final ValueEval getAbsoluteValue(int row, int col) {
+ int rowOffsetIx = row - _firstRow;
+ int colOffsetIx = col - _firstColumn;
+
+ if(rowOffsetIx < 0 || rowOffsetIx >= _nRows) {
+ throw new IllegalArgumentException("Specified row index (" + row
+ + ") is outside the allowed range (" + _firstRow + ".." + _lastRow + ")");
+ }
+ if(colOffsetIx < 0 || colOffsetIx >= _nColumns) {
+ throw new IllegalArgumentException("Specified column index (" + col
+ + ") is outside the allowed range (" + _firstColumn + ".." + col + ")");
+ }
+ return getRelativeValue(rowOffsetIx, colOffsetIx);
+ }
+
+ @Override
+ public final boolean contains(int row, int col) {
+ return _firstRow <= row && _lastRow >= row
+ && _firstColumn <= col && _lastColumn >= col;
+ }
- @Override
+ @Override
+ public final boolean containsRow(int row) {
+ return _firstRow <= row && _lastRow >= row;
+ }
+
+ @Override
+ public final boolean containsColumn(int col) {
+ return _firstColumn <= col && _lastColumn >= col;
+ }
+
+ @Override
+ public final boolean isColumn() {
+ return _firstColumn == _lastColumn;
+ }
+
+ @Override
+ public final boolean isRow() {
+ return _firstRow == _lastRow;
+ }
+ @Override
+ public int getHeight() {
+ return _lastRow-_firstRow+1;
+ }
+
+ @Override
public final ValueEval getValue(int row, int col) {
- return getRelativeValue(row, col);
- }
+ return getRelativeValue(row, col);
+ }
@Override
- public final ValueEval getValue(int sheetIndex, int row, int col) {
+ public final ValueEval getValue(int sheetIndex, int row, int col) {
return getRelativeValue(sheetIndex, row, col);
}
- @Override
- public abstract ValueEval getRelativeValue(int relativeRowIndex, int relativeColumnIndex);
+ @Override
+ public abstract ValueEval getRelativeValue(int relativeRowIndex, int relativeColumnIndex);
public abstract ValueEval getRelativeValue(int sheetIndex, int relativeRowIndex, int relativeColumnIndex);
- @Override
- public int getWidth() {
- return _lastColumn-_firstColumn+1;
- }
+ @Override
+ public int getWidth() {
+ return _lastColumn-_firstColumn+1;
+ }
/**
* @return whether cell at rowIndex and columnIndex is a subtotal.
* By default return false which means 'don't care about subtotals'
*/
@Override
- public boolean isSubTotal(int rowIndex, int columnIndex) {
+ public boolean isSubTotal(int rowIndex, int columnIndex) {
return false;
}
@@ -166,7 +166,7 @@ public abstract class AreaEvalBase imple
* @see org.apache.poi.ss.formula.TwoDEval#isRowHidden(int)
*/
@Override
- public boolean isRowHidden(int rowIndex) {
+ public boolean isRowHidden(int rowIndex) {
return false;
}
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/BlankEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/BlankEval.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/BlankEval.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/BlankEval.java Sat May 22 20:56:44 2021
@@ -22,9 +22,9 @@ package org.apache.poi.ss.formula.eval;
*/
public final class BlankEval implements ValueEval {
- public static final BlankEval instance = new BlankEval();
+ public static final BlankEval instance = new BlankEval();
- private BlankEval() {
- // enforce singleton
- }
+ private BlankEval() {
+ // enforce singleton
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/BoolEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/BoolEval.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/BoolEval.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/BoolEval.java Sat May 22 20:56:44 2021
@@ -19,43 +19,43 @@ package org.apache.poi.ss.formula.eval;
public final class BoolEval implements NumericValueEval, StringValueEval {
- private final boolean _value;
+ private final boolean _value;
- public static final BoolEval FALSE = new BoolEval(false);
+ public static final BoolEval FALSE = new BoolEval(false);
- public static final BoolEval TRUE = new BoolEval(true);
+ public static final BoolEval TRUE = new BoolEval(true);
- /**
- * Convenience method for the following:<br>
- * {@code (b ? BoolEval.TRUE : BoolEval.FALSE)}
- *
- * @return the {@code BoolEval} instance representing {@code b}.
- */
- public static BoolEval valueOf(boolean b) {
- return b ? TRUE : FALSE;
- }
-
- private BoolEval(boolean value) {
- _value = value;
- }
-
- public boolean getBooleanValue() {
- return _value;
- }
-
- @Override
- public double getNumberValue() {
- return _value ? 1 : 0;
- }
-
- @Override
- public String getStringValue() {
- return _value ? "TRUE" : "FALSE";
- }
-
- public String toString() {
- return getClass().getName() + " [" +
- getStringValue() +
- "]";
- }
+ /**
+ * Convenience method for the following:<br>
+ * {@code (b ? BoolEval.TRUE : BoolEval.FALSE)}
+ *
+ * @return the {@code BoolEval} instance representing {@code b}.
+ */
+ public static BoolEval valueOf(boolean b) {
+ return b ? TRUE : FALSE;
+ }
+
+ private BoolEval(boolean value) {
+ _value = value;
+ }
+
+ public boolean getBooleanValue() {
+ return _value;
+ }
+
+ @Override
+ public double getNumberValue() {
+ return _value ? 1 : 0;
+ }
+
+ @Override
+ public String getStringValue() {
+ return _value ? "TRUE" : "FALSE";
+ }
+
+ public String toString() {
+ return getClass().getName() + " [" +
+ getStringValue() +
+ "]";
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/ConcatEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/ConcatEval.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/ConcatEval.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/ConcatEval.java Sat May 22 20:56:44 2021
@@ -22,36 +22,36 @@ import org.apache.poi.ss.formula.functio
public final class ConcatEval extends Fixed2ArgFunction {
- public static final Function instance = new ConcatEval();
+ public static final Function instance = new ConcatEval();
- private ConcatEval() {
- // enforce singleton
- }
+ private ConcatEval() {
+ // enforce singleton
+ }
- public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1) {
- ValueEval ve0;
- ValueEval ve1;
- try {
- ve0 = OperandResolver.getSingleValue(arg0, srcRowIndex, srcColumnIndex);
- ve1 = OperandResolver.getSingleValue(arg1, srcRowIndex, srcColumnIndex);
- } catch (EvaluationException e) {
- return e.getErrorEval();
- }
- StringBuilder sb = new StringBuilder();
- sb.append(getText(ve0));
- sb.append(getText(ve1));
- return new StringEval(sb.toString());
- }
+ public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1) {
+ ValueEval ve0;
+ ValueEval ve1;
+ try {
+ ve0 = OperandResolver.getSingleValue(arg0, srcRowIndex, srcColumnIndex);
+ ve1 = OperandResolver.getSingleValue(arg1, srcRowIndex, srcColumnIndex);
+ } catch (EvaluationException e) {
+ return e.getErrorEval();
+ }
+ StringBuilder sb = new StringBuilder();
+ sb.append(getText(ve0));
+ sb.append(getText(ve1));
+ return new StringEval(sb.toString());
+ }
- private Object getText(ValueEval ve) {
- if (ve instanceof StringValueEval) {
- StringValueEval sve = (StringValueEval) ve;
- return sve.getStringValue();
- }
- if (ve == BlankEval.instance) {
- return "";
- }
- throw new IllegalAccessError("Unexpected value type ("
- + ve.getClass().getName() + ")");
- }
+ private Object getText(ValueEval ve) {
+ if (ve instanceof StringValueEval) {
+ StringValueEval sve = (StringValueEval) ve;
+ return sve.getStringValue();
+ }
+ if (ve == BlankEval.instance) {
+ return "";
+ }
+ throw new IllegalAccessError("Unexpected value type ("
+ + ve.getClass().getName() + ")");
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/EvaluationException.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/EvaluationException.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/EvaluationException.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/EvaluationException.java Sat May 22 20:56:44 2021
@@ -25,28 +25,28 @@ package org.apache.poi.ss.formula.eval;
* Here is an example coded without {@code EvaluationException}, to show how it can help:
* <pre>{@code
* public Eval evaluate(Eval[] args, int srcRow, short srcCol) {
- * // ...
- * Eval arg0 = args[0];
- * if(arg0 instanceof ErrorEval) {
- * return arg0;
- * }
- * if(!(arg0 instanceof AreaEval)) {
- * return ErrorEval.VALUE_INVALID;
- * }
- * double temp = 0;
- * AreaEval area = (AreaEval)arg0;
- * ValueEval[] values = area.getValues();
- * for (int i = 0; i < values.length; i++) {
- * ValueEval ve = values[i];
- * if(ve instanceof ErrorEval) {
- * return ve;
- * }
- * if(!(ve instanceof NumericValueEval)) {
- * return ErrorEval.VALUE_INVALID;
- * }
- * temp += ((NumericValueEval)ve).getNumberValue();
- * }
- * // ...
+ * // ...
+ * Eval arg0 = args[0];
+ * if(arg0 instanceof ErrorEval) {
+ * return arg0;
+ * }
+ * if(!(arg0 instanceof AreaEval)) {
+ * return ErrorEval.VALUE_INVALID;
+ * }
+ * double temp = 0;
+ * AreaEval area = (AreaEval)arg0;
+ * ValueEval[] values = area.getValues();
+ * for (int i = 0; i < values.length; i++) {
+ * ValueEval ve = values[i];
+ * if(ve instanceof ErrorEval) {
+ * return ve;
+ * }
+ * if(!(ve instanceof NumericValueEval)) {
+ * return ErrorEval.VALUE_INVALID;
+ * }
+ * temp += ((NumericValueEval)ve).getNumberValue();
+ * }
+ * // ...
* }
* }</pre>
* In this example, if any error is encountered while processing the arguments, an error is
@@ -57,39 +57,39 @@ package org.apache.poi.ss.formula.eval;
*
* <pre>{@code
* public Eval evaluate(Eval[] args, int srcRow, short srcCol) {
- * try {
- * // ...
- * AreaEval area = getAreaArg(args[0]);
- * double temp = sumValues(area.getValues());
- * // ...
- * } catch (EvaluationException e) {
- * return e.getErrorEval();
- * }
+ * try {
+ * // ...
+ * AreaEval area = getAreaArg(args[0]);
+ * double temp = sumValues(area.getValues());
+ * // ...
+ * } catch (EvaluationException e) {
+ * return e.getErrorEval();
+ * }
*}
*
*private static AreaEval getAreaArg(Eval arg0) throws EvaluationException {
- * if (arg0 instanceof ErrorEval) {
- * throw new EvaluationException((ErrorEval) arg0);
- * }
- * if (arg0 instanceof AreaEval) {
- * return (AreaEval) arg0;
- * }
- * throw EvaluationException.invalidValue();
+ * if (arg0 instanceof ErrorEval) {
+ * throw new EvaluationException((ErrorEval) arg0);
+ * }
+ * if (arg0 instanceof AreaEval) {
+ * return (AreaEval) arg0;
+ * }
+ * throw EvaluationException.invalidValue();
*}
*
*private double sumValues(ValueEval[] values) throws EvaluationException {
- * double temp = 0;
- * for (int i = 0; i < values.length; i++) {
- * ValueEval ve = values[i];
- * if (ve instanceof ErrorEval) {
- * throw new EvaluationException((ErrorEval) ve);
- * }
- * if (!(ve instanceof NumericValueEval)) {
- * throw EvaluationException.invalidValue();
- * }
- * temp += ((NumericValueEval) ve).getNumberValue();
- * }
- * return temp;
+ * double temp = 0;
+ * for (int i = 0; i < values.length; i++) {
+ * ValueEval ve = values[i];
+ * if (ve instanceof ErrorEval) {
+ * throw new EvaluationException((ErrorEval) ve);
+ * }
+ * if (!(ve instanceof NumericValueEval)) {
+ * throw EvaluationException.invalidValue();
+ * }
+ * temp += ((NumericValueEval) ve).getNumberValue();
+ * }
+ * return temp;
*}
* }</pre>
* It is not mandatory to use EvaluationException, doing so might give the following advantages:<br>
@@ -107,27 +107,27 @@ package org.apache.poi.ss.formula.eval;
* be taken to not translate any POI internal error into an Excel evaluation error code.
*/
public final class EvaluationException extends Exception {
- private final ErrorEval _errorEval;
+ private final ErrorEval _errorEval;
- public EvaluationException(ErrorEval errorEval) {
- _errorEval = errorEval;
- }
- // some convenience factory methods
+ public EvaluationException(ErrorEval errorEval) {
+ _errorEval = errorEval;
+ }
+ // some convenience factory methods
/** <b>#VALUE!</b> - Wrong type of operand */
- public static EvaluationException invalidValue() {
- return new EvaluationException(ErrorEval.VALUE_INVALID);
- }
+ public static EvaluationException invalidValue() {
+ return new EvaluationException(ErrorEval.VALUE_INVALID);
+ }
/** <b>#REF!</b> - Illegal or deleted cell reference */
- public static EvaluationException invalidRef() {
- return new EvaluationException(ErrorEval.REF_INVALID);
- }
+ public static EvaluationException invalidRef() {
+ return new EvaluationException(ErrorEval.REF_INVALID);
+ }
/** <b>#NUM!</b> - Value range overflow */
- public static EvaluationException numberError() {
- return new EvaluationException(ErrorEval.NUM_ERROR);
- }
+ public static EvaluationException numberError() {
+ return new EvaluationException(ErrorEval.NUM_ERROR);
+ }
- public ErrorEval getErrorEval() {
- return _errorEval;
- }
+ public ErrorEval getErrorEval() {
+ return _errorEval;
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/ExternalNameEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/ExternalNameEval.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/ExternalNameEval.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/ExternalNameEval.java Sat May 22 20:56:44 2021
@@ -23,19 +23,19 @@ import org.apache.poi.ss.formula.Evaluat
* Evaluation of a Name defined in a Sheet or Workbook scope
*/
public final class ExternalNameEval implements ValueEval {
- private final EvaluationName _name;
+ private final EvaluationName _name;
- public ExternalNameEval(EvaluationName name) {
- _name = name;
- }
+ public ExternalNameEval(EvaluationName name) {
+ _name = name;
+ }
- public EvaluationName getName() {
- return _name;
- }
+ public EvaluationName getName() {
+ return _name;
+ }
- public String toString() {
- return getClass().getName() + " [" +
- _name.getNameText() +
- "]";
- }
+ public String toString() {
+ return getClass().getName() + " [" +
+ _name.getNameText() +
+ "]";
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/FunctionNameEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/FunctionNameEval.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/FunctionNameEval.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/FunctionNameEval.java Sat May 22 20:56:44 2021
@@ -19,23 +19,23 @@ package org.apache.poi.ss.formula.eval;
public final class FunctionNameEval implements ValueEval {
- private final String _functionName;
+ private final String _functionName;
- /**
- * Creates a NameEval representing a function name
- */
- public FunctionNameEval(String functionName) {
- _functionName = functionName;
- }
-
-
- public String getFunctionName() {
- return _functionName;
- }
-
- public String toString() {
- return getClass().getName() + " [" +
- _functionName +
- "]";
- }
+ /**
+ * Creates a NameEval representing a function name
+ */
+ public FunctionNameEval(String functionName) {
+ _functionName = functionName;
+ }
+
+
+ public String getFunctionName() {
+ return _functionName;
+ }
+
+ public String toString() {
+ return getClass().getName() + " [" +
+ _functionName +
+ "]";
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/IntersectionEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/IntersectionEval.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/IntersectionEval.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/IntersectionEval.java Sat May 22 20:56:44 2021
@@ -22,73 +22,73 @@ import org.apache.poi.ss.formula.functio
public final class IntersectionEval extends Fixed2ArgFunction {
- public static final Function instance = new IntersectionEval();
+ public static final Function instance = new IntersectionEval();
- private IntersectionEval() {
- // enforces singleton
- }
-
- @Override
- public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1) {
-
- try {
- AreaEval reA = evaluateRef(arg0);
- AreaEval reB = evaluateRef(arg1);
- AreaEval result = resolveRange(reA, reB);
- if (result == null) {
- return ErrorEval.NULL_INTERSECTION;
- }
- return result;
- } catch (EvaluationException e) {
- return e.getErrorEval();
- }
- }
-
- /**
- * @return simple rectangular {@link AreaEval} which represents the intersection of areas
- * {@code aeA} and {@code aeB}. If the two areas do not intersect, the result is {@code null}.
- */
- private static AreaEval resolveRange(AreaEval aeA, AreaEval aeB) {
-
- int aeAfr = aeA.getFirstRow();
- int aeAfc = aeA.getFirstColumn();
- int aeBlc = aeB.getLastColumn();
- if (aeAfc > aeBlc) {
- return null;
- }
- int aeBfc = aeB.getFirstColumn();
- if (aeBfc > aeA.getLastColumn()) {
- return null;
- }
- int aeBlr = aeB.getLastRow();
- if (aeAfr > aeBlr) {
- return null;
- }
- int aeBfr = aeB.getFirstRow();
- int aeAlr = aeA.getLastRow();
- if (aeBfr > aeAlr) {
- return null;
- }
-
-
- int top = Math.max(aeAfr, aeBfr);
- int bottom = Math.min(aeAlr, aeBlr);
- int left = Math.max(aeAfc, aeBfc);
- int right = Math.min(aeA.getLastColumn(), aeBlc);
-
- return aeA.offset(top-aeAfr, bottom-aeAfr, left-aeAfc, right-aeAfc);
- }
-
- private static AreaEval evaluateRef(ValueEval arg) throws EvaluationException {
- if (arg instanceof AreaEval) {
- return (AreaEval) arg;
- }
- if (arg instanceof RefEval) {
- return ((RefEval) arg).offset(0, 0, 0, 0);
- }
- if (arg instanceof ErrorEval) {
- throw new EvaluationException((ErrorEval)arg);
- }
- throw new IllegalArgumentException("Unexpected ref arg class (" + arg.getClass().getName() + ")");
- }
+ private IntersectionEval() {
+ // enforces singleton
+ }
+
+ @Override
+ public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1) {
+
+ try {
+ AreaEval reA = evaluateRef(arg0);
+ AreaEval reB = evaluateRef(arg1);
+ AreaEval result = resolveRange(reA, reB);
+ if (result == null) {
+ return ErrorEval.NULL_INTERSECTION;
+ }
+ return result;
+ } catch (EvaluationException e) {
+ return e.getErrorEval();
+ }
+ }
+
+ /**
+ * @return simple rectangular {@link AreaEval} which represents the intersection of areas
+ * {@code aeA} and {@code aeB}. If the two areas do not intersect, the result is {@code null}.
+ */
+ private static AreaEval resolveRange(AreaEval aeA, AreaEval aeB) {
+
+ int aeAfr = aeA.getFirstRow();
+ int aeAfc = aeA.getFirstColumn();
+ int aeBlc = aeB.getLastColumn();
+ if (aeAfc > aeBlc) {
+ return null;
+ }
+ int aeBfc = aeB.getFirstColumn();
+ if (aeBfc > aeA.getLastColumn()) {
+ return null;
+ }
+ int aeBlr = aeB.getLastRow();
+ if (aeAfr > aeBlr) {
+ return null;
+ }
+ int aeBfr = aeB.getFirstRow();
+ int aeAlr = aeA.getLastRow();
+ if (aeBfr > aeAlr) {
+ return null;
+ }
+
+
+ int top = Math.max(aeAfr, aeBfr);
+ int bottom = Math.min(aeAlr, aeBlr);
+ int left = Math.max(aeAfc, aeBfc);
+ int right = Math.min(aeA.getLastColumn(), aeBlc);
+
+ return aeA.offset(top-aeAfr, bottom-aeAfr, left-aeAfc, right-aeAfc);
+ }
+
+ private static AreaEval evaluateRef(ValueEval arg) throws EvaluationException {
+ if (arg instanceof AreaEval) {
+ return (AreaEval) arg;
+ }
+ if (arg instanceof RefEval) {
+ return ((RefEval) arg).offset(0, 0, 0, 0);
+ }
+ if (arg instanceof ErrorEval) {
+ throw new EvaluationException((ErrorEval)arg);
+ }
+ throw new IllegalArgumentException("Unexpected ref arg class (" + arg.getClass().getName() + ")");
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/MissingArgEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/MissingArgEval.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/MissingArgEval.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/MissingArgEval.java Sat May 22 20:56:44 2021
@@ -26,9 +26,9 @@ package org.apache.poi.ss.formula.eval;
*/
public final class MissingArgEval implements ValueEval {
- public static final MissingArgEval instance = new MissingArgEval();
+ public static final MissingArgEval instance = new MissingArgEval();
- private MissingArgEval() {
- // enforce singleton
- }
+ private MissingArgEval() {
+ // enforce singleton
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/NotImplementedException.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/NotImplementedException.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/NotImplementedException.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/NotImplementedException.java Sat May 22 20:56:44 2021
@@ -32,9 +32,9 @@ public class NotImplementedException ext
private static final long serialVersionUID = -5840703336495141301L;
public NotImplementedException(String message) {
- super(message);
- }
- public NotImplementedException(String message, NotImplementedException cause) {
- super(message, cause);
- }
+ super(message);
+ }
+ public NotImplementedException(String message, NotImplementedException cause) {
+ super(message, cause);
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/NotImplementedFunctionException.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/NotImplementedFunctionException.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/NotImplementedFunctionException.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/NotImplementedFunctionException.java Sat May 22 20:56:44 2021
@@ -29,16 +29,16 @@ public final class NotImplementedFunctio
private String functionName;
- public NotImplementedFunctionException(String functionName) {
- super(functionName);
- this.functionName = functionName;
- }
- public NotImplementedFunctionException(String functionName, NotImplementedException cause) {
- super(functionName, cause);
+ public NotImplementedFunctionException(String functionName) {
+ super(functionName);
this.functionName = functionName;
- }
-
- public String getFunctionName() {
- return functionName;
- }
+ }
+ public NotImplementedFunctionException(String functionName, NotImplementedException cause) {
+ super(functionName, cause);
+ this.functionName = functionName;
+ }
+
+ public String getFunctionName() {
+ return functionName;
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/PercentEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/PercentEval.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/PercentEval.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/PercentEval.java Sat May 22 20:56:44 2021
@@ -26,24 +26,24 @@ import org.apache.poi.ss.formula.functio
*/
public final class PercentEval extends Fixed1ArgFunction {
- public static final Function instance = new PercentEval();
+ public static final Function instance = new PercentEval();
- private PercentEval() {
- // enforce singleton
- }
+ private PercentEval() {
+ // enforce singleton
+ }
- @Override
- public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0) {
- double d;
- try {
- ValueEval ve = OperandResolver.getSingleValue(arg0, srcRowIndex, srcColumnIndex);
- d = OperandResolver.coerceValueToDouble(ve);
- } catch (EvaluationException e) {
- return e.getErrorEval();
- }
- if (d == 0.0) { // this '==' matches +0.0 and -0.0
- return NumberEval.ZERO;
- }
- return new NumberEval(d / 100);
- }
+ @Override
+ public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0) {
+ double d;
+ try {
+ ValueEval ve = OperandResolver.getSingleValue(arg0, srcRowIndex, srcColumnIndex);
+ d = OperandResolver.coerceValueToDouble(ve);
+ } catch (EvaluationException e) {
+ return e.getErrorEval();
+ }
+ if (d == 0.0) { // this '==' matches +0.0 and -0.0
+ return NumberEval.ZERO;
+ }
+ return new NumberEval(d / 100);
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/RangeEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/RangeEval.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/RangeEval.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/RangeEval.java Sat May 22 20:56:44 2021
@@ -23,50 +23,50 @@ import org.apache.poi.ss.formula.functio
public final class RangeEval extends Fixed2ArgFunction {
- public static final Function instance = new RangeEval();
+ public static final Function instance = new RangeEval();
- private RangeEval() {
- // enforces singleton
- }
-
- @Override
- public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1) {
-
- try {
- AreaEval reA = evaluateRef(arg0);
- AreaEval reB = evaluateRef(arg1);
- return resolveRange(reA, reB);
- } catch (EvaluationException e) {
- return e.getErrorEval();
- }
- }
-
- /**
- * @return simple rectangular {@link AreaEval} which fully encloses both areas
- * {@code aeA} and {@code aeB}
- */
- private static AreaEval resolveRange(AreaEval aeA, AreaEval aeB) {
- int aeAfr = aeA.getFirstRow();
- int aeAfc = aeA.getFirstColumn();
-
- int top = Math.min(aeAfr, aeB.getFirstRow());
- int bottom = Math.max(aeA.getLastRow(), aeB.getLastRow());
- int left = Math.min(aeAfc, aeB.getFirstColumn());
- int right = Math.max(aeA.getLastColumn(), aeB.getLastColumn());
-
- return aeA.offset(top-aeAfr, bottom-aeAfr, left-aeAfc, right-aeAfc);
- }
-
- private static AreaEval evaluateRef(ValueEval arg) throws EvaluationException {
- if (arg instanceof AreaEval) {
- return (AreaEval) arg;
- }
- if (arg instanceof RefEval) {
- return ((RefEval) arg).offset(0, 0, 0, 0);
- }
- if (arg instanceof ErrorEval) {
- throw new EvaluationException((ErrorEval)arg);
- }
- throw new IllegalArgumentException("Unexpected ref arg class (" + arg.getClass().getName() + ")");
- }
+ private RangeEval() {
+ // enforces singleton
+ }
+
+ @Override
+ public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1) {
+
+ try {
+ AreaEval reA = evaluateRef(arg0);
+ AreaEval reB = evaluateRef(arg1);
+ return resolveRange(reA, reB);
+ } catch (EvaluationException e) {
+ return e.getErrorEval();
+ }
+ }
+
+ /**
+ * @return simple rectangular {@link AreaEval} which fully encloses both areas
+ * {@code aeA} and {@code aeB}
+ */
+ private static AreaEval resolveRange(AreaEval aeA, AreaEval aeB) {
+ int aeAfr = aeA.getFirstRow();
+ int aeAfc = aeA.getFirstColumn();
+
+ int top = Math.min(aeAfr, aeB.getFirstRow());
+ int bottom = Math.max(aeA.getLastRow(), aeB.getLastRow());
+ int left = Math.min(aeAfc, aeB.getFirstColumn());
+ int right = Math.max(aeA.getLastColumn(), aeB.getLastColumn());
+
+ return aeA.offset(top-aeAfr, bottom-aeAfr, left-aeAfc, right-aeAfc);
+ }
+
+ private static AreaEval evaluateRef(ValueEval arg) throws EvaluationException {
+ if (arg instanceof AreaEval) {
+ return (AreaEval) arg;
+ }
+ if (arg instanceof RefEval) {
+ return ((RefEval) arg).offset(0, 0, 0, 0);
+ }
+ if (arg instanceof ErrorEval) {
+ throw new EvaluationException((ErrorEval)arg);
+ }
+ throw new IllegalArgumentException("Unexpected ref arg class (" + arg.getClass().getName() + ")");
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/RefEvalBase.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/RefEvalBase.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/RefEvalBase.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/RefEvalBase.java Sat May 22 20:56:44 2021
@@ -25,8 +25,8 @@ import org.apache.poi.ss.formula.SheetRa
public abstract class RefEvalBase implements RefEval {
private final int _firstSheetIndex;
private final int _lastSheetIndex;
- private final int _rowIndex;
- private final int _columnIndex;
+ private final int _rowIndex;
+ private final int _columnIndex;
protected RefEvalBase(SheetRange sheetRange, int rowIndex, int columnIndex) {
if (sheetRange == null) {
@@ -37,18 +37,18 @@ public abstract class RefEvalBase implem
_rowIndex = rowIndex;
_columnIndex = columnIndex;
}
- protected RefEvalBase(int firstSheetIndex, int lastSheetIndex, int rowIndex, int columnIndex) {
- _firstSheetIndex = firstSheetIndex;
- _lastSheetIndex = lastSheetIndex;
- _rowIndex = rowIndex;
- _columnIndex = columnIndex;
- }
+ protected RefEvalBase(int firstSheetIndex, int lastSheetIndex, int rowIndex, int columnIndex) {
+ _firstSheetIndex = firstSheetIndex;
+ _lastSheetIndex = lastSheetIndex;
+ _rowIndex = rowIndex;
+ _columnIndex = columnIndex;
+ }
protected RefEvalBase(int onlySheetIndex, int rowIndex, int columnIndex) {
this(onlySheetIndex, onlySheetIndex, rowIndex, columnIndex);
}
- public int getNumberOfSheets() {
- return _lastSheetIndex-_firstSheetIndex+1;
+ public int getNumberOfSheets() {
+ return _lastSheetIndex-_firstSheetIndex+1;
}
public int getFirstSheetIndex() {
return _firstSheetIndex;
@@ -57,9 +57,9 @@ public abstract class RefEvalBase implem
return _lastSheetIndex;
}
public final int getRow() {
- return _rowIndex;
- }
- public final int getColumn() {
- return _columnIndex;
- }
+ return _rowIndex;
+ }
+ public final int getColumn() {
+ return _columnIndex;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org