Showing the changes to java/pkg/sun/text/SupplementaryCharacterData.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,93 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | * or visit www.oracle.com if you need additional information or have any | ||
| 23 | * 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 | /** | ||
| 51 | * Creates a new SupplementaryCharacterData object with the given table. | ||
| 52 | */ | ||
| 53 | public SupplementaryCharacterData(int[] table) { | ||
| 54 | dataTable = table; | ||
| 55 | } | ||
| 56 | |||
| 57 | /** | ||
| 58 | * Returns a corresponding value for the given supplementary code-point. | ||
| 59 | */ | ||
| 60 | public int getValue(int index) { | ||
| 61 | // Index should be a valid supplementary character. | ||
| 62 | assert index >= Character.MIN_SUPPLEMENTARY_CODE_POINT && | ||
| 63 | index <= Character.MAX_CODE_POINT : | ||
| 64 | "Invalid code point:" + Integer.toHexString(index); | ||
| 65 | |||
| 66 | int i = 0; | ||
| 67 | int j = dataTable.length - 1; | ||
| 68 | int k; | ||
| 69 | |||
| 70 | for (;;) { | ||
| 71 | k = (i + j) / 2; | ||
| 72 | |||
| 73 | int start = dataTable[k] >> 8; | ||
| 74 | int end = dataTable[k+1] >> 8; | ||
| 75 | |||
| 76 | if (index < start) { | ||
| 77 | j = k; | ||
| 78 | } else if (index > (end-1)) { | ||
| 79 | i = k; | ||
| 80 | } else { | ||
| 81 | return dataTable[k] & 0xFF; | ||
| 82 | } | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | /** | ||
| 87 | * Returns the data array. | ||
| 88 | */ | ||
| 89 | public int[] getArray() { | ||
| 90 | return dataTable; | ||
| 91 | } | ||
| 92 | |||
| 93 | } | ||