Package com.ibm.icu.text

Examples of com.ibm.icu.text.Collator$ServiceShim


  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();
View Full Code Here


 
  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(collator));
    }
  }
View Full Code Here

   * Sort the commands using the correct language.
   * @param commands the List of ParameterizedCommands
   * @return The sorted List
   */
  private List sortParameterizedCommands(List commands) {
    final Collator collator = Collator.getInstance();
   
    // this comparator is based on the ParameterizedCommands#compareTo(*)
    // method, but uses the collator.
    Comparator comparator = new Comparator() {
      public int compare(Object o1, Object o2) {
        String name1 = null;
        String name2 = null;
        try {
          name1 = ((ParameterizedCommand) o1).getName();
        } catch (NotDefinedException e) {
          return -1;
        }
        try {
          name2 = ((ParameterizedCommand) o2).getName();
        } catch (NotDefinedException e) {
          return 1;
        }
        int rc = collator.compare(name1, name2);
        if (rc != 0) {
          return rc;
        }

        String id1 = ((ParameterizedCommand) o1).getId();
        String id2 = ((ParameterizedCommand) o2).getId();
        return collator.compare(id1, id2);
      }
    };
    Collections.sort(commands, comparator);
    return commands;
  }
View Full Code Here

        if (isComplete(spec))
          fPreferences.add(spec);
      }
    }

    final Collator collator= Collator.getInstance();
    Collections.sort(fFragments, new Comparator() {
      /*
       * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
       */
      public int compare(Object o1, Object o2) {
        if (o1 == o2)
          return 0;

        AnnotationPreference ap1= (AnnotationPreference)o1;
        AnnotationPreference ap2= (AnnotationPreference)o2;

        String label1= ap1.getPreferenceLabel();
        String label2= ap2.getPreferenceLabel();

        if (label1 == null && label2 == null)
          return 0;

        if (label1 == null)
          return -1;

        if (label2 == null)
          return 1;

        return collator.compare(label1, label2);
      }
    });
  }
View Full Code Here

    private final Collator collator;

    @Inject public IcuCollationTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, Environment environment, @Assisted String name, @Assisted Settings settings) {
        super(index, indexSettings, name, settings);

        Collator collator;
        String rules = settings.get("rules");
        if (rules != null) {
            FailedToResolveConfigException failureToResolve = null;
            try {
                rules = environment.resolveConfigAndLoadToString(rules);
View Full Code Here

 
  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(collator));
    }
  }
View Full Code Here

         * Convenience override of getDisplayNames(ULocale, Comparator, String) that
         * uses the default collator for the locale as the comparator to
         * sort the display names, and null for the matchID.
         */
        public static SortedMap getDisplayNames(ICUService service, ULocale locale) {
            Collator col = Collator.getInstance(locale);
            return service.getDisplayNames(locale, col, null);
        }
View Full Code Here

    /*
     * (non-Javadoc) Method declared on IEditorRegistry.
     */
    public IFileEditorMapping[] getFileEditorMappings() {
        FileEditorMapping[] array = typeEditorMappings.allMappings();
        final Collator collator = Collator.getInstance();
        Arrays.sort(array, new Comparator() {
           
            /* (non-Javadoc)
             * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
             */
            public int compare(Object o1, Object o2) {
                String s1 = ((FileEditorMapping) o1).getLabel();
                String s2 = ((FileEditorMapping) o2).getLabel();
                return collator.compare(s1, s2);
            }
        });
        return array;
    }
View Full Code Here

    /*
     * Test method for 'com.ibm.icu.text.CollationKey.hashCode()'
     */
    public void testHashCode() {
        Collator c = Collator.getInstance();
        c.setStrength(Collator.PRIMARY);
        CollationKey k1 = c.getCollationKey("This");
        CollationKey k2 = c.getCollationKey("this");
        c.setStrength(Collator.TERTIARY);
        CollationKey kn = c.getCollationKey("this");
        testEHCS(k1, k2, kn);
    }
View Full Code Here

    /*
     * Test method for 'com.ibm.icu.text.CollationKey.compareTo(CollationKey)'
     */
    public void testCompareToCollationKey() {
        Collator c = Collator.getInstance();
        c.setStrength(Collator.PRIMARY);
        CollationKey k1 = c.getCollationKey("This");
        CollationKey k2 = c.getCollationKey("this");
        c.setStrength(Collator.TERTIARY);
        CollationKey k3 = c.getCollationKey("this");
        assertTrue(0 == k1.compareTo(k2));
        assertFalse(0 == k1.compareTo(k3));
    }
View Full Code Here

TOP

Related Classes of com.ibm.icu.text.Collator$ServiceShim

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.