* returns true if the cell at row and col specified
* as absolute indexes in the sheet is contained in
* this area.
- * @param row
- * @param col
+ * @param row 0-based row index
+ * @param col 0-based column index
*/
boolean contains(int row, int col);
/**
* returns true if the specified col is in range
- * @param col
+ * @param col 0-based column index
*/
boolean containsColumn(int col);
/**
* returns true if the specified row is in range
- * @param row
+ * @param row 0-based row index
*/
boolean containsRow(int row);
int getWidth();
int getHeight();
/**
+ * @param relativeRowIndex 0-based row index relative to this area
+ * @param relativeColumnIndex 0-based column index relative to this area
+ *
* @return the ValueEval from within this area at the specified relativeRowIndex and
* relativeColumnIndex. Never <code>null</code> (possibly {@link BlankEval}). The
* specified indexes should relative to the top left corner of this area.
"(\\."+Digits+"("+Exp+")?))"+
"[\\x00-\\x20]*");
private static final Pattern fpPattern = Pattern.compile(fpRegex);
-
+
private OperandResolver() {
// no instances of this class
}
}
return result;
}
-
+
/**
* Retrieves a single value from an area evaluation utilizing the 2D indices of the cell
* within its own area reference to index the value in the area evaluation.
else if (ae.isRow() && relativeColIndex < ae.getWidth()) {
return ae.getRelativeValue(0, relativeColIndex);
}
-
+
return ErrorEval.NA;
}
}
return ae.getAbsoluteValue(ae.getFirstRow(), srcCellCol);
}
-
+
private static ValueEval chooseSingleElementFromRef(RefEval ref) {
return ref.getInnerValueEval( ref.getFirstSheetIndex() );
}
* {@link StringEval}, {@link BoolEval} or {@link BlankEval}
*/
public static double coerceValueToDouble(ValueEval ev) throws EvaluationException {
-
if (ev == BlankEval.instance) {
return 0.0;
}
if (dd == null) {
throw EvaluationException.invalidValue();
}
- return dd.doubleValue();
+ return dd;
}
throw new RuntimeException("Unexpected arg eval type (" + ev.getClass().getName() + ")");
}
/**
* Converts a string to a double using standard rules that Excel would use.<br>
* Tolerates leading and trailing spaces, <p>
- *
- * Doesn't support currency prefixes, commas, percentage signs or arithmetic operations strings.
+ *
+ * Doesn't support currency prefixes, commas, percentage signs or arithmetic operations strings.
*
* Some examples:<br>
* " 123 " -> 123.0<br>
else {
return null;
}
-
+
}
public static Double parseDateTime(String pText) {
return null;
}
if (ve instanceof BoolEval) {
- return Boolean.valueOf(((BoolEval) ve).getBooleanValue());
+ return ((BoolEval) ve).getBooleanValue();
}
if (ve instanceof StringEval) {
if (Double.isNaN(d)) {
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
- return Boolean.valueOf(d != 0);
+ return d != 0;
}
if (ve instanceof ErrorEval) {
throw new EvaluationException((ErrorEval) ve);
import org.apache.poi.ss.formula.functions.Countif.ErrorMatcher;
/**
- * Base class for SUMIFS() and COUNTIFS() functions, as they share much of the same logic,
+ * Base class for SUMIFS() and COUNTIFS() functions, as they share much of the same logic,
* the difference being the source of the totals.
*/
/*package*/ abstract class Baseifs implements FreeRefFunction {
* @return true if there should be a range argument before the criteria pairs
*/
protected abstract boolean hasInitialRange();
-
+
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
final boolean hasInitialRange = hasInitialRange();
final int firstCriteria = hasInitialRange ? 1 : 0;
-
+
if( args.length < (2+firstCriteria) || args.length % 2 != firstCriteria ) {
return ErrorEval.VALUE_INVALID;
}
if (hasInitialRange) {
sumRange = convertRangeArg(args[0]);
}
-
+
// collect pairs of ranges and criteria
AreaEval[] ae = new AreaEval[(args.length - firstCriteria)/2];
I_MatchPredicate[] mp = new I_MatchPredicate[ae.length];
for(int i = firstCriteria, k=0; i < args.length; i += 2, k++){
ae[k] = convertRangeArg(args[i]);
-
+
mp[k] = Countif.createCriteriaPredicate(args[i+1], ec.getRowIndex(), ec.getColumnIndex());
}
private static void validateCriteriaRanges(AreaEval sumRange, AreaEval[] criteriaRanges) throws EvaluationException {
int h = criteriaRanges[0].getHeight();
int w = criteriaRanges[0].getWidth();
-
- if (sumRange != null
- && (sumRange.getHeight() != h
+
+ if (sumRange != null
+ && (sumRange.getHeight() != h
|| sumRange.getWidth() != w) ) {
throw EvaluationException.invalidValue();
}
-
+
for(AreaEval r : criteriaRanges){
if(r.getHeight() != h ||
r.getWidth() != w ) {
*/
private static void validateCriteria(I_MatchPredicate[] criteria) throws EvaluationException {
for(I_MatchPredicate predicate : criteria) {
-
+
// check for errors in predicate and return immediately using this error code
if(predicate instanceof ErrorMatcher) {
throw new EvaluationException(ErrorEval.valueOf(((ErrorMatcher)predicate).getValue()));
/**
* For counts, this would return 1, for sums it returns a cell value or zero.
* This is only called after all the criteria are confirmed true for the coordinates.
+ *
* @param sumRange if used
- * @param relRowIndex
- * @param relColIndex
+ * @param relRowIndex 0-based row index relative to the sumRange area
+ * @param relColIndex 0-based column index relative to the sumRange area
+ *
* @return the aggregate input value corresponding to the given range coordinates
*/
private static double accumulate(AreaEval sumRange, int relRowIndex, int relColIndex) {
if (sumRange == null) return 1.0; // count
-
+
ValueEval addend = sumRange.getRelativeValue(relRowIndex, relColIndex);
if (addend instanceof NumberEval) {
return ((NumberEval)addend).getNumberValue();
}
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(64);
- sb.append(getClass().getName());
- sb.append(" [").append(_representation).append("]");
- return sb.toString();
+ return getClass().getName() + " [" + _representation + "]";
}
+
public String getRepresentation() {
return _representation;
}
// x is text that is not a number
return false;
}
- return _value == val.doubleValue();
+ return _value == val;
} else if((x instanceof NumberEval)) {
NumberEval ne = (NumberEval) x;
testValue = ne.getNumberValue();
}
return false;
}
-
+
public int getValue() {
return _value;
}
Boolean booleanVal = parseBoolean(value);
if(booleanVal != null) {
- return new BooleanMatcher(booleanVal.booleanValue(), operator);
+ return new BooleanMatcher(booleanVal, operator);
}
Double doubleVal = OperandResolver.parseDouble(value);
if(doubleVal != null) {
- return new NumberMatcher(doubleVal.doubleValue(), operator);
+ return new NumberMatcher(doubleVal, operator);
}
ErrorEval ee = parseError(value);
if (ee != null) {
} catch (EvaluationException e) {
return e.getErrorEval();
}
- throw new RuntimeException("Invalid arg type for SUMPRODUCT: ("
- + firstArg.getClass().getName() + ")");
+ throw new RuntimeException("Invalid arg type for SUMPRODUCT: " + firstArg);
}
private static ValueEval evaluateSingleProduct(ValueEval[] evalArgs) throws EvaluationException {
- int maxN = evalArgs.length;
-
double term = 1D;
- for(int n=0; n<maxN; n++) {
- double val = getScalarValue(evalArgs[n]);
- term *= val;
+ for (ValueEval evalArg : evalArgs) {
+ term *= getScalarValue(evalArg);
}
return new NumberEval(term);
}
}
private static boolean areasAllSameSize(TwoDEval[] args, int height, int width) {
- for (int i = 0; i < args.length; i++) {
- TwoDEval areaEval = args[i];
+ for (TwoDEval areaEval : args) {
// check that height and width match
- if(areaEval.getHeight() != height) {
+ if (areaEval.getHeight() != height) {
return false;
}
- if(areaEval.getWidth() != width) {
+ if (areaEval.getWidth() != width) {
return false;
}
}
}
}
- public class NullInputStream extends InputStream {
+ public static class NullInputStream extends InputStream {
private final int bytes;
private final boolean exception;
/**
* Default content type tree. <Extension, ContentType>
*/
- private TreeMap<String, String> defaultContentType;
+ private final TreeMap<String, String> defaultContentType;
/**
* Override content type tree.
throw new IllegalArgumentException("contentType");
}
- return (this.defaultContentType.containsValue(contentType) ||
+ return (this.defaultContentType.containsValue(contentType) ||
(this.overrideContentType != null && this.overrideContentType.containsValue(contentType)));
}
*/
if (this.container != null && this.container.getPart(partName) != null) {
throw new OpenXML4JRuntimeException(
- "Rule M2.4 exception : Part \'"
+ "Rule M2.4 exception : Part '"
+ partName
- + "\' not found - this error should NEVER happen!\n"
+ + "' not found - this error should NEVER happen!\n"
+ "Check that your code is closing the open resources in the correct order prior to filing a bug report.\n"
+ "If you can provide the triggering file, then please raise a bug at https://bz.apache.org/bugzilla/enter_bug.cgi?product=POI and attach the file that triggers it, thanks!");
}