From 7d73b417668c59eb991e2c56c4ad9371c2b85fc1 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Mon, 17 Dec 2018 09:11:06 +0000 Subject: [PATCH] use spaces for indents git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1849067 13f79535-47bb-0310-9956-ffa450edef68 --- .../MultiOperandNumericFunction.java | 319 +++++++++--------- 1 file changed, 160 insertions(+), 159 deletions(-) diff --git a/src/java/org/apache/poi/ss/formula/functions/MultiOperandNumericFunction.java b/src/java/org/apache/poi/ss/formula/functions/MultiOperandNumericFunction.java index dae92cb6af..8e4ec2c729 100644 --- a/src/java/org/apache/poi/ss/formula/functions/MultiOperandNumericFunction.java +++ b/src/java/org/apache/poi/ss/formula/functions/MultiOperandNumericFunction.java @@ -39,187 +39,188 @@ import org.apache.poi.ss.formula.eval.ValueEval; */ public abstract class MultiOperandNumericFunction implements Function { - private final boolean _isReferenceBoolCounted; - private final boolean _isBlankCounted; + private final boolean _isReferenceBoolCounted; + private final boolean _isBlankCounted; protected MultiOperandNumericFunction(boolean isReferenceBoolCounted, boolean isBlankCounted) { _isReferenceBoolCounted = isReferenceBoolCounted; _isBlankCounted = isBlankCounted; } - static final double[] EMPTY_DOUBLE_ARRAY = { }; - - private static class DoubleList { - private double[] _array; - private int _count; - - public DoubleList() { - _array = new double[8]; - _count = 0; - } - - public double[] toArray() { - if(_count < 1) { - return EMPTY_DOUBLE_ARRAY; - } - double[] result = new double[_count]; - System.arraycopy(_array, 0, result, 0, _count); - return result; - } - - private void ensureCapacity(int reqSize) { - if(reqSize > _array.length) { - int newSize = reqSize * 3 / 2; // grow with 50% extra - double[] newArr = new double[newSize]; - System.arraycopy(_array, 0, newArr, 0, _count); - _array = newArr; - } - } - - public void add(double value) { - ensureCapacity(_count + 1); - _array[_count] = value; - _count++; - } - } - - private static final int DEFAULT_MAX_NUM_OPERANDS = SpreadsheetVersion.EXCEL2007.getMaxFunctionArgs(); - - public final ValueEval evaluate(ValueEval[] args, int srcCellRow, int srcCellCol) { - try { - double[] values = getNumberArray(args); - double d = evaluate(values); - if (Double.isNaN(d) || Double.isInfinite(d)) { - return ErrorEval.NUM_ERROR; - } - return new NumberEval(d); - } catch (EvaluationException e) { - return e.getErrorEval(); - } - } - - protected abstract double evaluate(double[] values) throws EvaluationException; - - /** - * Maximum number of operands accepted by this function. - * Subclasses may override to change default value. - */ - protected int getMaxNumOperands() { - return DEFAULT_MAX_NUM_OPERANDS; - } - - /** - * Returns a double array that contains values for the numeric cells - * from among the list of operands. Blanks and Blank equivalent cells - * are ignored. Error operands or cells containing operands of type - * that are considered invalid and would result in #VALUE! error in - * excel cause this function to return null. - * - * @return never null - */ - protected final double[] getNumberArray(ValueEval[] operands) throws EvaluationException { - if (operands.length > getMaxNumOperands()) { - throw EvaluationException.invalidValue(); - } - DoubleList retval = new DoubleList(); - - for (int i=0, iSize=operands.length; i _array.length) { + int newSize = reqSize * 3 / 2; // grow with 50% extra + double[] newArr = new double[newSize]; + System.arraycopy(_array, 0, newArr, 0, _count); + _array = newArr; + } + } + + public void add(double value) { + ensureCapacity(_count + 1); + _array[_count] = value; + _count++; + } + } + + private static final int DEFAULT_MAX_NUM_OPERANDS = SpreadsheetVersion.EXCEL2007.getMaxFunctionArgs(); + + public final ValueEval evaluate(ValueEval[] args, int srcCellRow, int srcCellCol) { + try { + double[] values = getNumberArray(args); + double d = evaluate(values); + if (Double.isNaN(d) || Double.isInfinite(d)) { + return ErrorEval.NUM_ERROR; + } + return new NumberEval(d); + } catch (EvaluationException e) { + return e.getErrorEval(); + } + } + + protected abstract double evaluate(double[] values) throws EvaluationException; + + /** + * Maximum number of operands accepted by this function. + * Subclasses may override to change default value. + */ + protected int getMaxNumOperands() { + return DEFAULT_MAX_NUM_OPERANDS; + } + + /** + * Returns a double array that contains values for the numeric cells + * from among the list of operands. Blanks and Blank equivalent cells + * are ignored. Error operands or cells containing operands of type + * that are considered invalid and would result in #VALUE! error in + * excel cause this function to return null. + * + * @return never null + */ + protected final double[] getNumberArray(ValueEval[] operands) throws EvaluationException { + if (operands.length > getMaxNumOperands()) { + throw EvaluationException.invalidValue(); + } + DoubleList retval = new DoubleList(); + + for (int i = 0, iSize = operands.length; i < iSize; i++) { + collectValues(operands[i], retval); + } + return retval.toArray(); + } /** - * Whether to count nested subtotals. + * Whether to count nested subtotals. */ - public boolean isSubtotalCounted(){ + public boolean isSubtotalCounted() { return true; } - /** - * Collects values from a single argument - */ - private void collectValues(ValueEval operand, DoubleList temp) throws EvaluationException { + /** + * Collects values from a single argument + */ + private void collectValues(ValueEval operand, DoubleList temp) throws EvaluationException { if (operand instanceof ThreeDEval) { ThreeDEval ae = (ThreeDEval) operand; - for (int sIx=ae.getFirstSheetIndex(); sIx <= ae.getLastSheetIndex(); sIx++) { + for (int sIx = ae.getFirstSheetIndex(); sIx <= ae.getLastSheetIndex(); sIx++) { int width = ae.getWidth(); int height = ae.getHeight(); - for (int rrIx=0; rrIx