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 File: WorkHorseForCollatorDatatypes.java    From spliceengine with 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 #2
Source File: GroupComPara.java    From Android with 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 #3
Source File: CollationKeyTestImpl.java    From dragonwell8_jdk with 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 #4
Source File: FriendCompara.java    From Android with 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 #5
Source File: WorkHorseForCollatorDatatypes.java    From gemfirexd-oss with 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 #6
Source File: CollationKeyTestImpl.java    From jdk8u_jdk with 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 #7
Source File: CollationKeyTestImpl.java    From openjdk-jdk8u with 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 #8
Source File: CollationKeyTestImpl.java    From openjdk-jdk9 with 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 File: SQLChar.java    From spliceengine with 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 #10
Source File: WorkHorseForCollatorDatatypes.java    From gemfirexd-oss with 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 #11
Source File: CollationKeyTestImpl.java    From TencentKona-8 with 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 #12
Source File: ListFoldersBaseFragment.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the list of subfolders, using getFileNameForSorting() for ordering.
 *
 * @param parentFolder The parent folder.
 * @return The list of subfolders.
 */
@NonNull
public static List<String> getFolderNames(@NonNull final File parentFolder) {
	File[] folders = parentFolder.listFiles(new FileFilter() {
		@Override
		public boolean accept(@NonNull final File pathname) {
			return pathname.isDirectory();
		}
	});

	List<String> folderNames = new ArrayList<>();
	if (folders == null) {
		return folderNames;
	}

	Collator collator = Collator.getInstance();
	final Map<File, CollationKey> collationMap = new HashMap<>();
	for (File folder : folders) {
		collationMap.put(folder, collator.getCollationKey(getFilenameForSorting(folder)));
	}

	Arrays.sort(folders, new Comparator<File>() {
		@Override
		public int compare(final File f1, final File f2) {
			return collationMap.get(f1).compareTo(collationMap.get(f2));
		}
	});

	for (File f : folders) {
		folderNames.add(f.getName());
	}

	if (Application.getAuthorizationLevel() == AuthorizationLevel.TRIAL_ACCESS
			&& folderNames.size() > TRIAL_MAX_NAMES) {
		folderNames = folderNames.subList(0, TRIAL_MAX_NAMES);
	}

	return folderNames;
}
 
Example #13
Source File: MonkeyTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void TestCollationKey()
{
    String source = "-abcdefghijklmnopqrstuvwxyz#&^$@";
    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 #14
Source File: DisplayPhotosController.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the list of subfolders, using getFileNameForSorting() for ordering.
 *
 * @param parentFolder
 *            The parent folder.
 * @param searchString
 *            A search String for the name.
 * @return The list of subfolders.
 */
public static final List<String> getFolderNames(final File parentFolder, final String searchString) {
	File[] folders = parentFolder.listFiles(new FileFilter() {
		@Override
		public boolean accept(final File pathname) {
			return pathname.isDirectory() && nameStartsWith(pathname.getName(), searchString);
		}
	});

	List<String> folderNames = new ArrayList<>();
	if (folders == null) {
		return folderNames;
	}

	Collator collator = Collator.getInstance();
	final Map<File, CollationKey> collationMap = new HashMap<>();
	for (File folder : folders) {
		collationMap.put(folder, collator.getCollationKey(getFilenameForSorting(folder)));
	}

	Arrays.sort(folders, new Comparator<File>() {
		@Override
		public int compare(final File f1, final File f2) {
			return collationMap.get(f1).compareTo(collationMap.get(f2));
		}
	});
	for (File f : folders) {
		folderNames.add(f.getName());
	}
	return folderNames;
}
 
Example #15
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 #16
Source File: SQLChar.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * This method gets called for the collation sensitive char classes ie
 * CollatorSQLChar, CollatorSQLVarchar, CollatorSQLLongvarchar,
 * CollatorSQLClob. These collation sensitive chars need to have the 
 * collation key in order to do string comparison. And the collation key
 * is obtained using the Collator object that these classes already have.
 * 
 * @return CollationKey obtained using Collator on the string
 * @throws StandardException
 */
protected CollationKey getCollationKey() throws StandardException
{
    char tmpCharArray[];

    if (cKey != null)
        return cKey;

    if (rawLength == -1)
    {
        /* materialize the string if input is a stream */
        tmpCharArray = getCharArray();
        if (tmpCharArray == null)
            return null;
    }
    
    int lastNonspaceChar = rawLength;

    while (lastNonspaceChar > 0 && 
           rawData[lastNonspaceChar - 1] == '\u0020')
        lastNonspaceChar--;         // count off the trailing spaces.

    RuleBasedCollator rbc = getCollatorForCollation();      
    cKey = rbc.getCollationKey(new String(rawData, 0, lastNonspaceChar));

    return cKey;
}
 
Example #17
Source File: MonkeyTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void TestCollationKey()
{
    String source = "-abcdefghijklmnopqrstuvwxyz#&^$@";
    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 #18
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 #19
Source File: ExecutableMemberDocImpl.java    From openjdk-jdk9 with 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 #20
Source File: DocImpl.java    From openjdk-8-source with 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 #21
Source File: BrailleBackPreferencesActivity.java    From brailleback with Apache License 2.0 5 votes vote down vote up
private CollationKey getCollationKey(TableInfo tableInfo) {
    CollationKey key = mCollationKeyMap.get(tableInfo);
    if (key == null) {
        key = mCollator.getCollationKey(
            tableInfo.getLocale().getDisplayName());
        mCollationKeyMap.put(tableInfo, key);
    }
    return key;
}
 
Example #22
Source File: SQLChar.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * This method gets called for the collation sensitive char classes ie
 * CollatorSQLChar, CollatorSQLVarchar, CollatorSQLLongvarchar,
 * CollatorSQLClob. These collation sensitive chars need to have the
 * collation key in order to do string comparison. And the collation key
 * is obtained using the Collator object that these classes already have.
 *
 * @return CollationKey obtained using Collator on the string
 * @throws StandardException
 */
protected CollationKey getCollationKey() throws StandardException
{
    char tmpCharArray[];

    if (cKey != null)
        return cKey;

    if (rawLength == -1)
    {
        /* materialize the string if input is a stream */
        tmpCharArray = getCharArray();
        if (tmpCharArray == null)
            return null;
    }

    int lastNonspaceChar = rawLength;

    while (lastNonspaceChar > 0 &&
           rawData[lastNonspaceChar - 1] == '\u0020')
        lastNonspaceChar--;         // count off the trailing spaces.

    RuleBasedCollator rbc = getCollatorForCollation();
    cKey = rbc.getCollationKey(new String(rawData, 0, lastNonspaceChar));

    return cKey;
}
 
Example #23
Source File: TextUtil.java    From grammaticus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private CollationKey getCollationKey(String comp) {
    CollationKey key = cKeyMap.get(comp);
    if (key == null) {
        key = collator.getCollationKey(comp);
        cKeyMap.put(comp, key);
    }
    return key;
}
 
Example #24
Source File: ZipReader.java    From kkFileView with 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 #25
Source File: ExecutableMemberDocImpl.java    From openjdk-8-source with 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 #26
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 #27
Source File: DocImpl.java    From openjdk-jdk9 with 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 #28
Source File: ZipReader.java    From kkFileViewOfficeEdit with 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 #29
Source File: Utils.java    From openjdk-jdk9 with 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 File: DocImpl.java    From openjdk-jdk8u-backup with 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;
}