本文整理汇总了Java中com.ibm.icu.text.Collator类的典型用法代码示例。如果您正苦于以下问题:Java Collator类的具体用法?Java Collator怎么用?Java Collator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Collator类属于com.ibm.icu.text包,在下文中一共展示了Collator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCustomRules
import com.ibm.icu.text.Collator; //导入依赖的package包/类
public void testCustomRules() throws Exception {
RuleBasedCollator baseCollator = (RuleBasedCollator) Collator.getInstance(new ULocale("de_DE"));
String DIN5007_2_tailorings =
"& ae , a\u0308 & AE , A\u0308"+
"& oe , o\u0308 & OE , O\u0308"+
"& ue , u\u0308 & UE , u\u0308";
RuleBasedCollator tailoredCollator = new RuleBasedCollator(baseCollator.getRules() + DIN5007_2_tailorings);
String tailoredRules = tailoredCollator.getRules();
Settings settings = Settings.builder()
.put("index.analysis.filter.myCollator.type", "icu_collation")
.put("index.analysis.filter.myCollator.rules", tailoredRules)
.put("index.analysis.filter.myCollator.strength", "primary")
.build();
TestAnalysis analysis = createTestAnalysis(new Index("test", "_na_"), settings, new AnalysisICUPlugin());
TokenFilterFactory filterFactory = analysis.tokenFilter.get("myCollator");
assertCollatesToSame(filterFactory, "Töne", "Toene");
}
示例2: getGroupForPrimary
import com.ibm.icu.text.Collator; //导入依赖的package包/类
/**
* Finds the reordering group which contains the primary weight.
* @return the first script of the group, or -1 if the weight is beyond the last group
*/
public int getGroupForPrimary(long p) {
p >>= 16;
if(p < scriptStarts[1] || scriptStarts[scriptStarts.length - 1] <= p) {
return -1;
}
int index = 1;
while(p >= scriptStarts[index + 1]) { ++index; }
for(int i = 0; i < numScripts; ++i) {
if(scriptsIndex[i] == index) {
return i;
}
}
for(int i = 0; i < MAX_NUM_SPECIAL_REORDER_CODES; ++i) {
if(scriptsIndex[numScripts + i] == index) {
return Collator.ReorderCodes.FIRST + i;
}
}
return -1;
}
示例3: getScriptIndex
import com.ibm.icu.text.Collator; //导入依赖的package包/类
private int getScriptIndex(int script) {
if(script < 0) {
return 0;
} else if(script < numScripts) {
return scriptsIndex[script];
} else if(script < Collator.ReorderCodes.FIRST) {
return 0;
} else {
script -= Collator.ReorderCodes.FIRST;
if(script < MAX_NUM_SPECIAL_REORDER_CODES) {
return scriptsIndex[numScripts + script];
} else {
return 0;
}
}
}
示例4: getReorderCode
import com.ibm.icu.text.Collator; //导入依赖的package包/类
/**
* Gets a script or reorder code from its string representation.
* @return the script/reorder code, or
* -1 if not recognized
*/
public static int getReorderCode(String word) {
for(int i = 0; i < gSpecialReorderCodes.length; ++i) {
if(word.equalsIgnoreCase(gSpecialReorderCodes[i])) {
return Collator.ReorderCodes.FIRST + i;
}
}
try {
int script = UCharacter.getPropertyValueEnum(UProperty.SCRIPT, word);
if(script >= 0) {
return script;
}
} catch (IllegalIcuArgumentException e) {
// fall through
}
if(word.equalsIgnoreCase("others")) {
return Collator.ReorderCodes.OTHERS; // same as Zzzz = USCRIPT_UNKNOWN
}
return -1;
}
示例5: findOrInsertNodeForRootCE
import com.ibm.icu.text.Collator; //导入依赖的package包/类
private int findOrInsertNodeForRootCE(long ce, int strength) {
assert((int)(ce >>> 56) != Collation.UNASSIGNED_IMPLICIT_BYTE);
// Find or insert the node for each of the root CE's weights,
// down to the requested level/strength.
// Root CEs must have common=zero quaternary weights (for which we never insert any nodes).
assert((ce & 0xc0) == 0);
int index = findOrInsertNodeForPrimary(ce >>> 32);
if(strength >= Collator.SECONDARY) {
int lower32 = (int)ce;
index = findOrInsertWeakNode(index, lower32 >>> 16, Collator.SECONDARY);
if(strength >= Collator.TERTIARY) {
index = findOrInsertWeakNode(index, lower32 & Collation.ONLY_TERTIARY_MASK,
Collator.TERTIARY);
}
}
return index;
}
示例6: insertTailoredNodeAfter
import com.ibm.icu.text.Collator; //导入依赖的package包/类
/**
* Makes and inserts a new tailored node into the list, after the one at index.
* Skips over nodes of weaker strength to maintain collation order
* ("postpone insertion").
* @return the new node's index
*/
private int insertTailoredNodeAfter(int index, int strength) {
assert(0 <= index && index < nodes.size());
if(strength >= Collator.SECONDARY) {
index = findCommonNode(index, Collator.SECONDARY);
if(strength >= Collator.TERTIARY) {
index = findCommonNode(index, Collator.TERTIARY);
}
}
// Postpone insertion:
// Insert the new node before the next one with a strength at least as strong.
long node = nodes.elementAti(index);
int nextIndex;
while((nextIndex = nextIndexFromNode(node)) != 0) {
node = nodes.elementAti(nextIndex);
if(strengthFromNode(node) <= strength) { break; }
// Skip the next node which has a weaker (larger) strength than the new one.
index = nextIndex;
}
node = IS_TAILORED | nodeFromStrength(strength);
return insertNodeBetween(index, nextIndex, node);
}
示例7: findCommonNode
import com.ibm.icu.text.Collator; //导入依赖的package包/类
/**
* Finds the node which implies or contains a common=05 weight of the given strength
* (secondary or tertiary), if the current node is stronger.
* Skips weaker nodes and tailored nodes if the current node is stronger
* and is followed by an explicit-common-weight node.
* Always returns the input index if that node is no stronger than the given strength.
*/
private int findCommonNode(int index, int strength) {
assert(Collator.SECONDARY <= strength && strength <= Collator.TERTIARY);
long node = nodes.elementAti(index);
if(strengthFromNode(node) >= strength) {
// The current node is no stronger.
return index;
}
if(strength == Collator.SECONDARY ? !nodeHasBefore2(node) : !nodeHasBefore3(node)) {
// The current node implies the strength-common weight.
return index;
}
index = nextIndexFromNode(node);
node = nodes.elementAti(index);
assert(!isTailoredNode(node) && strengthFromNode(node) == strength &&
weight16FromNode(node) < Collation.COMMON_WEIGHT16);
// Skip to the explicit common node.
do {
index = nextIndexFromNode(node);
node = nodes.elementAti(index);
assert(strengthFromNode(node) >= strength);
} while(isTailoredNode(node) || strengthFromNode(node) > strength ||
weight16FromNode(node) < Collation.COMMON_WEIGHT16);
assert(weight16FromNode(node) == Collation.COMMON_WEIGHT16);
return index;
}
示例8: loadGroups
import com.ibm.icu.text.Collator; //导入依赖的package包/类
private boolean loadGroups(CollationData data) {
headerLength = 1 + NUM_SPECIAL_GROUPS;
int r0 = (CollationFastLatin.VERSION << 8) | headerLength;
result.append((char)r0);
// The first few reordering groups should be special groups
// (space, punct, ..., digit) followed by Latn, then Grek and other scripts.
for(int i = 0; i < NUM_SPECIAL_GROUPS; ++i) {
lastSpecialPrimaries[i] = data.getLastPrimaryForGroup(Collator.ReorderCodes.FIRST + i);
if(lastSpecialPrimaries[i] == 0) {
// missing data
return false;
}
result.append(0); // reserve a slot for this group
}
firstDigitPrimary = data.getFirstPrimaryForGroup(Collator.ReorderCodes.DIGIT);
firstLatinPrimary = data.getFirstPrimaryForGroup(UScript.LATIN);
lastLatinPrimary = data.getLastPrimaryForGroup(UScript.LATIN);
if(firstDigitPrimary == 0 || firstLatinPrimary == 0) {
// missing data
return false;
}
return true;
}
示例9: setCollatorStrength
import com.ibm.icu.text.Collator; //导入依赖的package包/类
private static void setCollatorStrength(RuleBasedCollator collator, CollationSpecifier specifier) {
if (specifier.caseSensitive() && specifier.accentSensitive()) {
collator.setStrength(Collator.TERTIARY);
collator.setCaseLevel(false);
}
else if (specifier.caseSensitive() && !specifier.accentSensitive()) {
collator.setCaseLevel(true);
collator.setStrength(Collator.PRIMARY);
}
else if (!specifier.caseSensitive() && specifier.accentSensitive()) {
collator.setStrength(Collator.SECONDARY);
collator.setCaseLevel(false);
}
else {
collator.setStrength(Collator.PRIMARY);
collator.setCaseLevel(false);
}
}
示例10: testCollationKeySort
import com.ibm.icu.text.Collator; //导入依赖的package包/类
public void testCollationKeySort() throws Exception {
Analyzer usAnalyzer = new ICUCollationKeyAnalyzer
(TEST_VERSION_CURRENT, Collator.getInstance(Locale.ROOT));
Analyzer franceAnalyzer = new ICUCollationKeyAnalyzer
(TEST_VERSION_CURRENT, Collator.getInstance(Locale.FRANCE));
Analyzer swedenAnalyzer = new ICUCollationKeyAnalyzer
(TEST_VERSION_CURRENT, Collator.getInstance(new Locale("sv", "se")));
Analyzer denmarkAnalyzer = new ICUCollationKeyAnalyzer
(TEST_VERSION_CURRENT, Collator.getInstance(new Locale("da", "dk")));
// The ICU Collator and java.text.Collator implementations differ in their
// orderings - "BFJHD" is the ordering for the ICU Collator for Locale.ROOT.
testCollationKeySort
(usAnalyzer, franceAnalyzer, swedenAnalyzer, denmarkAnalyzer,
"BFJHD", "ECAGI", "BJDFH", "BJDHF");
}
示例11: createStaticFields
import com.ibm.icu.text.Collator; //导入依赖的package包/类
private String createStaticFields() {
HashSet<String> added= new HashSet<String>();
List<NLSSubstitution> subs= new ArrayList<NLSSubstitution>();
for (int i= 0; i < fNLSSubstitutions.length; i++) {
NLSSubstitution substitution= fNLSSubstitutions[i];
int newState= substitution.getState();
if ((substitution.hasStateChanged() || substitution.isAccessorRename())&& newState == NLSSubstitution.EXTERNALIZED) {
if (added.add(substitution.getKey()))
subs.add(substitution);
}
}
Collections.sort(subs, new Comparator<NLSSubstitution>() {
private Collator fCollator= Collator.getInstance();
public int compare(NLSSubstitution s0, NLSSubstitution s1) {
return fCollator.compare(s0.getKey(), s1.getKey());
}
});
StringBuffer buf= new StringBuffer();
for (Iterator<NLSSubstitution> iter= subs.iterator(); iter.hasNext();) {
NLSSubstitution element= iter.next();
appendStaticField(buf, element);
}
return buf.toString();
}
示例12: insert
import com.ibm.icu.text.Collator; //导入依赖的package包/类
/**
* Inserts the given key value pairs into this model at appropriate
* positions. Records all required text changes in the given change
*
* @param keyValuePairs the key value pairs to insert
* @param change the change to use to record text changes
*/
public void insert(KeyValuePair[] keyValuePairs, TextChange change) {
ArrayList<KeyValuePair> sorted= new ArrayList<KeyValuePair>(Arrays.asList(keyValuePairs));
Collections.sort(sorted, new Comparator<KeyValuePair>() {
public int compare(KeyValuePair p1, KeyValuePair p2) {
return Collator.getInstance().compare(p1.fKey, p2.fKey);
}
});
for (int i = 0; i < sorted.size(); i++) {
KeyValuePair curr= sorted.get(i);
InsertEdit insertEdit= insert(curr);
String message= Messages.format(NLSMessages.NLSPropertyFileModifier_add_entry, BasicElementLabels.getJavaElementName(curr.getKey()));
TextChangeCompatibility.addTextEdit(change, message, insertEdit);
}
}
示例13: ensurePagesRegistered
import com.ibm.icu.text.Collator; //导入依赖的package包/类
private synchronized void ensurePagesRegistered() {
if (fPageDescriptors != null)
return;
ArrayList<CleanUpTabPageDescriptor> result= new ArrayList<CleanUpTabPageDescriptor>();
IExtensionPoint point= Platform.getExtensionRegistry().getExtensionPoint(JavaPlugin.getPluginId(), EXTENSION_POINT_NAME);
IConfigurationElement[] elements= point.getConfigurationElements();
for (int i= 0; i < elements.length; i++) {
IConfigurationElement element= elements[i];
if (TABPAGE_CONFIGURATION_ELEMENT_NAME.equals(element.getName())) {
result.add(new CleanUpTabPageDescriptor(element));
}
}
fPageDescriptors= result.toArray(new CleanUpTabPageDescriptor[result.size()]);
Arrays.sort(fPageDescriptors, new Comparator<CleanUpTabPageDescriptor>() {
public int compare(CleanUpTabPageDescriptor o1, CleanUpTabPageDescriptor o2) {
String name1= o1.getName();
String name2= o2.getName();
return Collator.getInstance().compare(name1.replaceAll("&", ""), name2.replaceAll("&", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
});
}
示例14: compare
import com.ibm.icu.text.Collator; //导入依赖的package包/类
public int compare(String o1, String o2) {
if (o1.equals(o2))
return 0;
History history= QualifiedTypeNameHistory.getDefault();
int pos1= history.getPosition(o1);
int pos2= history.getPosition(o2);
if (pos1 == pos2)
return Collator.getInstance().compare(o1, o2);
if (pos1 > pos2) {
return -1;
} else {
return 1;
}
}
示例15: makeCheck
import com.ibm.icu.text.Collator; //导入依赖的package包/类
@VisibleForTesting
void makeCheck(ImmutableList<Collator> collators, ImmutableList<String> tokenizedInput,
ULocale locale, String message) {
int position = 0;
boolean failed = false;
if (tokenizedInput != null) {
main: for (int i = 1; i < tokenizedInput.size(); i++) {
position = i;
for (Collator testCollator : collators) {
if (testCollator.compare(tokenizedInput.get(i - 1), tokenizedInput.get(i)) <= 0) {
continue main;
}
}
failed = true;
break;
}
}
String errorMessage = message != null ? message
: String.format("List is not sorted for %s. Should have \"%s\" <= \"%s\" at position %s.",
locale, tokenizedInput.get(position), tokenizedInput.get(position - 1), position);
Assert.assertFalse(errorMessage, failed);
}