01: /*
02: * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun in the LICENSE file that accompanied this code.
10: *
11: * This code is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14: * version 2 for more details (a copy is included in the LICENSE file that
15: * accompanied this code).
16: *
17: * You should have received a copy of the GNU General Public License version
18: * 2 along with this work; if not, write to the Free Software Foundation,
19: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20: *
21: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25:
26: package sun.text;
27:
28: /**
29: * SupplementaryCharacterData is an SMI-private class which was written for
30: * RuleBasedBreakIterator and BreakDictionary.
31: */
32: public final class SupplementaryCharacterData implements Cloneable {
33:
34: /**
35: * An array for supplementary characters and values.
36: * Lower one byte is used to keep a byte-value.
37: * Upper three bytes are used to keep the first supplementary character
38: * which has the value. The value is also valid for the following
39: * supplementary characters until the next supplementary character in
40: * the array <code>dataTable</code>.
41: * For example, if the value of <code>dataTable[2]</code> is
42: * <code>0x01000123</code> and the value of <code>dataTable[3]</code> is
43: * <code>0x01000567</code>, supplementary characters from
44: * <code>0x10001</code> to <code>0x10004</code> has the value
45: * <code>0x23</code>. And, <code>getValue(0x10003)</code> returns the value.
46: */
47: private int[] dataTable;
48:
49: /**
50: * Creates a new SupplementaryCharacterData object with the given table.
51: */
52: public SupplementaryCharacterData(int[] table) {
53: dataTable = table;
54: }
55:
56: /**
57: * Returns a corresponding value for the given supplementary code-point.
58: */
59: public int getValue(int index) {
60: // Index should be a valid supplementary character.
61: assert index >= Character.MIN_SUPPLEMENTARY_CODE_POINT
62: && index <= Character.MAX_CODE_POINT : "Invalid code point:"
63: + Integer.toHexString(index);
64:
65: int i = 0;
66: int j = dataTable.length - 1;
67: int k;
68:
69: for (;;) {
70: k = (i + j) / 2;
71:
72: int start = dataTable[k] >> 8;
73: int end = dataTable[k + 1] >> 8;
74:
75: if (index < start) {
76: j = k;
77: } else if (index > (end - 1)) {
78: i = k;
79: } else {
80: return dataTable[k] & 0xFF;
81: }
82: }
83: }
84:
85: /**
86: * Returns the data array.
87: */
88: public int[] getArray() {
89: return dataTable;
90: }
91:
92: }
|