當前位置: 首頁>>代碼示例>>Java>>正文


Java Collator.compare方法代碼示例

本文整理匯總了Java中java.text.Collator.compare方法的典型用法代碼示例。如果您正苦於以下問題:Java Collator.compare方法的具體用法?Java Collator.compare怎麽用?Java Collator.compare使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.text.Collator的用法示例。


在下文中一共展示了Collator.compare方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: compareGraphObjects

import java.text.Collator; //導入方法依賴的package包/類
private static int compareGraphObjects(GraphObject a, GraphObject b, Collection<String> sortFields,
        Collator collator) {
    for (String sortField : sortFields) {
        String sa = (String) a.getProperty(sortField);
        String sb = (String) b.getProperty(sortField);

        if (sa != null && sb != null) {
            int result = collator.compare(sa, sb);
            if (result != 0) {
                return result;
            }
        } else if (!(sa == null && sb == null)) {
            return (sa == null) ? -1 : 1;
        }
    }
    return 0;
}
 
開發者ID:MobileDev418,項目名稱:AndroidBackendlessChat,代碼行數:18,代碼來源:GraphObjectAdapter.java

示例2: compareTo

import java.text.Collator; //導入方法依賴的package包/類
@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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:DocumentGroupImpl.java

示例3: compare

import java.text.Collator; //導入方法依賴的package包/類
@Override
public int compare(AppInfo lhs, AppInfo rhs)
{
    // 為了適應漢字的比較
    Collator c = Collator.getInstance(Locale.CHINA);
    return (asc == 1) ? c.compare(lhs.appName, rhs.appName)
	: c.compare(rhs.appName, lhs.appName);
}
 
開發者ID:stytooldex,項目名稱:stynico,代碼行數:9,代碼來源:buff_ext.java

示例4: localeCompare

import java.text.Collator; //導入方法依賴的package包/類
/**
 * 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 double 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 collator.compare(str, JSType.toString(that));
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:18,代碼來源:NativeString.java

示例5: compareTo

import java.text.Collator; //導入方法依賴的package包/類
@Override
public int compareTo(ApplicationInfoEx other) {
	// Locale respecting sorter
	Collator collator = Collator.getInstance(Locale.getDefault());
	return collator.compare(TextUtils.join(", ", getApplicationName()),
			TextUtils.join(", ", other.getApplicationName()));
}
 
開發者ID:ukanth,項目名稱:XPrivacy,代碼行數:8,代碼來源:ApplicationInfoEx.java

示例6: compareTo

import java.text.Collator; //導入方法依賴的package包/類
@Override
public int compareTo(FileNavigator o) {
    Collator collator = Collator.getInstance();
    return collator.compare(this.modelName, o.modelName);
}
 
開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:6,代碼來源:FileNavigator.java

示例7: compareTo

import java.text.Collator; //導入方法依賴的package包/類
@Override
public int compareTo(Item o) {
    Collator collator = Collator.getInstance();
    return collator.compare(this.modelName, o.modelName);
}
 
開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:6,代碼來源:Preferences.java

示例8: buildSenseCollectionAsSynstes

import java.text.Collator; //導入方法依賴的package包/類
public Collection<Sense> buildSenseCollectionAsSynstes(List<Sense> sense, String sortFrase) {
        Collection<Sense> synsets = new ArrayList<Sense>();
        if (!sense.isEmpty()) {
            for (Sense senseItem : sense) {
//                if (senseItem.getSenseToSynset().getSenseIndex() == 0) {
//                    synsets.add(senseItem);
//                }
//                if (senseItem.getLexicon().getId() == 2
//                        && senseItem.getSenseToSynset().getSenseIndex() == 1) {
//                    synsets.add(senseItem);
//                }
            }
        }

        Collator collator = Collator.getInstance(Locale.US);
        String rules = ((RuleBasedCollator) collator).getRules();
        try {
            RuleBasedCollator correctedCollator
                    = new RuleBasedCollator(rules.replaceAll("<'\u005f'", "<' '<'\u005f'"));
            collator = correctedCollator;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        collator.setStrength(Collator.PRIMARY);
        collator.setDecomposition(Collator.NO_DECOMPOSITION);

        final Collator myFavouriteCollator = collator;

        Comparator<Sense> senseComparator = new Comparator<Sense>() {
            @Override
            public int compare(Sense a, Sense b) {
                String aa = a.getWord().getWord().toLowerCase();
                String bb = b.getWord().getWord().toLowerCase();

                int c = myFavouriteCollator.compare(aa, bb);
                if (c == 0) {
                    aa = a.getPartOfSpeech().getId().toString();
                    bb = b.getPartOfSpeech().getId().toString();
                    c = myFavouriteCollator.compare(aa, bb);
                }
                if (c == 0) {
                    if (a.getVariant() == b.getVariant()) {
                        c = 0;
                    }
                    if (a.getVariant() > b.getVariant()) {
                        c = 1;
                    }
                    if (a.getVariant() < b.getVariant()) {
                        c = -1;
                    }
                }
                if (c == 0) {
                    aa = a.getLexicon().getId().toString();
                    bb = b.getLexicon().getId().toString();
                    c = myFavouriteCollator.compare(aa, bb);
                }
                return c;
            }
        };

        //Items starting with frase
        List<Sense> withFraseOnBegining = new ArrayList<>();
        //Other items
        List<Sense> other = new ArrayList<>();

        for (Sense se : synsets) {
            if (se.getWord().toString().startsWith(sortFrase.toLowerCase())) {
                withFraseOnBegining.add(se);
            } else {
                other.add(se);
            }
        }
        Collections.sort(withFraseOnBegining, senseComparator);
        Collections.sort(other, senseComparator);
        withFraseOnBegining.addAll(other);
        return withFraseOnBegining;
    }
 
開發者ID:CLARIN-PL,項目名稱:WordnetLoom,代碼行數:78,代碼來源:GenericListModel.java

示例9: compare

import java.text.Collator; //導入方法依賴的package包/類
/**
 * Compare two strings with Locale.ENGLISH
 * This method is preferred over String.compareTo() method.
 * @param str1 String 1
 * @param str2 String 2
 * @return negative integer if str1 lexicographically precedes str2
 *            positive integer if str1 lexicographically follows str2
 *             0 if both strings are equal
 * @throws IllegalArgumentException throws exception if both or either of the strings is null
 */
public static int compare(String str1, String str2) {
    if (str1 == null || str2 == null) {
        throw new IllegalArgumentException("Arguments cannot be null");
    }

    Collator collator = Collator.getInstance(LOCALE_ENGLISH);
    return collator.compare(str1, str2);
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:19,代碼來源:StringUtils.java

示例10: compare

import java.text.Collator; //導入方法依賴的package包/類
/**
 * Compare two strings with Locale.ENGLISH
 * This method is preferred over String.compareTo() method.
 * @param str1 String 1
 * @param str2 String 2
 * @return negative integer if str1 lexicographically precedes str2
 * 		   positive integer if str1 lexicographically follows str2
 * 			0 if both strings are equal
 * @throws IllegalArgumentException throws exception if both or either of the strings is null
 */
public static int compare(String str1, String str2) {
    if( str1 == null || str2 == null) {
        throw new IllegalArgumentException("Arguments cannot be null");
    }

    Collator collator = Collator.getInstance(LOCALE_ENGLISH);
    return collator.compare(str1, str2);
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:19,代碼來源:StringUtils.java


注:本文中的java.text.Collator.compare方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。