Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 0 Fork 0

gwdcode/JDK11.0.2-lib.src.java.base.java

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (1)
master
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
The license selected for the repository is subject to the license used by the main branch of the repository.
master
Branches (1)
master
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (1)
master
jdk11.0.2lib.src.java.base.java
/
text
/
MergeCollation.java
jdk11.0.2lib.src.java.base.java
/
text
/
MergeCollation.java
MergeCollation.java 11.35 KB
Copy Edit Raw Blame History
gwdcode authored 2020年10月30日 22:13 +08:00 . 常用普通java包(jdk11.0.2)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
/*
* Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
/*
* (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
* (C) Copyright IBM Corp. 1996, 1997 - All Rights Reserved
*
* The original version of this source code and documentation is copyrighted
* and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
* materials are provided under terms of a License Agreement between Taligent
* and Sun. This technology is protected by multiple US and International
* patents. This notice and attribution to Taligent may not be removed.
* Taligent is a registered trademark of Taligent, Inc.
*
*/
package java.text;
import java.util.ArrayList;
/**
* Utility class for normalizing and merging patterns for collation.
* Patterns are strings of the form <entry>*, where <entry> has the
* form:
* <pattern> := <entry>*
* <entry> := <separator><chars>{"/"<extension>}
* <separator> := "=", ",", ";", "<", "&"
* <chars>, and <extension> are both arbitrary strings.
* unquoted whitespaces are ignored.
* 'xxx' can be used to quote characters
* One difference from Collator is that & is used to reset to a current
* point. Or, in other words, it introduces a new sequence which is to
* be added to the old.
* That is: "a < b < c < d" is the same as "a < b & b < c & c < d" OR
* "a < b < d & b < c"
* XXX: make '' be a single quote.
* @see PatternEntry
* @author Mark Davis, Helena Shih
*/
final class MergeCollation {
/**
* Creates from a pattern
* @exception ParseException If the input pattern is incorrect.
*/
public MergeCollation(String pattern) throws ParseException
{
for (int i = 0; i < statusArray.length; i++)
statusArray[i] = 0;
setPattern(pattern);
}
/**
* recovers current pattern
*/
public String getPattern() {
return getPattern(true);
}
/**
* recovers current pattern.
* @param withWhiteSpace puts spacing around the entries, and \n
* before & and <
*/
public String getPattern(boolean withWhiteSpace) {
StringBuffer result = new StringBuffer();
PatternEntry tmp = null;
ArrayList<PatternEntry> extList = null;
int i;
for (i = 0; i < patterns.size(); ++i) {
PatternEntry entry = patterns.get(i);
if (entry.extension.length() != 0) {
if (extList == null)
extList = new ArrayList<>();
extList.add(entry);
} else {
if (extList != null) {
PatternEntry last = findLastWithNoExtension(i-1);
for (int j = extList.size() - 1; j >= 0 ; j--) {
tmp = extList.get(j);
tmp.addToBuffer(result, false, withWhiteSpace, last);
}
extList = null;
}
entry.addToBuffer(result, false, withWhiteSpace, null);
}
}
if (extList != null) {
PatternEntry last = findLastWithNoExtension(i-1);
for (int j = extList.size() - 1; j >= 0 ; j--) {
tmp = extList.get(j);
tmp.addToBuffer(result, false, withWhiteSpace, last);
}
extList = null;
}
return result.toString();
}
private final PatternEntry findLastWithNoExtension(int i) {
for (--i;i >= 0; --i) {
PatternEntry entry = patterns.get(i);
if (entry.extension.length() == 0) {
return entry;
}
}
return null;
}
/**
* emits the pattern for collation builder.
* @return emits the string in the format understable to the collation
* builder.
*/
public String emitPattern() {
return emitPattern(true);
}
/**
* emits the pattern for collation builder.
* @param withWhiteSpace puts spacing around the entries, and \n
* before & and <
* @return emits the string in the format understable to the collation
* builder.
*/
public String emitPattern(boolean withWhiteSpace) {
StringBuffer result = new StringBuffer();
for (int i = 0; i < patterns.size(); ++i)
{
PatternEntry entry = patterns.get(i);
if (entry != null) {
entry.addToBuffer(result, true, withWhiteSpace, null);
}
}
return result.toString();
}
/**
* sets the pattern.
*/
public void setPattern(String pattern) throws ParseException
{
patterns.clear();
addPattern(pattern);
}
/**
* adds a pattern to the current one.
* @param pattern the new pattern to be added
*/
public void addPattern(String pattern) throws ParseException
{
if (pattern == null)
return;
PatternEntry.Parser parser = new PatternEntry.Parser(pattern);
PatternEntry entry = parser.next();
while (entry != null) {
fixEntry(entry);
entry = parser.next();
}
}
/**
* gets count of separate entries
* @return the size of pattern entries
*/
public int getCount() {
return patterns.size();
}
/**
* gets count of separate entries
* @param index the offset of the desired pattern entry
* @return the requested pattern entry
*/
public PatternEntry getItemAt(int index) {
return patterns.get(index);
}
//============================================================
// privates
//============================================================
ArrayList<PatternEntry> patterns = new ArrayList<>(); // a list of PatternEntries
private transient PatternEntry saveEntry = null;
private transient PatternEntry lastEntry = null;
// This is really used as a local variable inside fixEntry, but we cache
// it here to avoid newing it up every time the method is called.
private transient StringBuffer excess = new StringBuffer();
//
// When building a MergeCollation, we need to do lots of searches to see
// whether a given entry is already in the table. Since we're using an
// array, this would make the algorithm O(N*N). To speed things up, we
// use this bit array to remember whether the array contains any entries
// starting with each Unicode character. If not, we can avoid the search.
// Using BitSet would make this easier, but it's significantly slower.
//
private transient byte[] statusArray = new byte[8192];
private final byte BITARRAYMASK = (byte)0x1;
private final int BYTEPOWER = 3;
private final int BYTEMASK = (1 << BYTEPOWER) - 1;
/*
If the strength is RESET, then just change the lastEntry to
be the current. (If the current is not in patterns, signal an error).
If not, then remove the current entry, and add it after lastEntry
(which is usually at the end).
*/
private final void fixEntry(PatternEntry newEntry) throws ParseException
{
// check to see whether the new entry has the same characters as the previous
// entry did (this can happen when a pattern declaring a difference between two
// strings that are canonically equivalent is normalized). If so, and the strength
// is anything other than IDENTICAL or RESET, throw an exception (you can't
// declare a string to be unequal to itself). --rtg 5/24/99
if (lastEntry != null && newEntry.chars.equals(lastEntry.chars)
&& newEntry.extension.equals(lastEntry.extension)) {
if (newEntry.strength != Collator.IDENTICAL
&& newEntry.strength != PatternEntry.RESET) {
throw new ParseException("The entries " + lastEntry + " and "
+ newEntry + " are adjacent in the rules, but have conflicting "
+ "strengths: A character can't be unequal to itself.", -1);
} else {
// otherwise, just skip this entry and behave as though you never saw it
return;
}
}
boolean changeLastEntry = true;
if (newEntry.strength != PatternEntry.RESET) {
int oldIndex = -1;
if ((newEntry.chars.length() == 1)) {
char c = newEntry.chars.charAt(0);
int statusIndex = c >> BYTEPOWER;
byte bitClump = statusArray[statusIndex];
byte setBit = (byte)(BITARRAYMASK << (c & BYTEMASK));
if (bitClump != 0 && (bitClump & setBit) != 0) {
oldIndex = patterns.lastIndexOf(newEntry);
} else {
// We're going to add an element that starts with this
// character, so go ahead and set its bit.
statusArray[statusIndex] = (byte)(bitClump | setBit);
}
} else {
oldIndex = patterns.lastIndexOf(newEntry);
}
if (oldIndex != -1) {
patterns.remove(oldIndex);
}
excess.setLength(0);
int lastIndex = findLastEntry(lastEntry, excess);
if (excess.length() != 0) {
newEntry.extension = excess + newEntry.extension;
if (lastIndex != patterns.size()) {
lastEntry = saveEntry;
changeLastEntry = false;
}
}
if (lastIndex == patterns.size()) {
patterns.add(newEntry);
saveEntry = newEntry;
} else {
patterns.add(lastIndex, newEntry);
}
}
if (changeLastEntry) {
lastEntry = newEntry;
}
}
private final int findLastEntry(PatternEntry entry,
StringBuffer excessChars) throws ParseException
{
if (entry == null)
return 0;
if (entry.strength != PatternEntry.RESET) {
// Search backwards for string that contains this one;
// most likely entry is last one
int oldIndex = -1;
if ((entry.chars.length() == 1)) {
int index = entry.chars.charAt(0) >> BYTEPOWER;
if ((statusArray[index] &
(BITARRAYMASK << (entry.chars.charAt(0) & BYTEMASK))) != 0) {
oldIndex = patterns.lastIndexOf(entry);
}
} else {
oldIndex = patterns.lastIndexOf(entry);
}
if ((oldIndex == -1))
throw new ParseException("couldn't find last entry: "
+ entry, oldIndex);
return oldIndex + 1;
} else {
int i;
for (i = patterns.size() - 1; i >= 0; --i) {
PatternEntry e = patterns.get(i);
if (e.chars.regionMatches(0,entry.chars,0,
e.chars.length())) {
excessChars.append(entry.chars, e.chars.length(),
entry.chars.length());
break;
}
}
if (i == -1)
throw new ParseException("couldn't find: " + entry, i);
return i + 1;
}
}
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

Releases

No release

Contributors

All

Language(Optional)

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gwdcode/jdk11.0.2lib.src.java.base.java.git
git@gitee.com:gwdcode/jdk11.0.2lib.src.java.base.java.git
gwdcode
jdk11.0.2lib.src.java.base.java
JDK11.0.2-lib.src.java.base.java
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /