1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.xmerge.converter.xml.sxc.pexcel.records.formula; 25 26 import java.util.HashMap; 27 28 /** 29 * This interface defines the attributes of a lookup table for this plugin. 30 * Symbols will generally be either operators (_, -, *, etc) or funtion names. 31 */ 32 public abstract class SymbolLookup { 33 34 protected HashMap stringToID = null; 35 protected HashMap idToString = null; 36 37 /** 38 * Perform lookup table specific initialization. This would typically entail loading values into 39 * the lookup table. It is best to optimize this process so that data is loaded statically and shared 40 * across all instances of the lookup table. 41 */ initialize()42 abstract public void initialize(); 43 44 /** 45 * Associate a symbol with a numeric value in the lookup table 46 * @param symbol The symbol that will act as the key in the lookup table 47 * @param id The value to be associated with a given symbol 48 */ addEntry(String symbol, int id)49 public void addEntry(String symbol, int id) { 50 Integer iObj = new Integer(id); 51 stringToID.put(symbol, iObj); 52 idToString.put(iObj, symbol); 53 } 54 55 /** 56 * Retrieve the symbol associated with a given identifier 57 * @param id The identfier for which we need to retieve the symbol string 58 * @return The string associated with this identifier in the lookup table. 59 */ getStringFromID(int id)60 public String getStringFromID(int id) { 61 return (String)idToString.get(new Integer(id)); 62 } 63 64 /** 65 * Retrieve the identifier associated with a given symbol 66 * @param symbol The symbol for which we need to retieve the identifier 67 * @throws UnsupportedFunctionException Thown when the symbol is not found in the lookup table 68 * @return The identifier associated with this string in the lookup table. 69 */ getIDFromString(String symbol)70 public int getIDFromString(String symbol) throws UnsupportedFunctionException { 71 Integer i = (Integer)stringToID.get(symbol); 72 if (i == null) 73 throw new UnsupportedFunctionException("Token '" + symbol + "' not supported by Pocket Excel"); 74 75 return ((Integer)stringToID.get(symbol)).intValue(); 76 } 77 } 78