From: Josh Micich Date: Wed, 31 Dec 2008 20:32:47 +0000 (+0000) Subject: Fix for 45031 - added implementation for CHOOSE function. X-Git-Tag: REL_3_5_BETA5~45 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5c0c965b32c64a92f4f544d1d0e5c18ad2f2e361;p=poi.git Fix for 45031 - added implementation for CHOOSE function. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@730469 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index 9a1908d994..d138d15031 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,6 +37,7 @@ + 45031- added implementation for CHOOSE() function 46361 - resolve licensing issues around the HDGF resource file, chunks_parse_cmds.tbl 46410 - added implementation for TIME() function 46320 - added HSSFPictureData.getFormat() diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index c13cb6cf29..4f1aafec49 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 45031- added implementation for CHOOSE() function 46361 - resolve licensing issues around the HDGF resource file, chunks_parse_cmds.tbl 46410 - added implementation for TIME() function 46320 - added HSSFPictureData.getFormat() diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Choose.java b/src/java/org/apache/poi/hssf/record/formula/functions/Choose.java index e7acc93c48..2f3ac240a9 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Choose.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Choose.java @@ -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(); + } + } } diff --git a/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls b/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls index 344a072cdf..29e474abbf 100644 Binary files a/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls and b/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls differ