Java Code Examples for java.text.Collator#getCollationKey()

The following examples show how to use java.text.Collator#getCollationKey() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: APITest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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...");
}
 
Example 2
Source File: APITest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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...");
}
 
Example 3
Source File: APITest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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...");
}
 
Example 4
Source File: APITest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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...");
}
 
Example 5
Source File: APITest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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...");
}
 
Example 6
Source File: KeyConfigure.java    From tn5250j with GNU General Public License v2.0 5 votes vote down vote up
private void supportAplColorCodesInSEU(Collator collator, StringBuffer sb, Set<CollationKey> set) {
	for (Entry<Integer, String> color : colorMap.entrySet()) {
		int keyVal = color.getKey().intValue();
		char c = (char)('\uff00' + keyVal);

	    sb.setLength(0);
	    sb.append("0FF" + Integer.toHexString(keyVal).toUpperCase());
	    sb.append(" - " + c + " - " + color.getValue());
	    CollationKey key = collator.getCollationKey(sb.toString());

	    set.add(key);
	}
}
 
Example 7
Source File: MusicIndex.java    From airsonic-advanced with GNU General Public License v3.0 4 votes vote down vote up
public SortableArtist(String name, String sortableName, Collator collator) {
    this.name = name;
    this.sortableName = sortableName;
    collationKey = collator.getCollationKey(sortableName);
}
 
Example 8
Source File: CollationKeyTestImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
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();
}
 
Example 9
Source File: CollationKeyTestImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
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();
}
 
Example 10
Source File: CollationKeyTestImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
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();
}
 
Example 11
Source File: MusicIndex.java    From airsonic with GNU General Public License v3.0 4 votes vote down vote up
public SortableArtist(String name, String sortableName, Collator collator) {
    this.name = name;
    this.sortableName = sortableName;
    collationKey = collator.getCollationKey(sortableName);
}
 
Example 12
Source File: CollationKeyTestImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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();
}
 
Example 13
Source File: CollationKeyTestImpl.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
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();
}
 
Example 14
Source File: MusicIndex.java    From subsonic with GNU General Public License v3.0 4 votes vote down vote up
public SortableArtist(String name, String sortableName, Collator collator) {
    this.name = name;
    this.sortableName = sortableName;
    collationKey = collator.getCollationKey(sortableName);
}
 
Example 15
Source File: KeyConfigure.java    From tn5250j with GNU General Public License v2.0 4 votes vote down vote up
private void loadList(String which) {

      lm.clear();
      lm.removeAllElements();


      if (which.equals(LangTool.getString("key.labelKeys"))) {
        Vector<KeyDescription> lk = new Vector<KeyDescription>(keyMnemonicResolver.getMnemonics().length);
        for (int x = 0; x < keyMnemonicResolver.getMnemonics().length; x++) {
          lk.addElement(new KeyDescription(LangTool.getString("key."+ keyMnemonicResolver.getMnemonics()[x]),x));
         }

         Collections.sort(lk, new KeyDescriptionCompare());

        for (int x = 0; x < keyMnemonicResolver.getMnemonics().length; x++) {
            lm.addElement(lk.get(x));
         }
         macros = false;
         special = false;
      }
      else {
         if (which.equals(LangTool.getString("key.labelMacros"))) {
            Vector<String> macrosVector = new Vector<String>();
            if (macrosList != null)
               for (int x = 0; x < macrosList.length; x++) {
                  macrosVector.add(macrosList[x]);
               }
            scriptDir("scripts",macrosVector);
            loadListModel(lm,macrosVector,null,0);
            macros = true;
            special = false;
         }
         else {

            // we will use a collator here so that we can take advantage of the locales
            Collator collator = Collator.getInstance();
            CollationKey key = null;
            StringBuffer sb = new StringBuffer();

            Set<CollationKey> set = new TreeSet<CollationKey>();

            supportAplColorCodesInSEU(collator, sb, set);

            for (int x =0;x < 256; x++) {
               char c = codePage.ebcdic2uni(x);
               char ac = codePage.ebcdic2uni(x);
               if (!Character.isISOControl(c)) {
                  sb.setLength(0);
                  if (Integer.toHexString(ac).length() == 1){
                     sb.append("0x0" + Integer.toHexString(ac).toUpperCase());
                  }
                  else {
                     sb.append("0x" + Integer.toHexString(ac).toUpperCase());
                  }

                  sb.append(" - " + c + " - " + getUnicodeString(c));
                  key = collator.getCollationKey(sb.toString());

                  set.add(key);
               }
            }

            Iterator<CollationKey> iterator = set.iterator();
            while (iterator.hasNext()) {
               CollationKey keyc = iterator.next();
               lm.addElement(keyc.getSourceString());
            }

            macros = false;
            special = true;

         }
      }
      if (!lm.isEmpty())
         functions.setSelectedIndex(0);
   }
 
Example 16
Source File: CollatorTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
public void test_stackCorruption() throws Exception {
    // This used to crash Android.
    Collator mColl = Collator.getInstance();
    mColl.setStrength(Collator.PRIMARY);
    mColl.getCollationKey("2d294f2d3739433565147655394f3762f3147312d3731641452f310");
}