java.text.CollationKey Java Examples

The following examples show how to use java.text.CollationKey. 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 Project: dragonwell8_jdk   Author: alibaba   File: CollationKeyTestImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
private  void  InsertionSort(CollationKey[] keys){
    int f, i;
    CollationKey tmp;

    for (f=1; f < keys.length; f++){
        if(keys[f].compareTo( keys[f-1]) > 0){
            continue;
        }
        tmp = keys[f];
        i = f-1;
        while ( (i>=0) && (keys[i].compareTo(tmp) > 0) ) {
            keys[i+1] = keys[i];
            i--;
        }
        keys[i+1]=tmp;
    }
}
 
Example #2
Source Project: TencentKona-8   Author: Tencent   File: CollationKeyTestImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
private  void  InsertionSort(CollationKey[] keys){
    int f, i;
    CollationKey tmp;

    for (f=1; f < keys.length; f++){
        if(keys[f].compareTo( keys[f-1]) > 0){
            continue;
        }
        tmp = keys[f];
        i = f-1;
        while ( (i>=0) && (keys[i].compareTo(tmp) > 0) ) {
            keys[i+1] = keys[i];
            i--;
        }
        keys[i+1]=tmp;
    }
}
 
Example #3
Source Project: spliceengine   Author: splicemachine   File: WorkHorseForCollatorDatatypes.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
/** @see SQLChar#stringCompare(SQLChar, SQLChar) */
int stringCompare(SQLChar str1, SQLChar str2)
throws StandardException
{
	CollationKey ckey1 = str1.getCollationKey();
	CollationKey ckey2 = str2.getCollationKey();
	
	/*
	** By convention, nulls sort High, and null == null
	*/
	if (ckey1 == null || ckey2 == null)
	{
		if (ckey1 != null)	// str2 == null
			return -1;
		if (ckey2 != null)	// this == null
			return 1;
		return 0;			// both == null
	}

	return ckey1.compareTo(ckey2);
}
 
Example #4
Source Project: spliceengine   Author: splicemachine   File: SQLChar.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "DB-9406")
public void    copyState
    (
     String otherValue,
     char[] otherRawData,
     int otherRawLength,
     CollationKey otherCKey,
     InputStream    otherStream,
     Clob otherClobValue,
     LocaleFinder otherLocaleFinder
     )
{
    value = otherValue;
    rawData = otherRawData;
    rawLength = otherRawLength;
    cKey = otherCKey;
    stream = otherStream;
    _clobValue = otherClobValue;
    localeFinder = otherLocaleFinder;
    isNull = evaluateNull();
}
 
Example #5
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: CollationKeyTestImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
private  void  InsertionSort(CollationKey[] keys){
    int f, i;
    CollationKey tmp;

    for (f=1; f < keys.length; f++){
        if(keys[f].compareTo( keys[f-1]) > 0){
            continue;
        }
        tmp = keys[f];
        i = f-1;
        while ( (i>=0) && (keys[i].compareTo(tmp) > 0) ) {
            keys[i+1] = keys[i];
            i--;
        }
        keys[i+1]=tmp;
    }
}
 
Example #6
Source Project: Android   Author: connectim   File: FriendCompara.java    License: MIT License 6 votes vote down vote up
@Override
public int compare(ContactEntity lhs, ContactEntity rhs) {
    String string1 = TextUtils.isEmpty(lhs.getRemark()) ? lhs.getUsername() : lhs.getRemark();
    String string2 = TextUtils.isEmpty(rhs.getRemark()) ? rhs.getUsername() : rhs.getRemark();

    char char1 = TextUtils.isEmpty(string1) ? '#' : string1.charAt(0);
    char char2 = TextUtils.isEmpty(string2) ? '#' : string2.charAt(0);

    CollationKey key1 = collator.getCollationKey(PinyinUtil.chatToPinyin(char1));
    CollationKey key2 = collator.getCollationKey(PinyinUtil.chatToPinyin(char2));

    // Comparison method violates its general contract
    if (key1.getSourceString().equals(key2.getSourceString())) {
        return 0;
    }
    if ("#".equals(key1.getSourceString())
            || "#".equals(key2.getSourceString())) {
        if ("#".equals(key1.getSourceString())) {
            return 1;
        } else if ("#".equals(key2.getSourceString())) {
            return -1;
        }
    }
    return key1.compareTo(key2);
}
 
Example #7
Source Project: Android   Author: connectim   File: GroupComPara.java    License: MIT License 6 votes vote down vote up
@Override
public int compare(GroupMemberEntity lhs, GroupMemberEntity rhs) {
    String string1 = TextUtils.isEmpty(lhs.getNick()) ? lhs.getUsername() : lhs.getNick();
    String string2 = TextUtils.isEmpty(rhs.getNick()) ? rhs.getUsername() : rhs.getNick();

    char char1 = TextUtils.isEmpty(string1) ? '#' : string1.charAt(0);
    char char2 = TextUtils.isEmpty(string2) ? '#' : string2.charAt(0);

    CollationKey key1 = collator.getCollationKey(PinyinUtil.chatToPinyin(char1));
    CollationKey key2 = collator.getCollationKey(PinyinUtil.chatToPinyin(char2));

    // Comparison method violates its general contract
    if (key1.getSourceString().equals(key2.getSourceString())) {
        return 0;
    }
    if ("#".equals(key1.getSourceString())
            || "#".equals(key2.getSourceString())) {
        if ("#".equals(key1.getSourceString())) {
            return 1;
        } else if ("#".equals(key2.getSourceString())) {
            return -1;
        }
    }
    return key1.compareTo(key2);
}
 
Example #8
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: CollationKeyTestImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
private  void  InsertionSort(CollationKey[] keys){
    int f, i;
    CollationKey tmp;

    for (f=1; f < keys.length; f++){
        if(keys[f].compareTo( keys[f-1]) > 0){
            continue;
        }
        tmp = keys[f];
        i = f-1;
        while ( (i>=0) && (keys[i].compareTo(tmp) > 0) ) {
            keys[i+1] = keys[i];
            i--;
        }
        keys[i+1]=tmp;
    }
}
 
Example #9
Source Project: gemfirexd-oss   Author: gemxd   File: WorkHorseForCollatorDatatypes.java    License: Apache License 2.0 6 votes vote down vote up
/** @see SQLChar#stringCompare(SQLChar, SQLChar) */
int stringCompare(SQLChar str1, SQLChar str2)
throws StandardException
{
	CollationKey ckey1 = str1.getCollationKey();
	CollationKey ckey2 = str2.getCollationKey();
	
	/*
	** By convention, nulls sort High, and null == null
	*/
	if (ckey1 == null || ckey2 == null)
	{
		if (ckey1 != null)	// str2 == null
			return -1;
		if (ckey2 != null)	// this == null
			return 1;
		return 0;			// both == null
	}

	return ckey1.compareTo(ckey2);
}
 
Example #10
Source Project: jdk8u_jdk   Author: JetBrains   File: CollationKeyTestImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
private  void  InsertionSort(CollationKey[] keys){
    int f, i;
    CollationKey tmp;

    for (f=1; f < keys.length; f++){
        if(keys[f].compareTo( keys[f-1]) > 0){
            continue;
        }
        tmp = keys[f];
        i = f-1;
        while ( (i>=0) && (keys[i].compareTo(tmp) > 0) ) {
            keys[i+1] = keys[i];
            i--;
        }
        keys[i+1]=tmp;
    }
}
 
Example #11
Source Project: gemfirexd-oss   Author: gemxd   File: WorkHorseForCollatorDatatypes.java    License: Apache License 2.0 6 votes vote down vote up
/** @see SQLChar#stringCompare(SQLChar, SQLChar) */
int stringCompare(SQLChar str1, SQLChar str2)
throws StandardException
{
	CollationKey ckey1 = str1.getCollationKey();
	CollationKey ckey2 = str2.getCollationKey();
	
	/*
	** By convention, nulls sort High, and null == null
	*/
	if (ckey1 == null || ckey2 == null)
	{
		if (ckey1 != null)	// str2 == null
			return -1;
		if (ckey2 != null)	// this == null
			return 1;
		return 0;			// both == null
	}

	return ckey1.compareTo(ckey2);
}
 
Example #12
Source Project: kkFileViewOfficeEdit   Author: YiJiuSmile   File: ZipReader.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int compare(FileNode o1, FileNode o2) {
    // 判断两个对比对象是否是开头包含数字,如果包含数字则获取数字并按数字真正大小进行排序
    BigDecimal num1,num2;
    if (null != (num1 = isStartNumber(o1))
            && null != (num2 = isStartNumber(o2))) {
        return num1.subtract(num2).intValue();
    }
    CollationKey c1 = cmp.getCollationKey(o1.getOriginName());
    CollationKey c2 = cmp.getCollationKey(o2.getOriginName());
    return cmp.compare(c1.getSourceString(), c2.getSourceString());
}
 
Example #13
Source Project: dragonwell8_jdk   Author: alibaba   File: APITest.java    License: 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 #14
Source Project: dragonwell8_jdk   Author: alibaba   File: MonkeyTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void TestCollationKey()
{
    String source = "-abcdefghijklmnopqrstuvwxyz#&^[email protected]";
    Random r = new Random(3);
    int s = checkValue(r.nextInt() % source.length());
    int t = checkValue(r.nextInt() % source.length());
    int slen = checkValue((r.nextInt() - source.length()) % source.length());
    int tlen = checkValue((r.nextInt() - source.length()) % source.length());
    String subs = source.substring((s > slen ? slen : s), (s >= slen ? s : slen));
    String subt = source.substring((t > tlen ? tlen : t), (t >= tlen ? t : tlen));
    myCollator.setStrength(Collator.TERTIARY);
    CollationKey CollationKey1 = myCollator.getCollationKey(subs);
    CollationKey CollationKey2 = myCollator.getCollationKey(subt);
    int result = CollationKey1.compareTo(CollationKey2);  // Tertiary
    int revResult = CollationKey2.compareTo(CollationKey1);  // Tertiary
    report(("CollationKey(" + subs + ")"), ("CollationKey(" + subt + ")"), result, revResult);
    myCollator.setStrength(Collator.SECONDARY);
    CollationKey1 = myCollator.getCollationKey(subs);
    CollationKey2 = myCollator.getCollationKey(subt);
    result = CollationKey1.compareTo(CollationKey2);  // Secondary
    revResult = CollationKey2.compareTo(CollationKey1);   // Secondary
    report(("CollationKey(" + subs + ")") , ("CollationKey(" + subt + ")"), result, revResult);
    myCollator.setStrength(Collator.PRIMARY);
    CollationKey1 = myCollator.getCollationKey(subs);
    CollationKey2 = myCollator.getCollationKey(subt);
    result = CollationKey1.compareTo(CollationKey2);  // Primary
    revResult = CollationKey2.compareTo(CollationKey1);   // Primary
    report(("CollationKey(" + subs + ")"), ("CollationKey(" + subt + ")"), result, revResult);
    String addOne = subs + "\uE000";
    CollationKey1 = myCollator.getCollationKey(subs);
    CollationKey2 = myCollator.getCollationKey(addOne);
    result = CollationKey1.compareTo(CollationKey2);
    if (result != -1)
        errln("CollationKey(" + subs + ")" + ".LT." + "CollationKey(" + addOne + ") Failed.");
    result = CollationKey2.compareTo(CollationKey1);
    if (result != 1)
        errln("CollationKey(" + addOne + ")" + ".GT." + "CollationKey(" + subs + ") Failed.");
}
 
Example #15
Source Project: adaptive-radix-tree   Author: rohansuri   File: Collator.java    License: MIT License 5 votes vote down vote up
@Test
public void testICU(){
	String str = "hello";
	java.text.Collator col = java.text.Collator.getInstance(Locale.US);;
	CollationKey ck = col.getCollationKey(str);
	byte[] bytes = ck.toByteArray();
	System.out.println("collation key bytes length: " + bytes.length);
	System.out.println("collation key bytes: " + Arrays.toString(bytes));
	System.out.println("collation key as string:" + new String(bytes));
	System.out.println("original string: " + Arrays.toString(str.getBytes()));
}
 
Example #16
Source Project: TencentKona-8   Author: Tencent   File: ExecutableMemberDocImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generate a key for sorting.
 */
@Override
CollationKey generateKey() {
    String k = name() + flatSignature() + typeParametersString();
    // ',' and '&' are between '$' and 'a':  normalize to spaces.
    k = k.replace(',', ' ').replace('&', ' ');
    // System.out.println("COLLATION KEY FOR " + this + " is \"" + k + "\"");
    return env.doclocale.collator.getCollationKey(k);
}
 
Example #17
Source Project: TencentKona-8   Author: Tencent   File: DocImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * return a key for sorting.
 */
CollationKey key() {
    if (collationkey == null) {
        collationkey = generateKey();
    }
    return collationkey;
}
 
Example #18
Source Project: TencentKona-8   Author: Tencent   File: APITest.java    License: 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 #19
Source Project: TencentKona-8   Author: Tencent   File: MonkeyTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void TestCollationKey()
{
    String source = "-abcdefghijklmnopqrstuvwxyz#&^[email protected]";
    Random r = new Random(3);
    int s = checkValue(r.nextInt() % source.length());
    int t = checkValue(r.nextInt() % source.length());
    int slen = checkValue((r.nextInt() - source.length()) % source.length());
    int tlen = checkValue((r.nextInt() - source.length()) % source.length());
    String subs = source.substring((s > slen ? slen : s), (s >= slen ? s : slen));
    String subt = source.substring((t > tlen ? tlen : t), (t >= tlen ? t : tlen));
    myCollator.setStrength(Collator.TERTIARY);
    CollationKey CollationKey1 = myCollator.getCollationKey(subs);
    CollationKey CollationKey2 = myCollator.getCollationKey(subt);
    int result = CollationKey1.compareTo(CollationKey2);  // Tertiary
    int revResult = CollationKey2.compareTo(CollationKey1);  // Tertiary
    report(("CollationKey(" + subs + ")"), ("CollationKey(" + subt + ")"), result, revResult);
    myCollator.setStrength(Collator.SECONDARY);
    CollationKey1 = myCollator.getCollationKey(subs);
    CollationKey2 = myCollator.getCollationKey(subt);
    result = CollationKey1.compareTo(CollationKey2);  // Secondary
    revResult = CollationKey2.compareTo(CollationKey1);   // Secondary
    report(("CollationKey(" + subs + ")") , ("CollationKey(" + subt + ")"), result, revResult);
    myCollator.setStrength(Collator.PRIMARY);
    CollationKey1 = myCollator.getCollationKey(subs);
    CollationKey2 = myCollator.getCollationKey(subt);
    result = CollationKey1.compareTo(CollationKey2);  // Primary
    revResult = CollationKey2.compareTo(CollationKey1);   // Primary
    report(("CollationKey(" + subs + ")"), ("CollationKey(" + subt + ")"), result, revResult);
    String addOne = subs + "\uE000";
    CollationKey1 = myCollator.getCollationKey(subs);
    CollationKey2 = myCollator.getCollationKey(addOne);
    result = CollationKey1.compareTo(CollationKey2);
    if (result != -1)
        errln("CollationKey(" + subs + ")" + ".LT." + "CollationKey(" + addOne + ") Failed.");
    result = CollationKey2.compareTo(CollationKey1);
    if (result != 1)
        errln("CollationKey(" + addOne + ")" + ".GT." + "CollationKey(" + subs + ") Failed.");
}
 
Example #20
Source Project: jdk8u60   Author: chenghanpeng   File: ExecutableMemberDocImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generate a key for sorting.
 */
@Override
CollationKey generateKey() {
    String k = name() + flatSignature() + typeParametersString();
    // ',' and '&' are between '$' and 'a':  normalize to spaces.
    k = k.replace(',', ' ').replace('&', ' ');
    // System.out.println("COLLATION KEY FOR " + this + " is \"" + k + "\"");
    return env.doclocale.collator.getCollationKey(k);
}
 
Example #21
Source Project: spliceengine   Author: splicemachine   File: SQLChar.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Hash code implementation for collator sensitive subclasses.
 */
int hashCodeForCollation() {
    CollationKey key = null;

    try {
        key = getCollationKey();
    } catch (StandardException se) {
        // ignore exceptions, like we do in hashCode()
        if (SanityManager.DEBUG) {
            SanityManager.THROWASSERT("Unexpected exception", se);
        }
    }

    return key == null ? 0 : key.hashCode();
}
 
Example #22
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: ExecutableMemberDocImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generate a key for sorting.
 */
@Override
CollationKey generateKey() {
    String k = name() + flatSignature() + typeParametersString();
    // ',' and '&' are between '$' and 'a':  normalize to spaces.
    k = k.replace(',', ' ').replace('&', ' ');
    // System.out.println("COLLATION KEY FOR " + this + " is \"" + k + "\"");
    return env.doclocale.collator.getCollationKey(k);
}
 
Example #23
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: DocImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * return a key for sorting.
 */
CollationKey key() {
    if (collationkey == null) {
        collationkey = generateKey();
    }
    return collationkey;
}
 
Example #24
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: APITest.java    License: 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 #25
Source Project: Android   Author: connectim   File: BaseListComparatorSort.java    License: MIT License 5 votes vote down vote up
@Override
public int compare(T lhs, T rhs) {
    String ostr1;
    String ostr2;
    String lhsName = getName(lhs);
    String rhskName = getName(rhs);

    if (TextUtils.isEmpty(lhsName)) {
        ostr1 = PinyinUtil.getFirstChar(TextUtils.isEmpty(lhsName) ? "#" : lhsName);
    } else {
        ostr1 = PinyinUtil.getFirstChar(TextUtils.isEmpty(lhsName) ? "#" : lhsName);
    }


    if (TextUtils.isEmpty(rhskName)) {
        ostr2 = PinyinUtil.getFirstChar(TextUtils.isEmpty(rhskName) ? "#" : rhskName);
    } else {
        ostr2 = PinyinUtil.getFirstChar(TextUtils.isEmpty(rhskName) ? "#" : rhskName);
    }

    CollationKey key1 = collator.getCollationKey(pinyin(ostr1.equals("") ? '#': ostr1.charAt(0)));
    CollationKey key2 = collator.getCollationKey(pinyin(ostr2.equals("") ? '#': ostr2.charAt(0)));
    // Comparison method violates its general contract
    if(key1.getSourceString().equals(key2.getSourceString())){
        return 0;
    }
    if ("#".equals(key1.getSourceString())
            || "#".equals(key2.getSourceString())) {
        if ("#".equals(key1.getSourceString())) {
            return 1;
        } else if ("#".equals(key2.getSourceString())) {
            return -1;
        }
    }
    return key1.compareTo(key2);
}
 
Example #26
Source Project: Android   Author: connectim   File: GroupMemberCompara.java    License: MIT License 5 votes vote down vote up
@Override
public int compare(GroupMemberEntity lhs, GroupMemberEntity rhs) {
    String string1 = TextUtils.isEmpty(lhs.getNick()) ? lhs.getUsername() : lhs.getNick();
    String string2 = TextUtils.isEmpty(rhs.getNick()) ? rhs.getUsername() : rhs.getNick();
    if (TextUtils.isEmpty(string1)) {
        string1 = "#";
    }
    if (TextUtils.isEmpty(string2)) {
        string2 = "#";
    }

    char char1 = string1.charAt(0);
    char char2 = string2.charAt(0);

    CollationKey key1 = collator.getCollationKey(PinyinUtil.chatToPinyin(char1));
    CollationKey key2 = collator.getCollationKey(PinyinUtil.chatToPinyin(char2));

    // Comparison method violates its general contract
    if (key1.getSourceString().equals(key2.getSourceString())) {
        return 0;
    }
    if ("#".equals(key1.getSourceString())
            || "#".equals(key2.getSourceString())) {
        if ("#".equals(key1.getSourceString())) {
            return 1;
        } else if ("#".equals(key2.getSourceString())) {
            return -1;
        }
    }
    return key1.compareTo(key2);
}
 
Example #27
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: ExecutableMemberDocImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generate a key for sorting.
 */
@Override
CollationKey generateKey() {
    String k = name() + flatSignature() + typeParametersString();
    // ',' and '&' are between '$' and 'a':  normalize to spaces.
    k = k.replace(',', ' ').replace('&', ' ');
    // System.out.println("COLLATION KEY FOR " + this + " is \"" + k + "\"");
    return env.doclocale.collator.getCollationKey(k);
}
 
Example #28
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: DocImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * return a key for sorting.
 */
CollationKey key() {
    if (collationkey == null) {
        collationkey = generateKey();
    }
    return collationkey;
}
 
Example #29
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: Utils.java    License: GNU General Public License v2.0 5 votes vote down vote up
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;
        }
    };
}
 
Example #30
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: ExecutableMemberDocImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generate a key for sorting.
 */
@Override
CollationKey generateKey() {
    String k = name() + flatSignature() + typeParametersString();
    // ',' and '&' are between '$' and 'a':  normalize to spaces.
    k = k.replace(',', ' ').replace('&', ' ');
    // System.out.println("COLLATION KEY FOR " + this + " is \"" + k + "\"");
    return env.doclocale.collator.getCollationKey(k);
}