01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
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.
16: */
17: /*
18: * Created on May 14, 2005
19: *
20: */
21: package org.apache.poi.hssf.record.formula.eval;
22:
23: /**
24: * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
25: *
26: */
27: public abstract class NumericOperationEval implements OperationEval {
28:
29: protected abstract ValueEvalToNumericXlator getXlator();
30:
31: protected ValueEval singleOperandEvaluate(Eval eval, int srcRow,
32: short srcCol) {
33: ValueEval retval;
34: if (eval instanceof AreaEval) {
35: AreaEval ae = (AreaEval) eval;
36: if (ae.contains(srcRow, srcCol)) { // circular ref!
37: retval = ErrorEval.CIRCULAR_REF_ERROR;
38: } else if (ae.isRow()) {
39: if (ae.containsColumn(srcCol)) {
40: ValueEval ve = ae.getValueAt(ae.getFirstRow(),
41: srcCol);
42: ve = getXlator().attemptXlateToNumeric(ve);
43: retval = getXlator().attemptXlateToNumeric(ve);
44: } else {
45: retval = ErrorEval.VALUE_INVALID;
46: }
47: } else if (ae.isColumn()) {
48: if (ae.containsRow(srcRow)) {
49: ValueEval ve = ae.getValueAt(srcRow, ae
50: .getFirstColumn());
51: retval = getXlator().attemptXlateToNumeric(ve);
52: } else {
53: retval = ErrorEval.VALUE_INVALID;
54: }
55: } else {
56: retval = ErrorEval.VALUE_INVALID;
57: }
58: } else {
59: retval = getXlator()
60: .attemptXlateToNumeric((ValueEval) eval);
61: }
62: return retval;
63: }
64: }
|