1 /* GENERATED SOURCE. DO NOT MODIFY. */ 2 // 2016 and later: Unicode, Inc. and others. 3 // License & terms of use: http://www.unicode.org/copyright.html#License 4 /* 5 ******************************************************************************* 6 * Copyright (C) 2013-2015, International Business Machines 7 * Corporation and others. All Rights Reserved. 8 ******************************************************************************* 9 * CollationTailoring.java, ported from collationtailoring.h/.cpp 10 * 11 * C++ version created on: 2013mar12 12 * created by: Markus W. Scherer 13 */ 14 15 package android.icu.impl.coll; 16 17 import java.util.Map; 18 19 import android.icu.impl.Norm2AllModes; 20 import android.icu.impl.Normalizer2Impl; 21 import android.icu.impl.Trie2_32; 22 import android.icu.text.UnicodeSet; 23 import android.icu.util.ULocale; 24 import android.icu.util.UResourceBundle; 25 import android.icu.util.VersionInfo; 26 27 /** 28 * Collation tailoring data & settings. 29 * This is a container of values for a collation tailoring 30 * built from rules or deserialized from binary data. 31 * 32 * It is logically immutable: Do not modify its values. 33 * The fields are public for convenience. 34 * @hide Only a subset of ICU is exposed in Android 35 */ 36 public final class CollationTailoring { 37 CollationTailoring(SharedObject.Reference<CollationSettings> baseSettings) { 38 if(baseSettings != null) { 39 assert(baseSettings.readOnly().reorderCodes.length == 0); 40 assert(baseSettings.readOnly().reorderTable == null); 41 assert(baseSettings.readOnly().minHighNoReorder == 0); 42 settings = baseSettings.clone(); 43 } else { 44 settings = new SharedObject.Reference<CollationSettings>(new CollationSettings()); 45 } 46 } 47 48 void ensureOwnedData() { 49 if(ownedData == null) { 50 Normalizer2Impl nfcImpl = Norm2AllModes.getNFCInstance().impl; 51 ownedData = new CollationData(nfcImpl); 52 } 53 data = ownedData; 54 } 55 56 /** Not thread-safe, call only before sharing. */ 57 void setRules(String r) { 58 assert rules == null && rulesResource == null; 59 rules = r; 60 } 61 /** Not thread-safe, call only before sharing. */ 62 void setRulesResource(UResourceBundle res) { 63 assert rules == null && rulesResource == null; 64 rulesResource = res; 65 } 66 public String getRules() { 67 if (rules != null) { 68 return rules; 69 } 70 if (rulesResource != null) { 71 return rulesResource.getString(); 72 } 73 return ""; 74 } 75 76 static VersionInfo makeBaseVersion(VersionInfo ucaVersion) { 77 return VersionInfo.getInstance( 78 VersionInfo.UCOL_BUILDER_VERSION.getMajor(), 79 (ucaVersion.getMajor() << 3) + ucaVersion.getMinor(), 80 ucaVersion.getMilli() << 6, 81 0); 82 } 83 void setVersion(int baseVersion, int rulesVersion) { 84 // See comments for version field. 85 int r = (rulesVersion >> 16) & 0xff00; 86 int s = (rulesVersion >> 16) & 0xff; 87 int t = (rulesVersion >> 8) & 0xff; 88 int q = rulesVersion & 0xff; 89 version = (VersionInfo.UCOL_BUILDER_VERSION.getMajor() << 24) | 90 (baseVersion & 0xffc000) | // UCA version u.v.w 91 ((r + (r >> 6)) & 0x3f00) | 92 (((s << 3) + (s >> 5) + t + (q << 4) + (q >> 4)) & 0xff); 93 } 94 int getUCAVersion() { 95 // Version second byte/bits 23..16 to bits 11..4, 96 // third byte/bits 15..14 to bits 1..0. 97 return ((version >> 12) & 0xff0) | ((version >> 14) & 3); 98 } 99 100 // data for sorting etc. 101 public CollationData data; // == base data or ownedData 102 public SharedObject.Reference<CollationSettings> settings; // reference-counted 103 // In Java, deserialize the rules string from the resource bundle 104 // only when it is used. (It can be large and is rarely used.) 105 private String rules; 106 private UResourceBundle rulesResource; 107 // The locale is null (C++: bogus) when built from rules or constructed from a binary blob. 108 // It can then be set by the service registration code which is thread-safe. 109 public ULocale actualLocale = ULocale.ROOT; 110 // UCA version u.v.w & rules version r.s.t.q: 111 // version[0]: builder version (runtime version is mixed in at runtime) 112 // version[1]: bits 7..3=u, bits 2..0=v 113 // version[2]: bits 7..6=w, bits 5..0=r 114 // version[3]= (s<<5)+(s>>3)+t+(q<<4)+(q>>4) 115 public int version = 0; 116 117 // owned objects 118 CollationData ownedData; 119 Trie2_32 trie; 120 UnicodeSet unsafeBackwardSet; 121 public Map<Integer, Integer> maxExpansions; 122 123 /* 124 * Not Cloneable: A CollationTailoring cannot be copied. 125 * It is immutable, and the data trie cannot be copied either. 126 */ 127 } 128