*/
public final class BlankEval implements ValueEval {
- public static BlankEval INSTANCE = new BlankEval();
+ public static BlankEval INSTANCE = new BlankEval();
- private BlankEval() {
- }
+ private BlankEval() {
+ // enforce singleton
+ }
}
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-/*
- * Created on May 8, 2005
- *
- */
-package org.apache.poi.hssf.record.formula.eval;
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
-import org.apache.poi.hssf.record.formula.BoolPtg;
-import org.apache.poi.hssf.record.formula.Ptg;
+package org.apache.poi.hssf.record.formula.eval;
/**
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
- *
*/
-public class BoolEval implements NumericValueEval, StringValueEval {
+public final class BoolEval implements NumericValueEval, StringValueEval {
+
+ private boolean _value;
+
+ public static final BoolEval FALSE = new BoolEval(false);
+
+ public static final BoolEval TRUE = new BoolEval(true);
- private boolean value;
-
- public static final BoolEval FALSE = new BoolEval(false);
-
- public static final BoolEval TRUE = new BoolEval(true);
-
- /**
- * Convenience method for the following:<br/>
- * <code>(b ? BoolEval.TRUE : BoolEval.FALSE)</code>
- * @return a <tt>BoolEval</tt> instance representing <tt>b</tt>.
- */
- public static final BoolEval valueOf(boolean b) {
- // TODO - find / replace all occurrences
- return b ? TRUE : FALSE;
- }
+ /**
+ * Convenience method for the following:<br/>
+ * <code>(b ? BoolEval.TRUE : BoolEval.FALSE)</code>
+ *
+ * @return the <tt>BoolEval</tt> instance representing <tt>b</tt>.
+ */
+ public static final BoolEval valueOf(boolean b) {
+ return b ? TRUE : FALSE;
+ }
- public BoolEval(Ptg ptg) {
- this.value = ((BoolPtg) ptg).getValue();
- }
+ private BoolEval(boolean value) {
+ _value = value;
+ }
- private BoolEval(boolean value) {
- this.value = value;
- }
+ public boolean getBooleanValue() {
+ return _value;
+ }
- public boolean getBooleanValue() {
- return value;
- }
+ public double getNumberValue() {
+ return _value ? 1 : 0;
+ }
- public double getNumberValue() {
- return value ? 1 : 0;
- }
+ public String getStringValue() {
+ return _value ? "TRUE" : "FALSE";
+ }
- public String getStringValue() {
- return value ? "TRUE" : "FALSE";
- }
- public String toString() {
- StringBuffer sb = new StringBuffer(64);
- sb.append(getClass().getName()).append(" [");
- sb.append(getStringValue());
- sb.append("]");
- return sb.toString();
- }
+ public String toString() {
+ StringBuilder sb = new StringBuilder(64);
+ sb.append(getClass().getName()).append(" [");
+ sb.append(getStringValue());
+ sb.append("]");
+ return sb.toString();
+ }
}
/**
* Represents the (intermediate) evaluated result of a missing function argument. In most cases
* this can be translated into {@link BlankEval} but there are some notable exceptions. Functions
- * COUNT and COUNTA <em>do</em> count their missing args. Note - the differences between
+ * COUNT and COUNTA <em>do</em> count their missing args. Note - the differences between
* {@link MissingArgEval} and {@link BlankEval} have not been investigated fully, so the POI
* evaluator may need to be updated to account for these as they are found.
*
*/
public final class MissingArgEval implements ValueEval {
- public static MissingArgEval instance = new MissingArgEval();
+ public static MissingArgEval instance = new MissingArgEval();
- private MissingArgEval() {
- }
+ private MissingArgEval() {
+ // enforce singleton
+ }
}
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
package org.apache.poi.hssf.record.formula.eval;
/**
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
- *
*/
public final class StringEval implements StringValueEval {
- public static final StringEval EMPTY_INSTANCE = new StringEval("");
-
- private final String value;
-
- public StringEval(Ptg ptg) {
- this(((StringPtg) ptg).getValue());
- }
-
- public StringEval(String value) {
- if(value == null) {
- throw new IllegalArgumentException("value must not be null");
- }
- this.value = value;
- }
-
- public String getStringValue() {
- return value;
- }
- public String toString() {
- StringBuffer sb = new StringBuffer(64);
- sb.append(getClass().getName()).append(" [");
- sb.append(value);
- sb.append("]");
- return sb.toString();
- }
+ public static final StringEval EMPTY_INSTANCE = new StringEval("");
+
+ private final String _value;
+
+ public StringEval(Ptg ptg) {
+ this(((StringPtg) ptg).getValue());
+ }
+
+ public StringEval(String value) {
+ if (value == null) {
+ throw new IllegalArgumentException("value must not be null");
+ }
+ _value = value;
+ }
+
+ public String getStringValue() {
+ return _value;
+ }
+
+ public String toString() {
+ StringBuilder sb = new StringBuilder(64);
+ sb.append(getClass().getName()).append(" [");
+ sb.append(_value);
+ sb.append("]");
+ return sb.toString();
+ }
}
package org.apache.poi.hssf.record.formula.functions;
-import org.apache.poi.hssf.record.formula.eval.AreaEval;
import org.apache.poi.hssf.record.formula.eval.BoolEval;
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
-import org.apache.poi.hssf.record.formula.eval.RefEval;
+import org.apache.poi.hssf.record.formula.eval.EvaluationException;
+import org.apache.poi.hssf.record.formula.eval.OperandResolver;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
/**
- * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
- *
+ * @author Josh Micich
*/
public final class IsError implements Function {
- public ValueEval evaluate(ValueEval[] operands, int srcCellRow, short srcCellCol) {
- ValueEval retval = null;
- boolean b = false;
-
- switch (operands.length) {
- default:
- retval = ErrorEval.VALUE_INVALID;
- break;
- case 1:
- if (operands[0] instanceof ErrorEval) {
- b = true;
- }
- else if (operands[0] instanceof AreaEval) {
- AreaEval ae = (AreaEval) operands[0];
- if (ae.contains(srcCellRow, srcCellCol)) { // circular ref!
- retval = ErrorEval.CIRCULAR_REF_ERROR;
- }
- else if (ae.isRow()) {
- if (ae.containsColumn(srcCellCol)) {
- ValueEval ve = ae.getValueAt(ae.getFirstRow(), srcCellCol);
- if (ve instanceof RefEval)
- b = ((RefEval) ve).getInnerValueEval() instanceof ErrorEval;
- else
- b = (ve instanceof ErrorEval);
- }
- else {
- b = true;
- }
- }
- else if (ae.isColumn()) {
- if (ae.containsRow(srcCellRow)) {
- ValueEval ve = ae.getValueAt(srcCellRow, ae.getFirstColumn());
- if (ve instanceof RefEval)
- b = ((RefEval) ve).getInnerValueEval() instanceof ErrorEval;
- else
- b = (ve instanceof ErrorEval);
- }
- else {
- b = true;
- }
- }
- else {
- b = true;
- }
- }
- else if (operands[0] instanceof RefEval) {
- b = ((RefEval) operands[0]).getInnerValueEval() instanceof ErrorEval;
- }
- else {
- b = false;
- }
- }
-
- if (retval == null) {
- retval = b
- ? BoolEval.TRUE
- : BoolEval.FALSE;
- }
- return retval;
- }
+ public ValueEval evaluate(ValueEval[] operands, int srcCellRow, short srcCellCol) {
+ if (operands.length != 1) {
+ return ErrorEval.VALUE_INVALID;
+ }
+ try {
+ OperandResolver.getSingleValue(operands[0], srcCellRow, srcCellCol);
+ } catch (EvaluationException e) {
+ return BoolEval.TRUE;
+ }
+ return BoolEval.FALSE;
+ }
}