mirror of https://github.com/apache/poi.git
fixed compiler warnings and TODOs in org.apache.poi.hssf.record.formula.eval
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@826041 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ec3f4b9d77
commit
c8f135b59b
|
@ -23,8 +23,9 @@ package org.apache.poi.hssf.record.formula.eval;
|
|||
*/
|
||||
public final class BlankEval implements ValueEval {
|
||||
|
||||
public static BlankEval INSTANCE = new BlankEval();
|
||||
public static BlankEval INSTANCE = new BlankEval();
|
||||
|
||||
private BlankEval() {
|
||||
}
|
||||
private BlankEval() {
|
||||
// enforce singleton
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,74 +1,64 @@
|
|||
/*
|
||||
* 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
|
||||
|
||||
import org.apache.poi.hssf.record.formula.BoolPtg;
|
||||
import org.apache.poi.hssf.record.formula.Ptg;
|
||||
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 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);
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
private boolean _value;
|
||||
|
||||
public BoolEval(Ptg ptg) {
|
||||
this.value = ((BoolPtg) ptg).getValue();
|
||||
}
|
||||
public static final BoolEval FALSE = new BoolEval(false);
|
||||
|
||||
private BoolEval(boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
public static final BoolEval TRUE = new BoolEval(true);
|
||||
|
||||
public boolean getBooleanValue() {
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* 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 double getNumberValue() {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
private BoolEval(boolean value) {
|
||||
_value = value;
|
||||
}
|
||||
|
||||
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 boolean getBooleanValue() {
|
||||
return _value;
|
||||
}
|
||||
|
||||
public double getNumberValue() {
|
||||
return _value ? 1 : 0;
|
||||
}
|
||||
|
||||
public String getStringValue() {
|
||||
return _value ? "TRUE" : "FALSE";
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(64);
|
||||
sb.append(getClass().getName()).append(" [");
|
||||
sb.append(getStringValue());
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ package org.apache.poi.hssf.record.formula.eval;
|
|||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -28,8 +28,9 @@ package org.apache.poi.hssf.record.formula.eval;
|
|||
*/
|
||||
public final class MissingArgEval implements ValueEval {
|
||||
|
||||
public static MissingArgEval instance = new MissingArgEval();
|
||||
public static MissingArgEval instance = new MissingArgEval();
|
||||
|
||||
private MissingArgEval() {
|
||||
}
|
||||
private MissingArgEval() {
|
||||
// enforce singleton
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
|
@ -22,33 +22,33 @@ import org.apache.poi.hssf.record.formula.StringPtg;
|
|||
|
||||
/**
|
||||
* @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 static final StringEval EMPTY_INSTANCE = new StringEval("");
|
||||
|
||||
public StringEval(Ptg ptg) {
|
||||
this(((StringPtg) ptg).getValue());
|
||||
}
|
||||
private final String _value;
|
||||
|
||||
public StringEval(String value) {
|
||||
if(value == null) {
|
||||
throw new IllegalArgumentException("value must not be null");
|
||||
}
|
||||
this.value = value;
|
||||
}
|
||||
public StringEval(Ptg ptg) {
|
||||
this(((StringPtg) ptg).getValue());
|
||||
}
|
||||
|
||||
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 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,76 +17,26 @@
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue