KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*********************************************************************
2 *
3 * Copyright (C) 2002 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.HashMap JavaDoc;
23
24 /**
25  * An enumeration detailing the Excel parsed tokens
26  * A particular token may be associated with more than one token code
27  */

28 class Token
29 {
30   /**
31    * The array of values which apply to this token
32    */

33   public final int[] value;
34
35   /**
36    * All available tokens, keyed on value
37    */

38   private static HashMap JavaDoc tokens = new HashMap JavaDoc(20);
39
40   /**
41    * Constructor
42    * Sets the token value and adds this token to the array of all token
43    *
44    * @param v the biff code for the token
45    */

46   private Token(int v)
47   {
48     value = new int[] {v};
49
50     tokens.put(new Integer JavaDoc(v), this);
51   }
52
53   /**
54    * Constructor
55    * Sets the token value and adds this token to the array of all token
56    *
57    * @param v the biff code for the token
58    */

59   private Token(int v1, int v2)
60   {
61     value = new int[] {v1, v2};
62
63     tokens.put(new Integer JavaDoc(v1), this);
64     tokens.put(new Integer JavaDoc(v2), this);
65   }
66
67   /**
68    * Constructor
69    * Sets the token value and adds this token to the array of all token
70    *
71    * @param v the biff code for the token
72    */

73   private Token(int v1, int v2, int v3)
74   {
75     value = new int[] {v1, v2, v3};
76
77     tokens.put(new Integer JavaDoc(v1), this);
78     tokens.put(new Integer JavaDoc(v2), this);
79     tokens.put(new Integer JavaDoc(v3), this);
80   }
81
82   /**
83    * Constructor
84    * Sets the token value and adds this token to the array of all token
85    *
86    * @param v the biff code for the token
87    */

88   private Token(int v1, int v2, int v3, int v4)
89   {
90     value = new int[] {v1, v2, v3, v4};
91
92     tokens.put(new Integer JavaDoc(v1), this);
93     tokens.put(new Integer JavaDoc(v2), this);
94     tokens.put(new Integer JavaDoc(v3), this);
95     tokens.put(new Integer JavaDoc(v4), this);
96   }
97
98   /**
99    * Constructor
100    * Sets the token value and adds this token to the array of all token
101    *
102    * @param v the biff code for the token
103    */

104   private Token(int v1, int v2, int v3, int v4, int v5)
105   {
106     value = new int[] {v1, v2, v3, v4, v5};
107
108     tokens.put(new Integer JavaDoc(v1), this);
109     tokens.put(new Integer JavaDoc(v2), this);
110     tokens.put(new Integer JavaDoc(v3), this);
111     tokens.put(new Integer JavaDoc(v4), this);
112     tokens.put(new Integer JavaDoc(v5), this);
113   }
114
115   /**
116    * Gets the token code for the specified token
117    *
118    * @return the token code. This is the first item in the array
119    */

120   public byte getCode()
121   {
122     return (byte) value[0];
123   }
124
125   /**
126    * Gets an alternative token code for the specified token
127    * Used for certain types of volatile function
128    *
129    * @return the token code
130    */

131   public byte getCode2()
132   {
133     return (byte) (value.length > 0 ? value[1] : value[0]);
134   }
135
136   /**
137    * Gets the type object from its integer value
138    */

139   public static Token getToken(int v)
140   {
141     Token t = (Token) tokens.get(new Integer JavaDoc(v));
142     
143     return t != null ? t : UNKNOWN;
144   }
145
146   // Operands
147
public static final Token REF = new Token(0x44, 0x24, 0x64);
148   public static final Token REF3D = new Token(0x5a, 0x3a, 0x7a);
149   public static final Token MISSING_ARG = new Token(0x16);
150   public static final Token STRING = new Token(0x17);
151   public static final Token BOOL = new Token(0x1d);
152   public static final Token INTEGER = new Token(0x1e);
153   public static final Token DOUBLE = new Token(0x1f);
154   public static final Token REFV = new Token(0x2c, 0x4c);
155   public static final Token AREAV = new Token(0x2d, 0x4d, 0x6d);
156   public static final Token AREA = new Token(0x25, 0x65, 0x45);
157   public static final Token NAMED_RANGE = new Token(0x43, 0x23);
158   public static final Token NAME = new Token(0x39);
159   public static final Token AREA3D = new Token(0x3b);
160
161   // Unary Operators
162
public static final Token UNARY_PLUS = new Token(0x12);
163   public static final Token UNARY_MINUS = new Token(0x13);
164   public static final Token PERCENT = new Token(0x14);
165   public static final Token PARENTHESIS = new Token(0x15);
166
167   // Binary Operators
168
public static final Token ADD = new Token(0x3);
169   public static final Token SUBTRACT = new Token(0x4);
170   public static final Token MULTIPLY = new Token(0x5);
171   public static final Token DIVIDE = new Token(0x6);
172   public static final Token POWER = new Token(0x7);
173   public static final Token CONCAT = new Token(0x8);
174   public static final Token LESS_THAN = new Token(0x9);
175   public static final Token LESS_EQUAL = new Token(0xa);
176   public static final Token EQUAL = new Token(0xb);
177   public static final Token GREATER_EQUAL = new Token(0xc);
178   public static final Token GREATER_THAN = new Token(0xd);
179   public static final Token NOT_EQUAL = new Token(0xe);
180   public static final Token RANGE = new Token(0x11);
181
182   // Functions
183
public static final Token FUNCTION = new Token(0x41, 0x21, 0x61);
184   public static final Token FUNCTIONVARARG = new Token(0x42, 0x22, 0x62);
185
186   // Control
187
public static final Token ATTRIBUTE = new Token(0x19);
188   public static final Token MEM_FUNC = new Token(0x29, 0x49, 0x69);
189
190   // Unknown token
191
public static final Token UNKNOWN = new Token(0xffff);
192 }
193
194
Popular Tags