From: Josh Micich Date: Fri, 16 Oct 2009 19:07:11 +0000 (+0000) Subject: fixed compiler warnings and TODOs in org.apache.poi.hssf.record.formula.eval X-Git-Tag: REL_3_6~101 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c8f135b59bd77d513d86063ee004d90eb35a2a43;p=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 --- diff --git a/src/java/org/apache/poi/hssf/record/formula/eval/BlankEval.java b/src/java/org/apache/poi/hssf/record/formula/eval/BlankEval.java index d1f28df008..fa4a238bd3 100644 --- a/src/java/org/apache/poi/hssf/record/formula/eval/BlankEval.java +++ b/src/java/org/apache/poi/hssf/record/formula/eval/BlankEval.java @@ -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 + } } diff --git a/src/java/org/apache/poi/hssf/record/formula/eval/BoolEval.java b/src/java/org/apache/poi/hssf/record/formula/eval/BoolEval.java index 7b625aaa98..6ca60899ad 100644 --- a/src/java/org/apache/poi/hssf/record/formula/eval/BoolEval.java +++ b/src/java/org/apache/poi/hssf/record/formula/eval/BoolEval.java @@ -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 + + 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:
- * (b ? BoolEval.TRUE : BoolEval.FALSE) - * @return a BoolEval instance representing b. - */ - public static final BoolEval valueOf(boolean b) { - // TODO - find / replace all occurrences - return b ? TRUE : FALSE; - } + /** + * Convenience method for the following:
+ * (b ? BoolEval.TRUE : BoolEval.FALSE) + * + * @return the BoolEval instance representing b. + */ + 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(); + } } diff --git a/src/java/org/apache/poi/hssf/record/formula/eval/MissingArgEval.java b/src/java/org/apache/poi/hssf/record/formula/eval/MissingArgEval.java index 708329ba69..f398947d8c 100644 --- a/src/java/org/apache/poi/hssf/record/formula/eval/MissingArgEval.java +++ b/src/java/org/apache/poi/hssf/record/formula/eval/MissingArgEval.java @@ -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 do count their missing args. Note - the differences between + * COUNT and COUNTA do 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 + } } diff --git a/src/java/org/apache/poi/hssf/record/formula/eval/StringEval.java b/src/java/org/apache/poi/hssf/record/formula/eval/StringEval.java index 27a9c6a627..9c686dbe29 100644 --- a/src/java/org/apache/poi/hssf/record/formula/eval/StringEval.java +++ b/src/java/org/apache/poi/hssf/record/formula/eval/StringEval.java @@ -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 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(); + } } diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/IsError.java b/src/java/org/apache/poi/hssf/record/formula/functions/IsError.java index 55919a3a84..e220126d07 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/IsError.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/IsError.java @@ -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; + } }