]> source.dussan.org Git - poi.git/commitdiff
Fix for 45031 - added implementation for CHOOSE function.
authorJosh Micich <josh@apache.org>
Wed, 31 Dec 2008 20:32:47 +0000 (20:32 +0000)
committerJosh Micich <josh@apache.org>
Wed, 31 Dec 2008 20:32:47 +0000 (20:32 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@730469 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/record/formula/functions/Choose.java
src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls

index 9a1908d9941e446909307f96b92dbdda221cf23a..d138d15031352701ad871a42be9fedc6ee896d06 100644 (file)
@@ -37,6 +37,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.5-beta5" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="add">45031- added implementation for CHOOSE() function</action>
            <action dev="POI-DEVELOPERS" type="fix">46361 - resolve licensing issues around the HDGF resource file, chunks_parse_cmds.tbl</action>
            <action dev="POI-DEVELOPERS" type="add">46410 - added implementation for TIME() function</action>
            <action dev="POI-DEVELOPERS" type="add">46320 - added HSSFPictureData.getFormat()</action>
index c13cb6cf297f77cb2af2d300a92b2c65e44c314b..4f1aafec4950044147fb87eb85b802a1fa151f6b 100644 (file)
@@ -34,6 +34,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.5-beta5" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="add">45031- added implementation for CHOOSE() function</action>
            <action dev="POI-DEVELOPERS" type="fix">46361 - resolve licensing issues around the HDGF resource file, chunks_parse_cmds.tbl</action>
            <action dev="POI-DEVELOPERS" type="add">46410 - added implementation for TIME() function</action>
            <action dev="POI-DEVELOPERS" type="add">46320 - added HSSFPictureData.getFormat()</action>
index e7acc93c48b10c36b28541a62274bf6e137f7095..2f3ac240a902548618012658a2155e09a1bbbc3f 100644 (file)
@@ -1,25 +1,48 @@
-/*
-* 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 15, 2005
- *
- */
+/* ====================================================================
+   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.functions;
 
-public class Choose extends NotImplementedFunction {
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+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 Josh Micich
+ */
+public final class Choose implements Function {
+
+       public Eval evaluate(Eval[] args, int srcRowIndex, short srcColumnIndex) {
+               if (args.length < 2) {
+                       return ErrorEval.VALUE_INVALID;
+               }
 
+               try {
+                       ValueEval ev = OperandResolver.getSingleValue(args[0], srcRowIndex, srcColumnIndex);
+                       int ix = OperandResolver.coerceValueToInt(ev);
+                       if (ix < 1 || ix >= args.length) {
+                               return ErrorEval.VALUE_INVALID;
+                       }
+                       return OperandResolver.getSingleValue(args[ix], srcRowIndex, srcColumnIndex);
+               } catch (EvaluationException e) {
+                       return e.getErrorEval();
+               }
+       }
 }
index 344a072cdf7e49939e3164aa60a9593222d55b11..29e474abbf863cec6e281fa6f03a339a07557a26 100644 (file)
Binary files a/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls and b/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls differ