Move the FormulaEvaluator code out of scratchpad
[poi.git] / src / java / org / apache / poi / hssf / record / formula / eval / NumericOperationEval.java
blob6bc1c95dc124098ae2823feb0372c251d0a8a973
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 * Created on May 14, 2005
21 package org.apache.poi.hssf.record.formula.eval;
23 /**
24 * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
27 public abstract class NumericOperationEval implements OperationEval {
29 protected abstract ValueEvalToNumericXlator getXlator();
31 protected ValueEval singleOperandEvaluate(Eval eval, int srcRow, short srcCol) {
32 ValueEval retval;
33 if (eval instanceof AreaEval) {
34 AreaEval ae = (AreaEval) eval;
35 if (ae.contains(srcRow, srcCol)) { // circular ref!
36 retval = ErrorEval.CIRCULAR_REF_ERROR;
38 else if (ae.isRow()) {
39 if (ae.containsColumn(srcCol)) {
40 ValueEval ve = ae.getValueAt(ae.getFirstRow(), srcCol);
41 ve = getXlator().attemptXlateToNumeric(ve);
42 retval = getXlator().attemptXlateToNumeric(ve);
44 else {
45 retval = ErrorEval.VALUE_INVALID;
48 else if (ae.isColumn()) {
49 if (ae.containsRow(srcRow)) {
50 ValueEval ve = ae.getValueAt(srcRow, ae.getFirstColumn());
51 retval = getXlator().attemptXlateToNumeric(ve);
53 else {
54 retval = ErrorEval.VALUE_INVALID;
57 else {
58 retval = ErrorEval.VALUE_INVALID;
61 else {
62 retval = getXlator().attemptXlateToNumeric((ValueEval) eval);
64 return retval;