当前位置: 首页>>代码示例>>Java>>正文


Java Collator.getInstance方法代码示例

本文整理汇总了Java中com.ibm.icu.text.Collator.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java Collator.getInstance方法的具体用法?Java Collator.getInstance怎么用?Java Collator.getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.ibm.icu.text.Collator的用法示例。


在下文中一共展示了Collator.getInstance方法的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");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:SimpleIcuCollationTokenFilterTests.java

示例2: 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

示例3: 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

示例4: 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

示例5: catch

import com.ibm.icu.text.Collator; //导入方法依赖的package包/类
public void	Init(String locale, boolean numeric_ordering) {
	try {
		this.collator = Collator.getInstance(Locale.forLanguageTag(locale));
		if (numeric_ordering) {
			RuleBasedCollator rbc = (RuleBasedCollator)collator;
			rbc.setNumericCollation(true);
		}
	} catch (Exception e) {throw Err_.new_wo_type("collator init failed", "err", Err_.Message_lang(e));}		
}
 
开发者ID:gnosygnu,项目名称:xowa_android,代码行数:10,代码来源:Uca_collator__icu__4_8.java

示例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));
    }
}
 
开发者ID:jprante,项目名称:elasticsearch-icu,代码行数:11,代码来源:IcuCollationKeyAnalyzerTests.java

示例7: 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();

    Index index = new Index("test");
    Settings settings = Settings.settingsBuilder()
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .put("path.home", System.getProperty("path.home"))
            .put("index.analysis.analyzer.myAnalyzer.type", "icu_collation")
            .put("index.analysis.analyzer.myAnalyzer.rules", tailoredRules)
            .put("index.analysis.analyzer.myAnalyzer.strength", "primary")
            .build();
    AnalysisService analysisService = createAnalysisService(index, settings);
    Analyzer analyzer = analysisService.analyzer("myAnalyzer").analyzer();

    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-icu,代码行数:31,代码来源:IcuCollationAnalyzerTests.java

示例8: 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));
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:10,代码来源:TestICUCollationKeyAnalyzer.java

示例9: 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();
  //
  // at this point, you would save these tailoredRules to a file, 
  // and use the custom parameter.
  //
  String germanUmlaut = "Töne";
  String germanOE = "Toene";
  Map<String,String> args = new HashMap<>();
  args.put("custom", "rules.txt");
  args.put("strength", "primary");
  ICUCollationKeyFilterFactory factory = new ICUCollationKeyFilterFactory(args);
  factory.inform(new StringMockResourceLoader(tailoredRules));
  TokenStream tsUmlaut = factory.create(
      new KeywordTokenizer(new StringReader(germanUmlaut)));
  TokenStream tsOE = factory.create(
      new KeywordTokenizer(new StringReader(germanOE)));

  assertCollatesToSame(tsUmlaut, tsOE);
}
 
开发者ID:europeana,项目名称:search,代码行数:29,代码来源:TestICUCollationKeyFilterFactory.java

示例10: testCollationKeySort

import com.ibm.icu.text.Collator; //导入方法依赖的package包/类
public void testCollationKeySort() throws Exception {
  Analyzer usAnalyzer = new TestAnalyzer(Collator.getInstance(Locale.US));
  Analyzer franceAnalyzer 
    = new TestAnalyzer(Collator.getInstance(Locale.FRANCE));
  Analyzer swedenAnalyzer 
    = new TestAnalyzer(Collator.getInstance(new Locale("sv", "se")));
  Analyzer denmarkAnalyzer 
    = new TestAnalyzer(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.US.
  testCollationKeySort
  (usAnalyzer, franceAnalyzer, swedenAnalyzer, denmarkAnalyzer, 
   "BFJHD", "ECAGI", "BJDFH", "BJDHF");
}
 
开发者ID:europeana,项目名称:search,代码行数:16,代码来源:TestICUCollationKeyFilter.java

示例11: testBasic

import com.ibm.icu.text.Collator; //导入方法依赖的package包/类
public void testBasic() throws Exception {
  Directory dir = newDirectory();
  RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
  Document doc = new Document();
  Field field = newField("field", "", StringField.TYPE_STORED);
  ICUCollationDocValuesField collationField = new ICUCollationDocValuesField("collated", Collator.getInstance(ULocale.ENGLISH));
  doc.add(field);
  doc.add(collationField);

  field.setStringValue("ABC");
  collationField.setStringValue("ABC");
  iw.addDocument(doc);
  
  field.setStringValue("abc");
  collationField.setStringValue("abc");
  iw.addDocument(doc);
  
  IndexReader ir = iw.getReader();
  iw.close();
  
  IndexSearcher is = newSearcher(ir);
  
  SortField sortField = new SortField("collated", SortField.Type.STRING);
  
  TopDocs td = is.search(new MatchAllDocsQuery(), 5, new Sort(sortField));
  assertEquals("abc", ir.document(td.scoreDocs[0].doc).get("field"));
  assertEquals("ABC", ir.document(td.scoreDocs[1].doc).get("field"));
  ir.close();
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:31,代码来源:TestICUCollationDocValuesField.java

示例12: 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();
}
 
开发者ID:europeana,项目名称:search,代码行数:39,代码来源:TestICUCollationDocValuesField.java

示例13: setupSolrHome

import com.ibm.icu.text.Collator; //导入方法依赖的package包/类
/**
 * Ugly: but what to do? We want to test custom sort, which reads rules in as a resource.
 * These are largish files, and jvm-specific (as our documentation says, you should always
 * look out for jvm differences with collation).
 * So its preferable to create this file on-the-fly.
 */
public static String setupSolrHome() throws Exception {
  String tmpFile = createTempDir().getAbsolutePath();
  // make data and conf dirs
  new File(tmpFile  + "/collection1", "data").mkdirs();
  File confDir = new File(tmpFile + "/collection1", "conf");
  confDir.mkdirs();
  
  // copy over configuration files
  FileUtils.copyFile(getFile("analysis-extras/solr/collection1/conf/solrconfig-icucollate.xml"), new File(confDir, "solrconfig.xml"));
  FileUtils.copyFile(getFile("analysis-extras/solr/collection1/conf/schema-icucollate.xml"), new File(confDir, "schema.xml"));
  
  // generate custom collation rules (DIN 5007-2), saving to customrules.dat
  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();
  FileOutputStream os = new FileOutputStream(new File(confDir, "customrules.dat"));
  IOUtils.write(tailoredRules, os, "UTF-8");
  os.close();

  return tmpFile;
}
 
开发者ID:europeana,项目名称:search,代码行数:34,代码来源:TestICUCollationField.java

示例14: setupSolrHome

import com.ibm.icu.text.Collator; //导入方法依赖的package包/类
/**
 * Ugly: but what to do? We want to test custom sort, which reads rules in as a resource.
 * These are largish files, and jvm-specific (as our documentation says, you should always
 * look out for jvm differences with collation).
 * So its preferable to create this file on-the-fly.
 */
public static String setupSolrHome() throws Exception {
  File tmpFile = createTempDir();
  
  // make data and conf dirs
  new File(tmpFile + "/collection1", "data").mkdirs();
  File confDir = new File(tmpFile + "/collection1", "conf");
  confDir.mkdirs();
  
  // copy over configuration files
  FileUtils.copyFile(getFile("analysis-extras/solr/collection1/conf/solrconfig-icucollate.xml"), new File(confDir, "solrconfig.xml"));
  FileUtils.copyFile(getFile("analysis-extras/solr/collection1/conf/schema-icucollate-dv.xml"), new File(confDir, "schema.xml"));
  
  // generate custom collation rules (DIN 5007-2), saving to customrules.dat
  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();
  FileOutputStream os = new FileOutputStream(new File(confDir, "customrules.dat"));
  IOUtils.write(tailoredRules, os, "UTF-8");
  os.close();

  return tmpFile.getAbsolutePath();
}
 
开发者ID:europeana,项目名称:search,代码行数:35,代码来源:TestICUCollationFieldDocValues.java

示例15: sort

import com.ibm.icu.text.Collator; //导入方法依赖的package包/类
public void sort() {
	Comparator<IBinding> comparator= new Comparator<IBinding>() {
		Collator collator= Collator.getInstance();
		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);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:13,代码来源:GenerateToStringDialog.java


注:本文中的com.ibm.icu.text.Collator.getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。