functioneval.java

来自「EXCEL read and write」· Java 代码 · 共 432 行 · 第 1/2 页

JAVA
432
字号
/* ====================================================================   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;import java.util.HashMap;import java.util.Map;import org.apache.poi.hssf.record.formula.functions.*;/** * @author Amol S. Deshmukh < amolweb at ya hoo dot com > *   */public abstract class FunctionEval implements OperationEval {    /**     * Some function IDs that require special treatment     */    private static final class FunctionID {        /** 78 */        public static final int OFFSET = 78;        /** 148 */        public static final int INDIRECT = 148;        /** 255 */        public static final int EXTERNAL_FUNC = 255;    }    // convenient access to namespace    private static final FunctionID ID = null;        protected static Function[] functions = produceFunctions();    private static Map freeRefFunctionsByIdMap;         static {        Map m = new HashMap();        addMapping(m, ID.INDIRECT, new Indirect());        addMapping(m, ID.EXTERNAL_FUNC, new ExternalFunction());        freeRefFunctionsByIdMap = m;    }    private static void addMapping(Map m, int offset, FreeRefFunction frf) {        m.put(createFRFKey(offset), frf);    }    private static Integer createFRFKey(int functionIndex) {        return new Integer(functionIndex);    }            public Function getFunction() {        short fidx = getFunctionIndex();        return functions[fidx];    }    public boolean isFreeRefFunction() {        return freeRefFunctionsByIdMap.containsKey(createFRFKey(getFunctionIndex()));    }    public FreeRefFunction getFreeRefFunction() {        return (FreeRefFunction) freeRefFunctionsByIdMap.get(createFRFKey(getFunctionIndex()));    }    public abstract short getFunctionIndex();    private static Function[] produceFunctions() {        Function[] retval = new Function[368];        retval[0] = new Count(); // COUNT        retval[1] = new If(); // IF        retval[2] = new IsNa(); // ISNA        retval[3] = new IsError(); // ISERROR        retval[4] = AggregateFunction.SUM;        retval[5] = AggregateFunction.AVERAGE;        retval[6] = AggregateFunction.MIN;        retval[7] = AggregateFunction.MAX;        retval[8] = new Row(); // ROW        retval[9] = new Column(); // COLUMN        retval[10] = new Na(); // NA        retval[11] = new Npv(); // NPV        retval[12] = AggregateFunction.STDEV;        retval[13] = NumericFunction.DOLLAR;        retval[14] = new Fixed(); // FIXED        retval[15] = NumericFunction.SIN;        retval[16] = NumericFunction.COS;        retval[17] = NumericFunction.TAN;        retval[18] = NumericFunction.ATAN;        retval[19] = new Pi(); // PI        retval[20] = NumericFunction.SQRT;        retval[21] = NumericFunction.EXP;        retval[22] = NumericFunction.LN;        retval[23] = NumericFunction.LOG10;        retval[24] = NumericFunction.ABS;        retval[25] = NumericFunction.INT;        retval[26] = NumericFunction.SIGN;        retval[27] = NumericFunction.ROUND;        retval[28] = new Lookup(); // LOOKUP        retval[29] = new Index(); // INDEX        retval[30] = new Rept(); // REPT        retval[31] = TextFunction.MID;        retval[32] = TextFunction.LEN;        retval[33] = new Value(); // VALUE        retval[34] = new True(); // TRUE        retval[35] = new False(); // FALSE        retval[36] = new And(); // AND        retval[37] = new Or(); // OR        retval[38] = new Not(); // NOT        retval[39] = NumericFunction.MOD;        retval[40] = new Dcount(); // DCOUNT        retval[41] = new Dsum(); // DSUM        retval[42] = new Daverage(); // DAVERAGE        retval[43] = new Dmin(); // DMIN        retval[44] = new Dmax(); // DMAX        retval[45] = new Dstdev(); // DSTDEV        retval[46] = new Var(); // VAR        retval[47] = new Dvar(); // DVAR        retval[48] = new Text(); // TEXT        retval[49] = new Linest(); // LINEST        retval[50] = new Trend(); // TREND        retval[51] = new Logest(); // LOGEST        retval[52] = new Growth(); // GROWTH        retval[53] = new Goto(); // GOTO        retval[54] = new Halt(); // HALT        retval[56] = FinanceFunction.PV;        retval[57] = FinanceFunction.FV;        retval[58] = FinanceFunction.NPER;        retval[59] = FinanceFunction.PMT;        retval[60] = new Rate(); // RATE        retval[61] = new Mirr(); // MIRR        retval[62] = new Irr(); // IRR        retval[63] = new Rand(); // RAND        retval[64] = new Match(); // MATCH        retval[65] = DateFunc.instance; // DATE        retval[66] = new Time(); // TIME        retval[67] = CalendarFieldFunction.DAY; // DAY        retval[68] = CalendarFieldFunction.MONTH; // MONTH        retval[69] = CalendarFieldFunction.YEAR; // YEAR        retval[70] = new Weekday(); // WEEKDAY        retval[71] = new Hour(); // HOUR        retval[72] = new Minute(); // MINUTE        retval[73] = new Second(); // SECOND        retval[74] = new Now(); // NOW        retval[75] = new Areas(); // AREAS        retval[76] = new Rows(); // ROWS        retval[77] = new Columns(); // COLUMNS        retval[ID.OFFSET] = new Offset(); // OFFSET        retval[79] = new Absref(); // ABSREF        retval[80] = new Relref(); // RELREF        retval[81] = new Argument(); // ARGUMENT        retval[82] = new Search(); // SEARCH        retval[83] = new Transpose(); // TRANSPOSE        retval[84] = new org.apache.poi.hssf.record.formula.functions.Error(); // ERROR        retval[85] = new Step(); // STEP        retval[86] = new Type(); // TYPE        retval[87] = new Echo(); // ECHO        retval[88] = new Setname(); // SETNAME        retval[89] = new Caller(); // CALLER        retval[90] = new Deref(); // DEREF        retval[91] = new NotImplementedFunction(); // WINDOWS        retval[92] = new Series(); // SERIES        retval[93] = new NotImplementedFunction(); // DOCUMENTS        retval[94] = new Activecell(); // ACTIVECELL        retval[95] = new NotImplementedFunction(); // SELECTION        retval[96] = new Result(); // RESULT        retval[97] = NumericFunction.ATAN2;        retval[98] = NumericFunction.ASIN;        retval[99] = NumericFunction.ACOS;        retval[100] = new Choose(); // CHOOSE        retval[101] = new Hlookup(); // HLOOKUP        retval[102] = new Vlookup(); // VLOOKUP        retval[103] = new Links(); // LINKS        retval[104] = new Input(); // INPUT        retval[105] = new Isref(); // ISREF        retval[106] = new NotImplementedFunction(); // GETFORMULA        retval[107] = new NotImplementedFunction(); // GETNAME        retval[108] = new Setvalue(); // SETVALUE        retval[109] = NumericFunction.LOG;        retval[110] = new Exec(); // EXEC        retval[111] = new Char(); // CHAR        retval[112] = TextFunction.LOWER;        retval[113] = TextFunction.UPPER;        retval[114] = new Proper(); // PROPER        retval[115] = TextFunction.LEFT;        retval[116] = TextFunction.RIGHT;        retval[117] = TextFunction.EXACT;        retval[118] = TextFunction.TRIM;        retval[119] = new Replace(); // REPLACE        retval[120] = new Substitute(); // SUBSTITUTE        retval[121] = new Code(); // CODE        retval[122] = new Names(); // NAMES        retval[123] = new NotImplementedFunction(); // DIRECTORY        retval[124] = new Find(); // FIND        retval[125] = new Cell(); // CELL        retval[126] = new Iserr(); // ISERR        retval[127] = new Istext(); // ISTEXT        retval[128] = new Isnumber(); // ISNUMBER        retval[129] = new Isblank(); // ISBLANK        retval[130] = new T(); // T        retval[131] = new N(); // N        retval[132] = new NotImplementedFunction(); // FOPEN        retval[133] = new NotImplementedFunction(); // FCLOSE        retval[134] = new NotImplementedFunction(); // FSIZE        retval[135] = new NotImplementedFunction(); // FREADLN        retval[136] = new NotImplementedFunction(); // FREAD        retval[137] = new NotImplementedFunction(); // FWRITELN        retval[138] = new NotImplementedFunction(); // FWRITE        retval[139] = new Fpos(); // FPOS        retval[140] = new Datevalue(); // DATEVALUE

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?