KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > biff > formula > FunctionNames


1 /*********************************************************************
2 *
3 * Copyright (C) 2003 Andrew Khan
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ***************************************************************************/

19
20 package jxl.biff.formula;
21
22 import java.util.Locale JavaDoc;
23 import java.util.ResourceBundle JavaDoc;
24 import java.util.HashMap JavaDoc;
25
26 import common.Logger;
27
28 /**
29  * A class which contains the function names for the current workbook. The
30  * function names can potentially vary from workbook to workbook depending
31  * on the locale
32  */

33 public class FunctionNames
34 {
35   /**
36    * The logger class
37    */

38   private static Logger logger = Logger.getLogger(FunctionNames.class);
39
40   /**
41    * A hash mapping keyed on the function and returning its locale specific
42    * name
43    */

44   private HashMap JavaDoc names;
45
46   /**
47    * A hash mapping keyed on the locale specific name and returning the
48    * function
49    */

50   private HashMap JavaDoc functions;
51
52   /**
53    * Constructor
54    * @ws the workbook settings
55    */

56   public FunctionNames(Locale JavaDoc l)
57   {
58     ResourceBundle JavaDoc rb = ResourceBundle.getBundle("functions", l);
59     names = new HashMap JavaDoc(Function.functions.length);
60     functions = new HashMap JavaDoc(Function.functions.length);
61
62     // Iterate through all the functions, adding them to the hash maps
63
Function f = null;
64     String JavaDoc n = null;
65     String JavaDoc propname = null;
66     for (int i = 0; i < Function.functions.length ; i++)
67     {
68       f = Function.functions[i];
69       propname = f.getPropertyName();
70
71       n = propname.length() != 0 ? rb.getString(propname) : null;
72       
73       if (n != null)
74       {
75         names.put(f, n);
76         functions.put(n, f);
77       }
78     }
79   }
80
81   /**
82    * Gets the function for the specified name
83    */

84   Function getFunction(String JavaDoc s)
85   {
86     return (Function) functions.get(s);
87   }
88
89   /**
90    * Gets the name for the function
91    */

92   String JavaDoc getName(Function f)
93   {
94     return (String JavaDoc) names.get(f);
95   }
96 }
97
Popular Tags