public class RuleBasedCollator extends Collator
Collator
RuleBasedCollator
类,提供了一个简单的、数据驱动的一个具体子类,表整理。这个类,你可以创建一个定制的基于表的
Collator
。
RuleBasedCollator
映射字符排序的键。
RuleBasedCollator
有以下限制效率(其他子类可以用于更复杂的语言):
排序规则表由一个排序规则列表组成,其中每个规则都是三种形式之一:
<修改> <关系> <文本参数> <重置> <文本参数>文本参数> 重置> 文本参数> 关系> 修改>规则的元素定义如下:
b c
作为bc
。“@”:指示重音在向后排列,如在法语中。
“”:指示下一条规则如下位置,以将重置文本参数进行排序。
这听起来比它在实践中更复杂。例如,以下是表达同一事物的等效方法:
注意顺序是很重要的,作为后续项目的文本参数后立即。以下是不等价的:a < b < c a < b & b < c a < c & a < b
或文本参数必须已在序列中出现的文本,或争论一些初始字符串必须出现。(例如:“A”是有效的,因为“A”是存在于序列中的“自动曝光”重置之前。在这后一种情况下,“自动曝光”是没有输入和处理作为一个单一的字符,相反,“E”是排序,因为如果它扩展到两个字符:“A”后面的“E”。这种差异出现在自然语言:在传统的西班牙“CH”视同合同,单个字符(表示为“C<CH<D”),而在传统的德国a-umlaut视同扩展到两个字符(表示为“,一组B,B…“u00e3发射;发射;\ u00c3”)。【\ u00e3和u00c3,当然,对于a-umlaut转义序列。]a < b & a < c a < c & a < b
可忽略的人物
对于小人物,首先一定要有一个关系(实例我们用上面真的片段;“< b”真的应该是“<B”)。如果,然而,第一种关系不是“<”,然后所有的所有文字争论到第一个“<”不容忽视。例如,“,-<B“做”-“可忽略的人物,我们看到在“黑色的鸟早”。在样品的不同的语言,你看到大多数的口音是可以忽略的。
归一化和口音
RuleBasedCollator
自动过程的规则表,包括前组成并结合重音字符字符版本。即使提供的规则字符串只包含基本特征和分离相结合的口音特点,预先由重音字符从规则的字符串匹配字符的所有规范的组合将进入表。
这允许您使用rulebasedcollator比较重音弦即使对照设置为no_decomposition。有两点需要注意,但是。首先,如果字符串是整理包含组合序列可能不规范秩序,你应该整理到canonical_decomposition或full_decomposition使组合序列排序。其次,如果字符串包含兼容性分解特征(如全角半角形式),你必须使用full_decomposition,因为规则表只包括正则映射。
错误
以下是错误:
RuleBasedCollator
抛出一个
ParseException
。
实例
简单:“< A >
挪威:“<,< B,B<C,C<D,D组、E组、F组、G组、H组我,我< J,J<K,K<L,L<m,m<n,n<O,O < P,P Q,Q<R,R<S,S<T,T<u,u<V,V<W,W<x,x<y,y<Z,Z < \ u00e6,\ u00c6 < \ u00f8,\ u00d8 < \ u00e5 = \ u030a,\ u00c5 = \ u030a;AA、AA”
创建一个专门的规则,根据你的需要RuleBasedCollator
对象,你构建的RuleBasedCollator
与包含在String
对象的规则。例如:
或:String simple = "< a< b< c< d"; RuleBasedCollator mySimple = new RuleBasedCollator(simple);
String Norwegian = "< a, A < b, B < c, C < d, D < e, E < f, F < g, G < h, H < i, I" + "< j, J < k, K < l, L < m, M < n, N < o, O < p, P < q, Q < r, R" + "< s, S < t, T < u, U < v, V < w, W < x, X < y, Y < z, Z" + "< \u00E6, \u00C6" + // Latin letter ae & AE "< \u00F8, \u00D8" + // Latin letter o & O with stroke "< \u00E5 = a\u030A," + // Latin letter a with ring above " \u00C5 = A\u030A;" + // Latin letter A with ring above " aa, AA"; RuleBasedCollator myNorwegian = new RuleBasedCollator(Norwegian);
一个新的排序规则的字符串可以通过连接字符串创建规则。例如,通过getRules()
返回的规则可以将多个RuleBasedCollator
s级联。
下面的示例演示如何更改非间距重音的顺序,
// old rule String oldRules = "=\u0301;\u0300;\u0302;\u0308" // main accents + ";\u0327;\u0303;\u0304;\u0305" // main accents + ";\u0306;\u0307;\u0309;\u030A" // main accents + ";\u030B;\u030C;\u030D;\u030E" // main accents + ";\u030F;\u0310;\u0311;\u0312" // main accents + "< a , A ; ae, AE ; \u00e6 , \u00c6" + "< b , B < c, C < e, E & C < d, D"; // change the order of accent characters String addOn = "& \u0300 ; \u0308 ; \u0302"; RuleBasedCollator myCollator = new RuleBasedCollator(oldRules + addOn);
Collator
,
CollationElementIterator
CANONICAL_DECOMPOSITION, FULL_DECOMPOSITION, IDENTICAL, NO_DECOMPOSITION, PRIMARY, SECONDARY, TERTIARY
Constructor and Description |
---|
RuleBasedCollator(String rules)
rulebasedcollator构造函数。
|
Modifier and Type | Method and Description |
---|---|
Object |
clone()
标准重写;语义没有更改。
|
int |
compare(String source, String target)
比较基于排序规则规则的两个不同字符串中存储的字符数据。
|
boolean |
equals(Object obj)
比较两个排序规则对象的相等性。
|
CollationElementIterator |
getCollationElementIterator(CharacterIterator source)
返回一个给定的characteriterator CollationElementIterator。
|
CollationElementIterator |
getCollationElementIterator(String source)
返回一个给定字符串CollationElementIterator。
|
CollationKey |
getCollationKey(String source)
将字符串转换成一系列的人物,可与CollationKey.compareTo相比。
|
String |
getRules()
获取排序规则对象的表为基础的规则。
|
int |
hashCode()
生成基于表的排序规则对象的哈希代码
|
compare, equals, getAvailableLocales, getDecomposition, getInstance, getInstance, getStrength, setDecomposition, setStrength
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
comparing, comparing, comparingDouble, comparingInt, comparingLong, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
public RuleBasedCollator(String rules) throws ParseException
rules
的排序规则建立整理表。
ParseException
-格式异常将在规则的建立过程失败时引发。例如,建立规则“A”?< D”会导致构造函数抛出ParseException因为'吗?”是不被引用。
Locale
public String getRules()
public CollationElementIterator getCollationElementIterator(String source)
source
-被整理的字符串
CollationElementIterator
对象
CollationElementIterator
public CollationElementIterator getCollationElementIterator(CharacterIterator source)
source
的迭代器进行整理
CollationElementIterator
对象
CollationElementIterator
public int compare(String source, String target)
compare
方法重写,继承类
Collator
source
-源字符串。
target
-目标字符串。
NullPointerException
-如果
source
或
target
是空的。
CollationKey
,
Collator.getCollationKey(java.lang.String)
public CollationKey getCollationKey(String source)
getCollationKey
方法重写,继承类
Collator
source
-被转化成一个排序键的字符串。
CollationKey
,
Collator.compare(java.lang.String, java.lang.String)
public boolean equals(Object obj)
equals
接口
Comparator<Object>
equals
方法重写,继承类
Collator
obj
整理对象的表是与此相比。
Object.hashCode()
,
HashMap
public int hashCode()
hashCode
方法重写,继承类
Collator
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.