java.text.Collator#getInstance ( )源码实例Demo

下面列出了java.text.Collator#getInstance ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: Util.java
/**
 * Order projects by display name.
 */
public static Comparator<Project> projectDisplayNameComparator() {
    return new Comparator<Project>() {
        private final Collator LOC_COLLATOR = Collator.getInstance();
        public int compare(Project o1, Project o2) {
            ProjectInformation i1 = ProjectUtils.getInformation(o1);
            ProjectInformation i2 = ProjectUtils.getInformation(o2);
            int result = LOC_COLLATOR.compare(i1.getDisplayName(), i2.getDisplayName());
            if (result != 0) {
                return result;
            } else {
                result = i1.getName().compareTo(i2.getName());
                if (result != 0) {
                    return result;
                } else {
                    return System.identityHashCode(o1) - System.identityHashCode(o2);
                }
            }
        }
    };
}
 
源代码2 项目: netbeans   文件: AntScriptUtils.java
/**
 * Finds the names of callable targets in an Ant script.
 * @param script Ant script to inspect
 * @return list of target names, sorted (by locale)
 * @throws IOException if the script cannot be inspected
 */
public static List<String> getCallableTargetNames(FileObject script) throws IOException {
    AntProjectCookie apc = antProjectCookieFor(script);
    Set<TargetLister.Target> allTargets = TargetLister.getTargets(apc);
    SortedSet<String> targetNames = new TreeSet<String>(Collator.getInstance());
    for (TargetLister.Target target : allTargets) {
        if (target.isOverridden()) {
            // Cannot call it directly.
            continue;
        }
        if (target.isInternal()) {
            // Should not be called from outside.
            continue;
        }
        targetNames.add(target.getName());
    }
    return new ArrayList<String>(targetNames);
}
 
源代码3 项目: sakai   文件: AnonymousSubmissionComparator.java
public AnonymousSubmissionComparator() {
    try {
        collator = new RuleBasedCollator(((RuleBasedCollator) Collator.getInstance()).getRules().replaceAll("<'\u005f'", "<' '<'\u005f'"));
    } catch (ParseException e) {
        // error with init RuleBasedCollator with rules
        // use the default Collator
        collator = Collator.getInstance();
        log.warn("{} AssignmentComparator cannot init RuleBasedCollator. Will use the default Collator instead. {}", this, e);
    }
}
 
源代码4 项目: openjdk-8   文件: NativeString.java
/**
 * ECMA 15.5.4.9 String.prototype.localeCompare (that)
 * @param self self reference
 * @param that comparison object
 * @return result of locale sensitive comparison operation between {@code self} and {@code that}
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object localeCompare(final Object self, final Object that) {

    final String   str      = checkObjectToString(self);
    final Collator collator = Collator.getInstance(Global.getEnv()._locale);

    collator.setStrength(Collator.IDENTICAL);
    collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);

    return (double)collator.compare(str, JSType.toString(that));
}
 
源代码5 项目: openjdk-jdk9   文件: Utils.java
private DocCollator(Locale locale, int strength) {
    instance = Collator.getInstance(locale);
    instance.setStrength(strength);

    keys = new LinkedHashMap<String, CollationKey>(MAX_SIZE + 1, 0.75f, true) {
        private static final long serialVersionUID = 1L;
        @Override
        protected boolean removeEldestEntry(Entry<String, CollationKey> eldest) {
            return size() > MAX_SIZE;
        }
    };
}
 
源代码6 项目: olat   文件: AbstractPortletRunController.java
public AbstractPortletRunController(WindowControl wControl, UserRequest ureq, Translator trans, String portletName) {
    super(ureq, wControl, trans);
    collator = Collator.getInstance();
    this.portletName = portletName;
    this.guiPreferences = ureq.getUserSession().getGuiPreferences();
    this.identity = ureq.getIdentity();
    this.locale = ureq.getLocale();
}
 
源代码7 项目: netbeans   文件: DocumentGroupImpl.java
@Override
public int compareTo( DocumentGroupImpl o ) {
    Collator collator = Collator.getInstance();
    int res = collator.compare( displayName, o.displayName );
    if( 0 == res )
        res = collator.compare( name, o.name );
    return res;
}
 
源代码8 项目: Pydev   文件: GlobalsTwoPanelElementSelector2.java
@Override
protected Comparator<AdditionalInfoAndIInfo> getItemsComparator() {
    return new Comparator<AdditionalInfoAndIInfo>() {

        /*
         * (non-Javadoc)
         *
         * @see java.util.Comparator#compare(java.lang.Object,
         *      java.lang.Object)
         */
        @Override
        public int compare(AdditionalInfoAndIInfo resource1, AdditionalInfoAndIInfo resource2) {
            Collator collator = Collator.getInstance();
            String s1 = resource1.info.getName();
            String s2 = resource2.info.getName();
            int comparability = collator.compare(s1, s2);
            //same name
            if (comparability == 0) {
                String p1 = resource1.info.getDeclaringModuleName();
                String p2 = resource2.info.getDeclaringModuleName();
                if (p1 == null && p2 == null) {
                    return 0;
                }
                if (p1 != null && p2 == null) {
                    return -1;
                }
                if (p1 == null && p2 != null) {
                    return 1;
                }
                return p1.compareTo(p2);
            }

            return comparability;
        }
    };
}
 
源代码9 项目: openjdk-8-source   文件: DefaultRowSorter.java
private Comparator getComparator0(int column) {
    Comparator comparator = getComparator(column);
    if (comparator != null) {
        return comparator;
    }
    // This should be ok as useToString(column) should have returned
    // true in this case.
    return Collator.getInstance();
}
 
源代码10 项目: mollyim-android   文件: CountryListLoader.java
RegionComparator() {
  collator = Collator.getInstance();
  collator.setStrength(Collator.PRIMARY);
}
 
源代码11 项目: sakai   文件: ContentHostingComparator.java
public int comparerLocalSensitive(String s1, String s2) {
	Collator c = Collator.getInstance();
	c.setStrength(Collator.PRIMARY);
	return c.compare(s1, s2);
}
 
源代码12 项目: jdk8u_jdk   文件: CollationKeyTestImpl.java
public void run() {
    /** debug: printout the test data
    for (int i=0; i<sourceData_ja.length; i++){
            System.out.println(i+": "+sourceData_ja[i]);
    }
    **/
   /*
    * 1. Test the backward compatibility
    *    note: targetData_ja.length is equal to sourceData_ja.length
    */
    Collator myCollator = Collator.getInstance(Locale.JAPAN);
    CollationKey[] keys = new CollationKey[sourceData_ja.length];
    CollationKey[] target_keys = new CollationKey[targetData_ja.length];
    for (int i=0; i<sourceData_ja.length; i++){
            keys[i] = myCollator.getCollationKey(sourceData_ja[i]);
            target_keys[i] = myCollator.getCollationKey(targetData_ja[i]); //used later
    }
    /* Sort the string using CollationKey */
    InsertionSort(keys);
    /** debug: printout the result after sort
    System.out.println("--- After Sorting ---");
    for (int i=0; i<sourceData_ja.length; i++){
            System.out.println(i+" :"+keys[i].getSourceString());
    }
    **/
   /*
    * Compare the result using equals method and getSourceString method.
    */
    boolean pass = true;
    for (int i=0; i<sourceData_ja.length; i++){
            /* Comparing using String.equals: in order to use getStringSource() */
            if (! targetData_ja[i].equals(keys[i].getSourceString())){
                    throw new RuntimeException("FAILED: CollationKeyTest backward compatibility "
                              +"while comparing" +targetData_ja[i]+" vs "
                              +keys[i].getSourceString());
            }
            /* Comparing using CollaionKey.equals: in order to use equals() */
            if (! target_keys[i].equals(keys[i])){
                    throw new RuntimeException("FAILED: CollationKeyTest backward compatibility."
                              +" Using CollationKey.equals " +targetData_ja[i]
                              +" vs " +keys[i].getSourceString());
            }
            /* Comparing using CollaionKey.hashCode(): in order to use hashCode() */
            if (target_keys[i].hashCode() != keys[i].hashCode()){
                    throw new RuntimeException("FAILED: CollationKeyTest backward compatibility."
                              +" Using CollationKey.hashCode " +targetData_ja[i]
                              +" vs " +keys[i].getSourceString());
            }
            /* Comparing using CollaionKey.toByteArray(): in order to use toByteArray() */
            byte[] target_bytes = target_keys[i].toByteArray();
            byte[] source_bytes = keys[i].toByteArray();
            for (int j=0; j<target_bytes.length; j++){
                    Byte targetByte = new Byte(target_bytes[j]);
                    Byte sourceByte = new Byte(source_bytes[j]);
                    if (targetByte.compareTo(sourceByte)!=0){
                        throw new RuntimeException("FAILED: CollationKeyTest backward "
                              +"compatibility. Using Byte.compareTo from CollationKey.toByteArray "
                              +targetData_ja[i]
                              +" vs " +keys[i].getSourceString());
                    }
            }
    }
    testSubclassMethods();
    testConstructor();
}
 
源代码13 项目: openjdk-jdk9   文件: Bug6755060.java
/********************************************************
*********************************************************/
public static void main (String[] args) {

  Locale reservedLocale = Locale.getDefault();

  try{

      int errors=0;

      Locale loc = new Locale ("th", "TH");   // Thai

      Locale.setDefault (loc);
      Collator col = Collator.getInstance ();

      /*
      * The original data "data" are the data to be sorted provided by the submitter of the CR.
      * It's in correct order in accord with thai collation in CLDR 1.9. If we use old Java without this fix,
      * the output order will be incorrect. Correct order will be turned into incorrect order.

      * If fix is there, "data" after sorting will be unchanged, same as "sortedData". If fix is lost (regression),
      * "data" after sorting will be changed, not as "sortedData".(not correct anymore)

      * The submitter of the CR also gives a expected "sortedData" in the CR, but it's in accord with collation in CLDR 1.4.
      * His data to be sorted are actually well sorted in accord with CLDR 1.9.
      */

      String[] data = {"\u0e01", "\u0e01\u0e2f", "\u0e01\u0e46", "\u0e01\u0e4f", "\u0e01\u0e5a", "\u0e01\u0e5b", "\u0e01\u0e4e", "\u0e01\u0e4c", "\u0e01\u0e48", "\u0e01\u0e01", "\u0e01\u0e4b\u0e01", "\u0e01\u0e4d", "\u0e01\u0e30", "\u0e01\u0e31\u0e01", "\u0e01\u0e32", "\u0e01\u0e33", "\u0e01\u0e34", "\u0e01\u0e35", "\u0e01\u0e36", "\u0e01\u0e37", "\u0e01\u0e38", "\u0e01\u0e39", "\u0e40\u0e01", "\u0e40\u0e01\u0e48", "\u0e40\u0e01\u0e49", "\u0e40\u0e01\u0e4b", "\u0e41\u0e01", "\u0e42\u0e01", "\u0e43\u0e01", "\u0e44\u0e01", "\u0e01\u0e3a", "\u0e24\u0e32", "\u0e24\u0e45", "\u0e40\u0e25", "\u0e44\u0e26"};

      String[] sortedData = {"\u0e01", "\u0e01\u0e2f", "\u0e01\u0e46", "\u0e01\u0e4f", "\u0e01\u0e5a", "\u0e01\u0e5b", "\u0e01\u0e4e", "\u0e01\u0e4c", "\u0e01\u0e48", "\u0e01\u0e01", "\u0e01\u0e4b\u0e01", "\u0e01\u0e4d", "\u0e01\u0e30", "\u0e01\u0e31\u0e01", "\u0e01\u0e32", "\u0e01\u0e33", "\u0e01\u0e34", "\u0e01\u0e35", "\u0e01\u0e36", "\u0e01\u0e37", "\u0e01\u0e38", "\u0e01\u0e39", "\u0e40\u0e01", "\u0e40\u0e01\u0e48", "\u0e40\u0e01\u0e49", "\u0e40\u0e01\u0e4b", "\u0e41\u0e01", "\u0e42\u0e01", "\u0e43\u0e01", "\u0e44\u0e01", "\u0e01\u0e3a", "\u0e24\u0e32", "\u0e24\u0e45", "\u0e40\u0e25", "\u0e44\u0e26"};

      Arrays.sort (data, col);

      System.out.println ("Using " + loc.getDisplayName());
      for (int i = 0;  i < data.length;  i++) {
          System.out.println(data[i] + "  :  " + sortedData[i]);
          if (sortedData[i].compareTo(data[i]) != 0) {
              errors++;
          }
      }//end for

      if (errors > 0){
          StringBuffer expected = new StringBuffer(), actual = new StringBuffer();
          expected.append(sortedData[0]);
          actual.append(data[0]);

              for (int i=1; i<data.length; i++) {
                  expected.append(",");
                  expected.append(sortedData[i]);

                  actual.append(",");
                  actual.append(data[i]);
              }

          String errmsg = "Error is found in collation testing in Thai\n" + "exepected order is: " + expected.toString() + "\n" + "actual order is: " + actual.toString() + "\n";

          throw new RuntimeException(errmsg);
      }
  }finally{
      // restore the reserved locale
      Locale.setDefault(reservedLocale);
  }

}
 
源代码14 项目: MesquiteCore   文件: MesquiteCollator.java
public MesquiteCollator (){
	collator = Collator.getInstance();
	pA = new Parser();
	pB = new Parser();
}
 
源代码15 项目: j2objc   文件: CollatorTest.java
/**
 * @tests java.text.Collator#getInstance()
 */
public void test_getInstance() {
	Collator c1 = Collator.getInstance();
	Collator c2 = Collator.getInstance(Locale.getDefault());
	assertTrue("Wrong locale", c1.equals(c2));
}
 
源代码16 项目: andOTP   文件: EntriesCardAdapter.java
IssuerComparator(){
    collator = Collator.getInstance();
    collator.setStrength(Collator.PRIMARY);
}
 
源代码17 项目: satstat   文件: RemoteFileComparator.java
@Override
public int compare(RemoteFile lhs, RemoteFile rhs) {
	Collator collator = Collator.getInstance();
	return collator.compare(lhs.name, rhs.name);
}
 
源代码18 项目: proarc   文件: BundleValueMap.java
public BundleValueComparator(Locale locale) {
    collator = Collator.getInstance(locale);
}
 
源代码19 项目: hottub   文件: TableRowSorter.java
/**
 * Returns the <code>Comparator</code> for the specified
 * column.  If a <code>Comparator</code> has not been specified using
 * the <code>setComparator</code> method a <code>Comparator</code>
 * will be returned based on the column class
 * (<code>TableModel.getColumnClass</code>) of the specified column.
 * If the column class is <code>String</code>,
 * <code>Collator.getInstance</code> is returned.  If the
 * column class implements <code>Comparable</code> a private
 * <code>Comparator</code> is returned that invokes the
 * <code>compareTo</code> method.  Otherwise
 * <code>Collator.getInstance</code> is returned.
 *
 * @throws IndexOutOfBoundsException {@inheritDoc}
 */
public Comparator<?> getComparator(int column) {
    Comparator comparator = super.getComparator(column);
    if (comparator != null) {
        return comparator;
    }
    Class columnClass = getModel().getColumnClass(column);
    if (columnClass == String.class) {
        return Collator.getInstance();
    }
    if (Comparable.class.isAssignableFrom(columnClass)) {
        return COMPARABLE_COMPARATOR;
    }
    return Collator.getInstance();
}
 
源代码20 项目: j2objc   文件: ICUServiceTest.java
/**
 * Convenience override of getDisplayNames(ULocale, Comparator, String) that
 * uses the default collator for the locale as the comparator to
 * sort the display names.
 */
public SortedMap getDisplayNames(ICUService service, ULocale locale, String matchID) {
    Collator col = Collator.getInstance(locale.toLocale());
    return service.getDisplayNames(locale, col, matchID);
}