本文整理了Java中com.ibm.icu.text.Collator
类的一些代码示例,展示了Collator
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collator
类的具体详情如下:
包路径:com.ibm.icu.text.Collator
类名称:Collator
[英]java.text.Collator. usage
Collator performs locale-sensitive string comparison. A concrete subclass, RuleBasedCollator, allows customization of the collation ordering by the use of rule sets.
A Collator is thread-safe only when frozen. See #isFrozen() and Freezable.
Following the Unicode Consortium's specifications for the Unicode Collation Algorithm (UCA), there are 5 different levels of strength used in comparisons:
For more information about the collation service see the User Guide.
Examples of use
// Get the Collator for US English and set its strength to PRIMARY
Collator usCollator = Collator.getInstance(Locale.US);
usCollator.setStrength(Collator.PRIMARY);
if (usCollator.compare("abc", "ABC") == 0) {
System.out.println("Strings are equivalent");
}
The following example shows how to compare two strings using the
Collator for the default locale.
// Compare two strings in the default locale
Collator myCollator = Collator.getInstance();
myCollator.setDecomposition(NO_DECOMPOSITION);
if (myCollator.compare("à\u0325", "a\u0325̀") != 0) {
System.out.println("à\u0325 is not equals to a\u0325̀ without decomposition");
myCollator.setDecomposition(CANONICAL_DECOMPOSITION);
if (myCollator.compare("à\u0325", "a\u0325̀") != 0) {
System.out.println("Error: à\u0325 should be equals to a\u0325̀ with decomposition");
}
else {
System.out.println("à\u0325 is equals to a\u0325̀ with decomposition");
}
}
else {
System.out.println("Error: à\u0325 should be not equals to a\u0325̀ without decomposition");
}
[中]
代码示例来源:origin: org.eclipse/org.eclipse.ui.editors
public int compare(Object o1, Object o2) {
if (!(o2 instanceof ListItem))
return -1;
if (!(o1 instanceof ListItem))
return 1;
String label1= ((ListItem)o1).label;
String label2= ((ListItem)o2).label;
return Collator.getInstance().compare(label1, label2);
}
};
代码示例来源:origin: org.apache.lucene/lucene-analyzers-icu
/**
* Create a new ICUCollatedTermAttributeImpl
* @param collator Collation key generator
*/
public ICUCollatedTermAttributeImpl(Collator collator) {
// clone the collator: see http://userguide.icu-project.org/collation/architecture
try {
this.collator = (Collator) collator.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.ibm.icu/icu4j-localespi
@Override
public void setDecomposition(int decompositionMode) {
switch (decompositionMode) {
case java.text.Collator.CANONICAL_DECOMPOSITION:
fIcuCollator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
break;
case java.text.Collator.NO_DECOMPOSITION:
fIcuCollator.setDecomposition(Collator.NO_DECOMPOSITION);
break;
case java.text.Collator.FULL_DECOMPOSITION:
// Not supported by ICU.
// This option is interpreted as IDENTICAL strength.
fIcuCollator.setStrength(Collator.IDENTICAL);
break;
default:
throw new IllegalArgumentException("Invalid decomposition mode.");
}
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.ui.ide
public CollationKey getDescriptionKey() {
if (descriptionKey == null) {
descriptionKey = Collator.getInstance()
.getCollationKey(description);
}
return descriptionKey;
}
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui
@Override
public int compare(String[] o1, String[] o2) {
return fCollator.compare(o1[1], o2[1]);
}
});
代码示例来源:origin: org.eclipse.platform/org.eclipse.ui.navigator.resources
/**
* Construct a sorter that uses the name of the resource as its sorting
* criteria.
*
*/
public ResourceExtensionSorter() {
super(ResourceSorter.NAME);
icuCollator = Collator.getInstance();
}
代码示例来源:origin: com.yahoo.vespa/container-search
public void setLocale(String locale, Strength strength) {
this.locale = locale;
this.strength = strength;
ULocale uloc;
try {
uloc = new ULocale(locale);
} catch (Throwable e) {
throw new RuntimeException("ULocale("+locale+") failed with exception " + e.toString());
}
try {
collator = Collator.getInstance(uloc);
if (collator == null) {
throw new RuntimeException("No collator available for: " + locale);
}
} catch (Throwable e) {
throw new RuntimeException("Collator.getInstance(ULocale("+locale+")) failed with exception " + e.toString());
}
collator.setStrength(strength2Collator(strength));
// collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
}
public String getLocale() { return locale; }
代码示例来源:origin: io.virtdata/virtdata-lib-realer
/**
* @return this, for chaining
* @internal Used in UnicodeTools
* @deprecated This API is ICU internal only.
*/
@Deprecated
public Collator setStrength2(int newStrength)
{
setStrength(newStrength);
return this;
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.ui.workbench.texteditor
@Override
public int compare(String[] o1, String[] o2) {
return fCollator.compare(o1[1], o2[1]);
}
});
代码示例来源:origin: dita-ot/dita-ot
public IndexCollator(final Locale theLocale) {
this.defaultCollator = java.text.Collator.getInstance(theLocale);
try {
this.icu4jCollator = com.ibm.icu.text.Collator.getInstance(theLocale);
} catch (final NoClassDefFoundError ex) {
System.out.println("[INFO] IBM ICU4J Collator is not found. Default Java Collator will be used");
icuCollator = false;
}
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.ui.ide
public CollationKey getResourceNameKey() {
if (resourceNameKey == null) {
resourceNameKey = Collator.getInstance().getCollationKey(
resourceName);
}
return resourceNameKey;
}
代码示例来源:origin: com.ibm.icu/icu4j-localespi
@Override
public void setStrength(int newStrength) {
switch (newStrength) {
case java.text.Collator.IDENTICAL:
fIcuCollator.setStrength(Collator.IDENTICAL);
break;
case java.text.Collator.PRIMARY:
fIcuCollator.setStrength(Collator.PRIMARY);
break;
case java.text.Collator.SECONDARY:
fIcuCollator.setStrength(Collator.SECONDARY);
break;
case java.text.Collator.TERTIARY:
fIcuCollator.setStrength(Collator.TERTIARY);
break;
default:
throw new IllegalArgumentException("Invalid strength.");
}
}
代码示例来源:origin: org.eclipse/org.eclipse.ui.editors
public int compareTo(Object o) {
if (!(o instanceof NavigationEnablementAction))
return -1;
String otherName= ((NavigationEnablementAction)o).fName;
return Collator.getInstance().compare(fName, otherName);
}
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui
@Override
public int compare(String[] o1, String[] o2) {
return fCollator.compare(o1[1], o2[1]);
}
});
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui
public void sort() {
Comparator<IBinding> comparator= new Comparator<IBinding>() {
Collator collator= Collator.getInstance();
@Override
public int compare(IBinding b1, IBinding b2) {
return collator.compare(b1.getName(), b2.getName());
}
};
Arrays.sort(fFields, comparator);
Arrays.sort(fMethods, comparator);
Arrays.sort(fInheritedFields, comparator);
Arrays.sort(fInheritedMethods, comparator);
}
代码示例来源:origin: org.elasticsearch.plugin/analysis-icu
/**
*
* @param input Source token stream
* @param collator CollationKey generator
*/
public ICUCollationKeyFilter(TokenStream input, Collator collator) {
super(input);
// clone the collator: see http://userguide.icu-project.org/collation/architecture
try {
this.collator = (Collator) collator.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.ui.editors
@Override
public int compare(ListItem o1, ListItem o2) {
String label1= o1.name;
String label2= o2.name;
return Collator.getInstance().compare(label1, label2);
}
};
代码示例来源:origin: dita-ot/dita-ot
public int compare(final Object o1, final Object o2) {
if (icuCollator) {
return this.icu4jCollator.compare(o1, o2);
} else {
return this.defaultCollator.compare(o1, o2);
}
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui
public void sort() {
Comparator<IBinding> comparator= new Comparator<IBinding>() {
Collator collator= Collator.getInstance();
@Override
public int compare(IBinding b1, IBinding b2) {
return collator.compare(b1.getName(), b2.getName());
}
};
Arrays.sort(fFields, comparator);
Arrays.sort(fMethods, comparator);
Arrays.sort(fInheritedFields, comparator);
Arrays.sort(fInheritedMethods, comparator);
}
代码示例来源:origin: org.apache.lucene/lucene-icu
/**
*
* @param input Source token stream
* @param collator CollationKey generator
*/
public ICUCollationKeyFilter(TokenStream input, Collator collator) {
super(input);
// clone the collator: see http://userguide.icu-project.org/collation/architecture
try {
this.collator = (Collator) collator.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
}
内容来源于网络,如有侵权,请联系作者删除!