本文整理汇总了Java中com.ibm.icu.text.Collator类的典型用法代码示例。如果您正苦于以下问题:Java Collator类的具体用法?Java Collator怎么用?Java Collator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Collator类属于com.ibm.icu.text包,在下文中一共展示了Collator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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");
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:SimpleIcuCollationTokenFilterTests.java
示例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;
}
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:24,代码来源:CollationData.java
示例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;
}
}
}
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:17,代码来源:CollationData.java
示例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;
}
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:25,代码来源:CollationRuleParser.java
示例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;
}
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:19,代码来源:CollationBuilder.java
示例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);
}
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:28,代码来源:CollationBuilder.java
示例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;
}
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:33,代码来源:CollationBuilder.java
示例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;
}
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:25,代码来源:CollationFastLatinBuilder.java
示例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);
}
}
开发者ID:jaytaylor,项目名称:sql-layer,代码行数:19,代码来源:CollationSpecifier.java
示例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");
}
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:TestICUCollationKeyAnalyzer.java
示例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();
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:25,代码来源:AccessorClassCreator.java
示例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);
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:25,代码来源:PropertyFileDocumentModel.java
示例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$
}
});
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:CleanUpRegistry.java
示例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;
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:OrganizeImportsAction.java
示例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);
}
开发者ID:googlei18n,项目名称:i18n_sanitycheck,代码行数:23,代码来源:OrderingChecker.java
示例16: testCustomRules
import com.ibm.icu.text.Collator; //导入依赖的package包/类
@Test
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.analyzer.myAnalyzer.type", "icu_collation")
.put("index.analysis.analyzer.myAnalyzer.rules", tailoredRules)
.put("index.analysis.analyzer.myAnalyzer.strength", "primary")
.build();
Analyzer analyzer = analyzer(settings, "myAnalyzer");
String germanUmlaut = "Töne";
TokenStream tsUmlaut = analyzer.tokenStream(null, germanUmlaut);
BytesRef b1 = bytesFromTokenStream(tsUmlaut);
String germanExpandedUmlaut = "Toene";
TokenStream tsExpanded = analyzer.tokenStream(null, germanExpandedUmlaut);
BytesRef b2 = bytesFromTokenStream(tsExpanded);
assertTrue(compare(b1.bytes, b2.bytes) == 0);
}
开发者ID:jprante,项目名称:elasticsearch-plugin-bundle,代码行数:27,代码来源:IcuCollationAnalyzerTests.java
示例17: getAllStyleHandles
import com.ibm.icu.text.Collator; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private StyleHandle[] getAllStyleHandles( )
{
List<StyleHandle> sLst = getReportDesignHandle( ).getAllStyles( );
StyleHandle[] list = sLst.toArray( new StyleHandle[sLst.size( )] );
Arrays.sort( list, new Comparator<StyleHandle>( ) {
Collator collator = Collator.getInstance( ULocale.getDefault( ) );
public int compare( StyleHandle s1, StyleHandle s2 )
{
return collator.compare( s1.getDisplayLabel( ),
s2.getDisplayLabel( ) );
}
} );
return list;
}
开发者ID:eclipse,项目名称:birt,代码行数:19,代码来源:ReportDataServiceProvider.java
示例18: createCollator
import com.ibm.icu.text.Collator; //导入依赖的package包/类
private Collator createCollator(SeriesDefinition sd )
{
// If sort strength is ASCII(-1), then just use default compare of
// String class to do collator, so here just return null;
if ( sd.isSetSortStrength( ) && sd.getSortStrength( ) < 0 )
{
return null;
}
Collator c = null;
if ( sd.getSortLocale( ) != null )
{
c = Collator.getInstance( new ULocale( sd.getSortLocale( ) ) );
}
else {
c = Collator.getInstance( );
}
if ( sd.isSetSortStrength( ) )
{
c.setStrength( sd.getSortStrength( ) );
}
return c;
}
开发者ID:eclipse,项目名称:birt,代码行数:25,代码来源:ResultSetWrapper.java
示例19: execute
import com.ibm.icu.text.Collator; //导入依赖的package包/类
public Object execute( Object[] args, IScriptFunctionContext context ) throws BirtException
{
Collator collator = (Collator) context.findProperty( "compare_locale" );
if ( args == null || args.length != 3 )
throw new IllegalArgumentException( MessageFormat.format( WRONG_ARGUMENT,
new Object[]{
BETWEEN
} ) );
try
{
return this.mode
? Boolean.valueOf( compare( args[0], args[1],collator ) >= 0
&& compare( args[0], args[2],collator ) <= 0 )
: Boolean.valueOf( !( compare( args[0], args[1],collator ) >= 0 && compare( args[0],
args[2],collator ) <= 0 ) );
}
catch ( BirtException e )
{
throw new IllegalArgumentException( e.getLocalizedMessage( ) );
}
}
开发者ID:eclipse,项目名称:birt,代码行数:23,代码来源:BirtComp.java
示例20: initializeCollator
import com.ibm.icu.text.Collator; //导入依赖的package包/类
private void initializeCollator( ) throws DataException
{
if ( session != null )
{
IBaseDataSetDesign design = ( (DataEngineImpl) this.session.getEngine( ) ).getDataSetDesign( getDataSetName( ) );
if ( design != null )
{
String nullOrdering = design.getNullsOrdering( );
Collator collator = design.getCompareLocale( ) == null ? null
: Collator.getInstance( design.getCompareLocale( ) );
dataSet.setCompareLocale( collator );
dataSet.setNullest( nullOrdering );
dataSet.getScriptScope( ).put( "compare_locale",
dataSet.getScriptScope( ),
collator );
}
}
}
开发者ID:eclipse,项目名称:birt,代码行数:21,代码来源:QueryExecutor.java
注:本文中的com.ibm.icu.text.Collator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论