Print this page
rev 5696 : 6336885: RFE: Locale Data Deployment Enhancements
4609153: Provide locale data for Indic locales
5104387: Support for gl_ES locale (galician language)
6337471: desktop/system locale preferences support
7056139: (cal) SPI support for locale-dependent Calendar parameters
7058206: Provide CalendarData SPI for week params and display field value names
7073852: Support multiple scripts for digits and decimal symbols per locale
7079560: [Fmt-Da] Context dependent month names support in SimpleDateFormat
7171324: getAvailableLocales() of locale sensitive services should return the actual availability of locales
7151414: (cal) Support calendar type identification
7168528: LocaleServiceProvider needs to be aware of Locale extensions
7171372: (cal) locale's default Calendar should be created if unknown calendar is specified
Summary: JEP 127: Improve Locale Data Packaging and Adopt Unicode CLDR Data (part 1 w/o packaging changes. by Naoto Sato and Masayoshi Okutsu)
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/classes/java/text/BreakDictionary.java
+++ new/src/share/classes/sun/util/locale/provider/BreakDictionary.java
1 1 /*
2 - * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
2 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation. Oracle designates this
8 8 * particular file as subject to the "Classpath" exception as provided
9 9 * by Oracle in the LICENSE file that accompanied this code.
10 10 *
11 11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 14 * version 2 for more details (a copy is included in the LICENSE file that
15 15 * accompanied this code).
16 16 *
17 17 * You should have received a copy of the GNU General Public License version
18 18 * 2 along with this work; if not, write to the Free Software Foundation,
19 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 20 *
21 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 22 * or visit www.oracle.com if you need additional information or have any
23 23 * questions.
24 24 */
25 25
26 26 /*
27 27 *
28 28 * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
29 29 * (C) Copyright IBM Corp. 1996 - 2002 - All Rights Reserved
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
30 30 *
31 31 * The original version of this source code and documentation
32 32 * is copyrighted and owned by Taligent, Inc., a wholly-owned
33 33 * subsidiary of IBM. These materials are provided under terms
34 34 * of a License Agreement between Taligent and Sun. This technology
35 35 * is protected by multiple US and International patents.
36 36 *
37 37 * This notice and attribution to Taligent may not be removed.
38 38 * Taligent is a registered trademark of Taligent, Inc.
39 39 */
40 -package java.text;
40 +package sun.util.locale.provider;
41 41
42 -import java.io.*;
42 +import java.io.BufferedInputStream;
43 +import java.io.IOException;
43 44 import java.security.AccessController;
44 45 import java.security.PrivilegedActionException;
45 46 import java.security.PrivilegedExceptionAction;
46 47 import java.util.MissingResourceException;
47 48 import sun.text.CompactByteArray;
48 49 import sun.text.SupplementaryCharacterData;
49 50
50 51 /**
51 52 * This is the class that represents the list of known words used by
52 53 * DictionaryBasedBreakIterator. The conceptual data structure used
53 54 * here is a trie: there is a node hanging off the root node for every
54 55 * letter that can start a word. Each of these nodes has a node hanging
55 56 * off of it for every letter that can be the second letter of a word
56 57 * if this node is the first letter, and so on. The trie is represented
57 58 * as a two-dimensional array that can be treated as a table of state
58 59 * transitions. Indexes are used to compress this array, taking
59 60 * advantage of the fact that this array will always be very sparse.
60 61 */
61 62 class BreakDictionary {
62 63
63 64 //=========================================================================
64 65 // data members
65 66 //=========================================================================
66 67
67 68 /**
68 69 * The version of the dictionary that was read in.
69 70 */
70 71 private static int supportedVersion = 1;
71 72
72 73 /**
73 74 * Maps from characters to column numbers. The main use of this is to
74 75 * avoid making room in the array for empty columns.
75 76 */
76 77 private CompactByteArray columnMap = null;
77 78 private SupplementaryCharacterData supplementaryCharColumnMap = null;
78 79
79 80 /**
80 81 * The number of actual columns in the table
81 82 */
82 83 private int numCols;
83 84
84 85 /**
85 86 * Columns are organized into groups of 32. This says how many
86 87 * column groups. (We could calculate this, but we store the
87 88 * value to avoid having to repeatedly calculate it.)
88 89 */
89 90 private int numColGroups;
90 91
91 92 /**
92 93 * The actual compressed state table. Each conceptual row represents
93 94 * a state, and the cells in it contain the row numbers of the states
94 95 * to transition to for each possible letter. 0 is used to indicate
95 96 * an illegal combination of letters (i.e., the error state). The
96 97 * table is compressed by eliminating all the unpopulated (i.e., zero)
97 98 * cells. Multiple conceptual rows can then be doubled up in a single
98 99 * physical row by sliding them up and possibly shifting them to one
99 100 * side or the other so the populated cells don't collide. Indexes
100 101 * are used to identify unpopulated cells and to locate populated cells.
101 102 */
102 103 private short[] table = null;
103 104
104 105 /**
105 106 * This index maps logical row numbers to physical row numbers
106 107 */
107 108 private short[] rowIndex = null;
108 109
109 110 /**
110 111 * A bitmap is used to tell which cells in the comceptual table are
111 112 * populated. This array contains all the unique bit combinations
112 113 * in that bitmap. If the table is more than 32 columns wide,
113 114 * successive entries in this array are used for a single row.
114 115 */
115 116 private int[] rowIndexFlags = null;
116 117
117 118 /**
118 119 * This index maps from a logical row number into the bitmap table above.
119 120 * (This keeps us from storing duplicate bitmap combinations.) Since there
120 121 * are a lot of rows with only one populated cell, instead of wasting space
121 122 * in the bitmap table, we just store a negative number in this index for
122 123 * rows with one populated cell. The absolute value of that number is
123 124 * the column number of the populated cell.
124 125 */
125 126 private short[] rowIndexFlagsIndex = null;
126 127
↓ open down ↓ |
74 lines elided |
↑ open up ↑ |
127 128 /**
128 129 * For each logical row, this index contains a constant that is added to
129 130 * the logical column number to get the physical column number
130 131 */
131 132 private byte[] rowIndexShifts = null;
132 133
133 134 //=========================================================================
134 135 // deserialization
135 136 //=========================================================================
136 137
137 - public BreakDictionary(String dictionaryName)
138 + BreakDictionary(String dictionaryName)
138 139 throws IOException, MissingResourceException {
139 140
140 141 readDictionaryFile(dictionaryName);
141 142 }
142 143
143 144 private void readDictionaryFile(final String dictionaryName)
144 145 throws IOException, MissingResourceException {
145 146
146 147 BufferedInputStream in;
147 148 try {
148 149 in = AccessController.doPrivileged(
149 150 new PrivilegedExceptionAction<BufferedInputStream>() {
151 + @Override
150 152 public BufferedInputStream run() throws Exception {
151 153 return new BufferedInputStream(getClass().getResourceAsStream("/sun/text/resources/" + dictionaryName));
152 154 }
153 155 }
154 156 );
155 157 }
156 158 catch (PrivilegedActionException e) {
157 159 throw new InternalError(e.toString(), e);
158 160 }
159 161
160 162 byte[] buf = new byte[8];
161 163 if (in.read(buf) != 8) {
162 164 throw new MissingResourceException("Wrong data length",
163 165 dictionaryName, "");
164 166 }
165 167
166 - // check vesion
167 - int version = BreakIterator.getInt(buf, 0);
168 + // check version
169 + int version = RuleBasedBreakIterator.getInt(buf, 0);
168 170 if (version != supportedVersion) {
169 171 throw new MissingResourceException("Dictionary version(" + version + ") is unsupported",
170 172 dictionaryName, "");
171 173 }
172 174
173 175 // get data size
174 - int len = BreakIterator.getInt(buf, 4);
176 + int len = RuleBasedBreakIterator.getInt(buf, 4);
175 177 buf = new byte[len];
176 178 if (in.read(buf) != len) {
177 179 throw new MissingResourceException("Wrong data length",
178 180 dictionaryName, "");
179 181 }
180 182
181 183 // close the stream
182 184 in.close();
183 185
184 186 int l;
185 187 int offset = 0;
186 188
187 189 // read in the column map for BMP characteres (this is serialized in
188 190 // its internal form: an index array followed by a data array)
189 - l = BreakIterator.getInt(buf, offset);
191 + l = RuleBasedBreakIterator.getInt(buf, offset);
190 192 offset += 4;
191 193 short[] temp = new short[l];
192 194 for (int i = 0; i < l; i++, offset+=2) {
193 - temp[i] = BreakIterator.getShort(buf, offset);
195 + temp[i] = RuleBasedBreakIterator.getShort(buf, offset);
194 196 }
195 - l = BreakIterator.getInt(buf, offset);
197 + l = RuleBasedBreakIterator.getInt(buf, offset);
196 198 offset += 4;
197 199 byte[] temp2 = new byte[l];
198 200 for (int i = 0; i < l; i++, offset++) {
199 201 temp2[i] = buf[offset];
200 202 }
201 203 columnMap = new CompactByteArray(temp, temp2);
202 204
203 205 // read in numCols and numColGroups
204 - numCols = BreakIterator.getInt(buf, offset);
206 + numCols = RuleBasedBreakIterator.getInt(buf, offset);
205 207 offset += 4;
206 - numColGroups = BreakIterator.getInt(buf, offset);
208 + numColGroups = RuleBasedBreakIterator.getInt(buf, offset);
207 209 offset += 4;
208 210
209 211 // read in the row-number index
210 - l = BreakIterator.getInt(buf, offset);
212 + l = RuleBasedBreakIterator.getInt(buf, offset);
211 213 offset += 4;
212 214 rowIndex = new short[l];
213 215 for (int i = 0; i < l; i++, offset+=2) {
214 - rowIndex[i] = BreakIterator.getShort(buf, offset);
216 + rowIndex[i] = RuleBasedBreakIterator.getShort(buf, offset);
215 217 }
216 218
217 219 // load in the populated-cells bitmap: index first, then bitmap list
218 - l = BreakIterator.getInt(buf, offset);
220 + l = RuleBasedBreakIterator.getInt(buf, offset);
219 221 offset += 4;
220 222 rowIndexFlagsIndex = new short[l];
221 223 for (int i = 0; i < l; i++, offset+=2) {
222 - rowIndexFlagsIndex[i] = BreakIterator.getShort(buf, offset);
224 + rowIndexFlagsIndex[i] = RuleBasedBreakIterator.getShort(buf, offset);
223 225 }
224 - l = BreakIterator.getInt(buf, offset);
226 + l = RuleBasedBreakIterator.getInt(buf, offset);
225 227 offset += 4;
226 228 rowIndexFlags = new int[l];
227 229 for (int i = 0; i < l; i++, offset+=4) {
228 - rowIndexFlags[i] = BreakIterator.getInt(buf, offset);
230 + rowIndexFlags[i] = RuleBasedBreakIterator.getInt(buf, offset);
229 231 }
230 232
231 233 // load in the row-shift index
232 - l = BreakIterator.getInt(buf, offset);
234 + l = RuleBasedBreakIterator.getInt(buf, offset);
233 235 offset += 4;
234 236 rowIndexShifts = new byte[l];
235 237 for (int i = 0; i < l; i++, offset++) {
236 238 rowIndexShifts[i] = buf[offset];
237 239 }
238 240
239 241 // load in the actual state table
240 - l = BreakIterator.getInt(buf, offset);
242 + l = RuleBasedBreakIterator.getInt(buf, offset);
241 243 offset += 4;
242 244 table = new short[l];
243 245 for (int i = 0; i < l; i++, offset+=2) {
244 - table[i] = BreakIterator.getShort(buf, offset);
246 + table[i] = RuleBasedBreakIterator.getShort(buf, offset);
245 247 }
246 248
247 249 // finally, prepare the column map for supplementary characters
248 - l = BreakIterator.getInt(buf, offset);
250 + l = RuleBasedBreakIterator.getInt(buf, offset);
249 251 offset += 4;
250 252 int[] temp3 = new int[l];
251 253 for (int i = 0; i < l; i++, offset+=4) {
252 - temp3[i] = BreakIterator.getInt(buf, offset);
254 + temp3[i] = RuleBasedBreakIterator.getInt(buf, offset);
253 255 }
254 256 supplementaryCharColumnMap = new SupplementaryCharacterData(temp3);
255 257 }
256 258
257 259 //=========================================================================
258 260 // access to the words
259 261 //=========================================================================
260 262
261 263 /**
262 264 * Uses the column map to map the character to a column number, then
263 265 * passes the row and column number to getNextState()
264 266 * @param row The current state
265 267 * @param ch The character whose column we're interested in
266 268 * @return The new state to transition to
267 269 */
268 270 public final short getNextStateFromCharacter(int row, int ch) {
269 271 int col;
270 272 if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
271 273 col = columnMap.elementAt((char)ch);
272 274 } else {
273 275 col = supplementaryCharColumnMap.getValue(ch);
274 276 }
275 277 return getNextState(row, col);
276 278 }
277 279
278 280 /**
279 281 * Returns the value in the cell with the specified (logical) row and
280 282 * column numbers. In DictionaryBasedBreakIterator, the row number is
281 283 * a state number, the column number is an input, and the return value
282 284 * is the row number of the new state to transition to. (0 is the
283 285 * "error" state, and -1 is the "end of word" state in a dictionary)
284 286 * @param row The row number of the current state
285 287 * @param col The column number of the input character (0 means "not a
286 288 * dictionary character")
287 289 * @return The row number of the new state to transition to
288 290 */
289 291 public final short getNextState(int row, int col) {
290 292 if (cellIsPopulated(row, col)) {
291 293 // we map from logical to physical row number by looking up the
292 294 // mapping in rowIndex; we map from logical column number to
293 295 // physical column number by looking up a shift value for this
294 296 // logical row and offsetting the logical column number by
295 297 // the shift amount. Then we can use internalAt() to actually
296 298 // get the value out of the table.
297 299 return internalAt(rowIndex[row], col + rowIndexShifts[row]);
↓ open down ↓ |
35 lines elided |
↑ open up ↑ |
298 300 }
299 301 else {
300 302 return 0;
301 303 }
302 304 }
303 305
304 306 /**
305 307 * Given (logical) row and column numbers, returns true if the
306 308 * cell in that position is populated
307 309 */
308 - private final boolean cellIsPopulated(int row, int col) {
310 + private boolean cellIsPopulated(int row, int col) {
309 311 // look up the entry in the bitmap index for the specified row.
310 312 // If it's a negative number, it's the column number of the only
311 313 // populated cell in the row
312 314 if (rowIndexFlagsIndex[row] < 0) {
313 315 return col == -rowIndexFlagsIndex[row];
314 316 }
315 317
316 318 // if it's a positive number, it's the offset of an entry in the bitmap
317 319 // list. If the table is more than 32 columns wide, the bitmap is stored
318 320 // successive entries in the bitmap list, so we have to divide the column
319 321 // number by 32 and offset the number we got out of the index by the result.
320 322 // Once we have the appropriate piece of the bitmap, test the appropriate
321 323 // bit and return the result.
322 324 else {
323 325 int flags = rowIndexFlags[rowIndexFlagsIndex[row] + (col >> 5)];
324 326 return (flags & (1 << (col & 0x1f))) != 0;
↓ open down ↓ |
6 lines elided |
↑ open up ↑ |
325 327 }
326 328 }
327 329
328 330 /**
329 331 * Implementation of getNextState() when we know the specified cell is
330 332 * populated.
331 333 * @param row The PHYSICAL row number of the cell
332 334 * @param col The PHYSICAL column number of the cell
333 335 * @return The value stored in the cell
334 336 */
335 - private final short internalAt(int row, int col) {
337 + private short internalAt(int row, int col) {
336 338 // the table is a one-dimensional array, so this just does the math necessary
337 339 // to treat it as a two-dimensional array (we don't just use a two-dimensional
338 340 // array because two-dimensional arrays are inefficient in Java)
339 341 return table[row * numCols + col];
340 342 }
341 343 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX