本文整理汇总了Java中com.ibm.icu.text.Collator.setStrength方法的典型用法代码示例。如果您正苦于以下问题:Java Collator.setStrength方法的具体用法?Java Collator.setStrength怎么用?Java Collator.setStrength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.icu.text.Collator
的用法示例。
在下文中一共展示了Collator.setStrength方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: testThreadSafe
import com.ibm.icu.text.Collator; //导入方法依赖的package包/类
@Test
public void testThreadSafe() throws Exception {
int iters = 20;
for (int i = 0; i < iters; i++) {
Locale locale = Locale.GERMAN;
Collator collator = Collator.getInstance(locale);
collator.setStrength(Collator.IDENTICAL);
assertThreadSafe(new Random(), new ICUCollationKeyAnalyzer(collator));
}
}
示例3: testThreadSafe
import com.ibm.icu.text.Collator; //导入方法依赖的package包/类
public void testThreadSafe() throws Exception {
int iters = 20 * RANDOM_MULTIPLIER;
for (int i = 0; i < iters; i++) {
Locale locale = Locale.GERMAN;
Collator collator = Collator.getInstance(locale);
collator.setStrength(Collator.IDENTICAL);
assertThreadSafe(new ICUCollationKeyAnalyzer(TEST_VERSION_CURRENT, collator));
}
}
示例4: testRanges
import com.ibm.icu.text.Collator; //导入方法依赖的package包/类
public void testRanges() throws Exception {
Directory dir = newDirectory();
RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
Document doc = new Document();
Field field = newField("field", "", StringField.TYPE_STORED);
Collator collator = Collator.getInstance(); // uses -Dtests.locale
if (random().nextBoolean()) {
collator.setStrength(Collator.PRIMARY);
}
ICUCollationDocValuesField collationField = new ICUCollationDocValuesField("collated", collator);
doc.add(field);
doc.add(collationField);
int numDocs = atLeast(500);
for (int i = 0; i < numDocs; i++) {
String value = TestUtil.randomSimpleString(random());
field.setStringValue(value);
collationField.setStringValue(value);
iw.addDocument(doc);
}
IndexReader ir = iw.getReader();
iw.close();
IndexSearcher is = newSearcher(ir);
int numChecks = atLeast(100);
for (int i = 0; i < numChecks; i++) {
String start = TestUtil.randomSimpleString(random());
String end = TestUtil.randomSimpleString(random());
BytesRef lowerVal = new BytesRef(collator.getCollationKey(start).toByteArray());
BytesRef upperVal = new BytesRef(collator.getCollationKey(end).toByteArray());
Query query = new ConstantScoreQuery(FieldCacheRangeFilter.newBytesRefRange("collated", lowerVal, upperVal, true, true));
doTestRanges(is, start, end, query, collator);
}
ir.close();
dir.close();
}
示例5: testRanges
import com.ibm.icu.text.Collator; //导入方法依赖的package包/类
public void testRanges() throws Exception {
Directory dir = newDirectory();
RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
Document doc = new Document();
Field field = newField("field", "", StringField.TYPE_STORED);
Collator collator = Collator.getInstance(); // uses -Dtests.locale
if (random().nextBoolean()) {
collator.setStrength(Collator.PRIMARY);
}
ICUCollationDocValuesField collationField = new ICUCollationDocValuesField("collated", collator);
doc.add(field);
doc.add(collationField);
int numDocs = atLeast(500);
for (int i = 0; i < numDocs; i++) {
String value = _TestUtil.randomSimpleString(random());
field.setStringValue(value);
collationField.setStringValue(value);
iw.addDocument(doc);
}
IndexReader ir = iw.getReader();
iw.close();
IndexSearcher is = newSearcher(ir);
int numChecks = atLeast(100);
for (int i = 0; i < numChecks; i++) {
String start = _TestUtil.randomSimpleString(random());
String end = _TestUtil.randomSimpleString(random());
BytesRef lowerVal = new BytesRef(collator.getCollationKey(start).toByteArray());
BytesRef upperVal = new BytesRef(collator.getCollationKey(end).toByteArray());
Query query = new ConstantScoreQuery(FieldCacheRangeFilter.newBytesRefRange("collated", lowerVal, upperVal, true, true));
doTestRanges(is, start, end, query, collator);
}
ir.close();
dir.close();
}
示例6: testThreadSafe
import com.ibm.icu.text.Collator; //导入方法依赖的package包/类
@Test
public void testThreadSafe() throws Exception {
int iters = 20;
for (int i = 0; i < iters; i++) {
Locale locale = Locale.GERMAN;
Collator collator = Collator.getInstance(locale);
collator.setStrength(Collator.IDENTICAL);
assertThreadSafe(new Random(), new IcuCollationKeyAnalyzer(collator));
}
}
示例7: createCollator
import com.ibm.icu.text.Collator; //导入方法依赖的package包/类
private Collator createCollator( ISortDefinition sd )
{
if ( sd.getSortStrength( ) != -1 )
{
Collator c = Collator.getInstance( sd.getSortLocale( ) == null
? session.getEngineContext( ).getLocale( )
: sd.getSortLocale( ) );
c.setStrength( sd.getSortStrength( ) );
return c;
}
return null;
}
示例8: getInstanceStrengthIdentical
import com.ibm.icu.text.Collator; //导入方法依赖的package包/类
static public Collator getInstanceStrengthIdentical(Locale l) {
Collator c = Collator.getInstance(l);
c.setStrength(Collator.IDENTICAL);
return c;
}
示例9: makeCheck
import com.ibm.icu.text.Collator; //导入方法依赖的package包/类
@Override
protected void makeCheck(Placeholder target, ImmutableList<String> tokenizedInput, ULocale locale,
String message) {
if (tokenizedInput.size() < 2) {
// Test passed. Nothing to sort.
return;
}
int strength = Collator.SECONDARY;
if (!target.isLenient()) {
if (!target.isStrict()) {
strength = Collator.TERTIARY;
} else {
strength = Collator.IDENTICAL;
}
}
// Init collators.
Collator collator = Collator.getInstance(locale);
ImmutableList.Builder<Collator> collators = ImmutableList.builder();
collators.add(collator);
try {
Collator collator2 = (RuleBasedCollator) collator.clone();
collator2.setStrength(strength);
collators.add(collator2);
RuleBasedCollator collator3 = (RuleBasedCollator) collator.clone();
collator3.setStrength(strength);
collator3.setAlternateHandlingShifted(true);
collators.add(collator3);
RuleBasedCollator collator4 = (RuleBasedCollator) collator.clone();
collator4.setStrength(strength);
collator4.setNumericCollation(true);
collators.add(collator4);
RuleBasedCollator collator5 = (RuleBasedCollator) collator.clone();
collator5.setStrength(strength);
collator5.setAlternateHandlingShifted(true);
collator5.setNumericCollation(true);
collators.add(collator5);
} catch (CloneNotSupportedException e) {
// Do nothing.
}
makeCheck(collators.build(), tokenizedInput, locale, message);
}