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


Java Collator.getCollationKey方法代码示例

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


在下文中一共展示了Collator.getCollationKey方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: TestCollationKey

import java.text.Collator; //导入方法依赖的package包/类
public final void TestCollationKey( )
{
    logln("testing CollationKey begins...");
    Collator col = null;
    try {
        col = Collator.getInstance(Locale.ROOT);
    } catch (Exception foo) {
        errln("Error : " + foo.getMessage());
        errln("Default collation creation failed.");
    }
    if (col == null) {
        return;
    }

    String test1 = "Abcda", test2 = "abcda";
    logln("Use tertiary comparison level testing ....");
    CollationKey sortk1 = col.getCollationKey(test1);
    CollationKey sortk2 = col.getCollationKey(test2);
    doAssert(sortk1.compareTo(sortk2) > 0,
                "Result should be \"Abcda\" >>> \"abcda\"");
    CollationKey sortk3 = sortk2;
    CollationKey sortkNew = sortk1;
    doAssert(sortk1 != sortk2, "The sort keys should be different");
    doAssert(sortk1.hashCode() != sortk2.hashCode(), "sort key hashCode() failed");
    doAssert(sortk2.compareTo(sortk3) == 0, "The sort keys should be the same");
    doAssert(sortk1 == sortkNew, "The sort keys assignment failed");
    doAssert(sortk1.hashCode() == sortkNew.hashCode(), "sort key hashCode() failed");
    doAssert(sortkNew != sortk3, "The sort keys should be different");
    doAssert(sortk1.compareTo(sortk3) > 0, "Result should be \"Abcda\" >>> \"abcda\"");
    doAssert(sortk2.compareTo(sortk3) == 0, "Result should be \"abcda\" == \"abcda\"");
    long    cnt1, cnt2;
    byte byteArray1[] = sortk1.toByteArray();
    byte byteArray2[] = sortk2.toByteArray();
    doAssert(byteArray1 != null && byteArray2 != null, "CollationKey.toByteArray failed.");
    logln("testing sortkey ends...");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:APITest.java

示例2: SortableArtist

import java.text.Collator; //导入方法依赖的package包/类
public SortableArtist(String name, String sortableName, Collator collator) {
    this.name = name;
    this.sortableName = sortableName;
    collationKey = collator.getCollationKey(sortableName);
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:6,代码来源:MusicIndex.java

示例3: run

import java.text.Collator; //导入方法依赖的package包/类
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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:66,代码来源:CollationKeyTestImpl.java


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