当前位置: 首页>>代码示例>>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;未经允许,请勿转载。