You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by jo...@apache.org on 2009/10/16 21:07:11 UTC

svn commit: r826041 - in /poi/trunk/src/java/org/apache/poi/hssf/record/formula: eval/BlankEval.java eval/BoolEval.java eval/MissingArgEval.java eval/StringEval.java functions/IsError.java

Author: josh
Date: Fri Oct 16 19:07:11 2009
New Revision: 826041

URL: http://svn.apache.org/viewvc?rev=826041&view=rev
Log:
fixed compiler warnings and TODOs in org.apache.poi.hssf.record.formula.eval

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/BlankEval.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/BoolEval.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/MissingArgEval.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/StringEval.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/IsError.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/BlankEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/BlankEval.java?rev=826041&r1=826040&r2=826041&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/BlankEval.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/BlankEval.java Fri Oct 16 19:07:11 2009
@@ -23,8 +23,9 @@
  */
 public final class BlankEval implements ValueEval {
 
-    public static BlankEval INSTANCE = new BlankEval();
+	public static BlankEval INSTANCE = new BlankEval();
 
-    private BlankEval() {
-    }
+	private BlankEval() {
+		// enforce singleton
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/BoolEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/BoolEval.java?rev=826041&r1=826040&r2=826041&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/BoolEval.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/BoolEval.java Fri Oct 16 19:07:11 2009
@@ -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:<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;
-    }
-
-    public BoolEval(Ptg ptg) {
-        this.value = ((BoolPtg) ptg).getValue();
-    }
-
-    private BoolEval(boolean value) {
-        this.value = value;
-    }
-
-    public boolean getBooleanValue() {
-        return value;
-    }
-
-    public double getNumberValue() {
-        return value ? 1 : 0;
-    }
-
-    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();
-    }
+	/**
+	 * 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;
+	}
+
+	private BoolEval(boolean value) {
+		_value = value;
+	}
+
+	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();
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/MissingArgEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/MissingArgEval.java?rev=826041&r1=826040&r2=826041&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/MissingArgEval.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/MissingArgEval.java Fri Oct 16 19:07:11 2009
@@ -20,7 +20,7 @@
 /**
  * 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 @@
  */
 public final class MissingArgEval implements ValueEval {
 
-    public static MissingArgEval instance = new MissingArgEval();
+	public static MissingArgEval instance = new MissingArgEval();
 
-    private MissingArgEval() {
-    }
+	private MissingArgEval() {
+		// enforce singleton
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/StringEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/StringEval.java?rev=826041&r1=826040&r2=826041&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/StringEval.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/StringEval.java Fri Oct 16 19:07:11 2009
@@ -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 @@
 
 /**
  * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
- *  
  */
 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();
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/IsError.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/IsError.java?rev=826041&r1=826040&r2=826041&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/IsError.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/IsError.java Fri Oct 16 19:07:11 2009
@@ -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 &lt; amolweb at ya hoo dot com &gt;
- *
+ * @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;
+	}
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org